First commit 10/04/1996
This commit is contained in:
commit
43a19f54da
32
BYTE.CPP
Normal file
32
BYTE.CPP
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
struct Bits
|
||||
{
|
||||
|
||||
unsigned int bit : 1;
|
||||
|
||||
};
|
||||
|
||||
typedef union char_bit
|
||||
{
|
||||
char byte;
|
||||
Bits bits[8];
|
||||
|
||||
} charbit;
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
charbit cb;
|
||||
int numero;
|
||||
|
||||
do{
|
||||
|
||||
scanf( "%d", numero );
|
||||
cb.byte = numero;
|
||||
printf( "%d %d %d %d %d %d %d %d", (int)cb.bits[0].bit, (int)cb.bits[1].bit, (int)cb.bits[2].bit, (int)cb.bits[3].bit,
|
||||
(int)cb.bits[4].bit, (int)cb.bits[5].bit, (int)cb.bits[6].bit, (int)cb.bits[7].bit );
|
||||
|
||||
}while( cb.byte > 0 );
|
||||
|
||||
|
||||
}
|
63
PLACA.CPP
Normal file
63
PLACA.CPP
Normal file
@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <conio.h>
|
||||
#include <dos.h>
|
||||
#include "prn_cnt.h"
|
||||
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
char ok = 0;
|
||||
int salida, estado;
|
||||
|
||||
Lpt_usado = 1;
|
||||
Init_all();
|
||||
/*
|
||||
do
|
||||
{
|
||||
for ( salida = 1; salida<=128; salida*=2 )
|
||||
{
|
||||
Escribe_Salidas( 6, NULL, (char)salida );
|
||||
delay(50);
|
||||
}
|
||||
for ( salida = 128; salida>1; salida/=2 )
|
||||
{
|
||||
Escribe_Salidas( 6, NULL, (char)salida );
|
||||
delay(50);
|
||||
}
|
||||
}while( !kbhit() );
|
||||
*/
|
||||
/*
|
||||
do
|
||||
{
|
||||
printf( "\n Introduzca salida y estado: " );
|
||||
scanf( "%d %d", &salida, &estado );
|
||||
Escribe_Salida( (char)salida, (char)estado );
|
||||
// Escribe_Salidas( 6, NULL, (char)salida );
|
||||
|
||||
} while( salida>0 );
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
estado = Lee_Entradas( 6, NULL );
|
||||
printf( "\n%d %d %d %d %d %d %d %d", ( estado & 0x80 ) != 0,
|
||||
( estado & 0x40 ) != 0,
|
||||
( estado & 0x20 ) != 0,
|
||||
( estado & 0x10 ) != 0,
|
||||
|
||||
( estado & 0x08 ) != 0,
|
||||
( estado & 0x04 ) != 0,
|
||||
( estado & 0x02 ) != 0,
|
||||
( estado & 0x01 ) != 0 );
|
||||
getch();
|
||||
|
||||
} while( !kbhit() );
|
||||
|
||||
|
||||
|
||||
// ESCRIBIR ES UN '1'
|
||||
// La direcci¢n de la placa es '6'
|
||||
// ===> la direcci¢n '0' es: 1 000 0011
|
||||
}
|
261
PRN_CNT.BAS
Normal file
261
PRN_CNT.BAS
Normal file
@ -0,0 +1,261 @@
|
||||
' /**************************************************************************\
|
||||
'| |
|
||||
'| Codigo Fuente de PRN_CNT |
|
||||
'| |
|
||||
' \**************************************************************************/
|
||||
|
||||
dim shared Salidas(10) as single, PortAddress(3) as integer
|
||||
PortAddress(1) = &378
|
||||
PortAddress(2) = &278
|
||||
PortAddress(3) = &3bc
|
||||
|
||||
dim shared NULL as ESTADOS
|
||||
|
||||
typedef struct ESTADOS
|
||||
{
|
||||
b1 as single
|
||||
b2 as single
|
||||
b3 as single
|
||||
b4 as single
|
||||
b5 as single
|
||||
b6 as single
|
||||
b7 as single
|
||||
}
|
||||
|
||||
sub Init.DeInit
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Esta rutina debe ser llamada al iniciar el programa que use las librerias. |
|
||||
| |
|
||||
| Es la encargada de poner a cero todas la salidas, al principio y al salir. |
|
||||
| |
|
||||
| |
|
||||
| Parametros de Entrada: ( ninguno ) |
|
||||
| Parametros de Salida: |
|
||||
| OK Todo ha ido bien. |
|
||||
| ERROR_EN_ATEXIT Error registrando funci¢n |
|
||||
| FUNCION_YA_REGISTRADA No es la 1¦ vez |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
call ResetAll
|
||||
|
||||
end sub
|
||||
|
||||
|
||||
|
||||
sub ResetAll
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Resetea todas las salidas y las pone a cero. |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
dim ampl as single
|
||||
|
||||
for ampl=0 to ampl<10 step 1
|
||||
call EscribeSalidas( ampl, NULL, 0 )
|
||||
next ampl
|
||||
|
||||
end sub
|
||||
|
||||
function LeeSalidas%( ampl as single, estados as ESTADOS )
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Obtiene el estado de las salidas ( On/Off ), de la ampliacion AMPL. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, solo se devolvera el char de salida. |
|
||||
\**************************************************************************/
|
||||
|
||||
dim desp as single
|
||||
|
||||
if ampl < 0 or ampl >9 then
|
||||
LeeSalidas = 0
|
||||
exit
|
||||
end if
|
||||
if estados <> NULL then
|
||||
|
||||
estados.Salida0 = ( ( Salidas( ampl ) and&00 ) <> 0 )
|
||||
estados.Salida1 = ( ( Salidas( ampl ) and&02 ) <> 0 )
|
||||
estados.Salida2 = ( ( Salidas( ampl ) and&04 ) <> 0 )
|
||||
estados.Salida3 = ( ( Salidas( ampl ) and&08 ) <> 0 )
|
||||
estados.Salida4 = ( ( Salidas( ampl ) and&10 ) <> 0 )
|
||||
estados.Salida5 = ( ( Salidas( ampl ) and&20 ) <> 0 )
|
||||
estados.Salida6 = ( ( Salidas( ampl ) and&40 ) <> 0 )
|
||||
estados.Salida7 = ( ( Salidas( ampl ) and&80 ) <> 0 )
|
||||
}
|
||||
|
||||
return Salidas( ampl )
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Obtiene el estado de una salida ( On/Off ), cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| salida ( Si 1 ampl. 0 a 7 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
char Lee_Salida( char salida )
|
||||
{
|
||||
return ( Salida( (salida / 8) + 1 ) and( &01 << ( salida - ((salida/8)+1)*8 ) ) <> 0
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Escribe la variable 'estados' ( On/Off ), en la ampliacion AMPL. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| estadosb 1byte con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, solo se utilizar la variable estadosb. |
|
||||
\**************************************************************************/
|
||||
|
||||
char Escribe_Salidas( char ampl, ESTADOS *estados, char estadosb )
|
||||
{
|
||||
char byte_out=0, cont
|
||||
|
||||
outportb( Port_Address(Lpt_usado-1) + 1, &0 )
|
||||
|
||||
|
||||
if ( estados = NULL )
|
||||
{
|
||||
outportb( Port_Address(Lpt_usado-1), estadosb )
|
||||
Salida( ampl ) = estadosb
|
||||
} else {
|
||||
byte_out = estados.Salida0
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 1) )
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 2) )
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 3) )
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 4) )
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 5) )
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 6) )
|
||||
byte_out = ( bytes_out or( ( estados.Salida1 ) << 7) )
|
||||
outportb( Port_Address(Lpt_usado-1), byte_out )
|
||||
Salida( ampl ) = byte_out
|
||||
}
|
||||
/*
|
||||
A2 (ampl and&01)
|
||||
A1 (ampl and&02)
|
||||
A0 (ampl and&04)
|
||||
*/
|
||||
outportb( Port_Address(Lpt_usado-1) + 1, &0 )
|
||||
|
||||
|
||||
outportb( Port_Address(Lpt_usado-1) + 1, &0 )
|
||||
|
||||
/*
|
||||
A2 01.0 Strobe
|
||||
A1 14.0 AutoFeed
|
||||
A0 16.0 Inicializaci¢n
|
||||
|
||||
11 10 12 13 15
|
||||
128 64 32 16 8 4 2 1
|
||||
0 1 0 1 0 1 0 1
|
||||
|
||||
13 12 11 10
|
||||
. . . . þ þ þ þ þ þ þ þ . <-- 1
|
||||
- - - - - - - - . . . .
|
||||
15
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function EscribeSalida%( salida as single, estados as single )
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Escribe el estado de una salida ( On/Off ), cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| salida ( Si 1 ampl. 0 a 3 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
dim ampl as single, byte_out as single
|
||||
ampl = (salida / 8) + 1
|
||||
|
||||
byte_out = Lee_Salidas( ampl, NULL )
|
||||
byte_out = ( byte_out and!( &01 << ( salida - ampl*8 ) ) ) or( estado << ( salida - ampl*8 ) )
|
||||
Salida( ampl ) = byte_out
|
||||
EscribeSalidas( ampl, NULL, byte_out )
|
||||
EscribeSalida = byte_out
|
||||
end function
|
||||
|
||||
|
||||
|
||||
function LeeEntradas%( ampl as single, estados as ESTADOS )
|
||||
|
||||
' /**************************************************************************\
|
||||
'| |
|
||||
'| Lee las entradas y la almacena en la variable estados. |
|
||||
'| |
|
||||
'| Parametros de Entrada: |
|
||||
'| ampl Ampliaci¢n donde debemos mirar |
|
||||
'| estados Puntero a estructura con los estados |
|
||||
'| |
|
||||
'| Parametros de Salida: |
|
||||
'| char 1Byte con los estados |
|
||||
'| |
|
||||
' \**************************************************************************/
|
||||
|
||||
end function
|
||||
|
||||
function LeeEntrada%( entrada as single )
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Lee una entrada cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| entrada ( Si 1 ampl. 0 a 3 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
dim byte_out as single, ampl as single
|
||||
ampl = (salida / 8) + 1
|
||||
|
||||
byte_out = Lee_Entradas( ( (salida / 8) + 1 ), NULL )
|
||||
|
||||
byte_out = ( byte_out and( &01 << ( salida - ampl*8 ) ) )
|
||||
LeeEntrada = byte_out
|
||||
|
||||
end function
|
||||
|
||||
|
||||
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛFÛIÛNÛÛÛDÛEÛÛÛLÛAÛÛÛÛCÛAÛBÛEÛCÛEÛRÛAÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
|
||||
|
||||
|
||||
|
325
PRN_CNT.CPP
Normal file
325
PRN_CNT.CPP
Normal file
@ -0,0 +1,325 @@
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Codigo Fuente de PRN_CNT |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
/*
|
||||
A2 01 -> !1 Strobe
|
||||
A1 14 -> !2 AutoFeed
|
||||
A0 16 -> 4 Inicializaci¢n
|
||||
READ/WRITE !8
|
||||
*/
|
||||
|
||||
|
||||
#include "c:\backup\fuentes\prn_cnt\prn_cnt.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dos.h>
|
||||
|
||||
|
||||
char Salida[10];
|
||||
int Port_Address[3] = { 0x378, 0x278, 0x3BC };
|
||||
char Lpt_usado = 1;
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Esta rutina debe ser llamada al iniciar el programa que use las librerias. |
|
||||
| |
|
||||
| Es la encargada de poner a cero todas la salidas, al principio y al salir. |
|
||||
| |
|
||||
| |
|
||||
| Parametros de Entrada: ( ninguno ) |
|
||||
| Parametros de Salida: |
|
||||
| OK Todo ha ido bien. |
|
||||
| ERROR_EN_ATEXIT Error registrando funci¢n |
|
||||
| FUNCION_YA_REGISTRADA No es la 1¦ vez |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
//Û
|
||||
int Init_all(void)
|
||||
{
|
||||
static char vez = 0;
|
||||
|
||||
if ( vez == 0 )
|
||||
{
|
||||
vez = 1;
|
||||
Reset_all();
|
||||
if ( atexit( Reset_all ) != 0 )
|
||||
return ERROR_EN_ATEXIT;
|
||||
else
|
||||
return OK;
|
||||
} else
|
||||
return FUNCION_YA_REGISTRADA;
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| WARNING: |
|
||||
| El uso de la siguiente funci¢n esta indicada solo para usuarios |
|
||||
| experimentados, se debe usar en lugar de la funci¢n anterior. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ( LEER/ESCRIBIR ) // L/E los registros del fich|
|
||||
| ( %s ) // _ero %s |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| 1 Ok! OK |
|
||||
| -1 Fallo desconocido FALLO_DESCONOCIDO |
|
||||
| -2 Archivo no existe NO_ARCHIVO |
|
||||
| -3 Error archivo no valido ARCHIVO_INCORRECTO |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
int Register( char leer_escribir, char *file )
|
||||
{
|
||||
FILE *fich;
|
||||
char Buffer[10];
|
||||
|
||||
if ( leer_escribir == ESCRIBIR )
|
||||
{
|
||||
if ( (fich = fopen( file, "wb" ) ) == NULL ) return ARCHIVO_INCORRECTO;
|
||||
strcpy( Buffer, "PRN_CNT->\0" );
|
||||
fwrite( Buffer, sizeof( char ), 10, fich );
|
||||
fwrite( Salida, sizeof( char ), 10, fich );
|
||||
fclose(fich);
|
||||
} else {
|
||||
if ( (fich = fopen( file, "rb" ) ) == NULL ) return NO_ARCHIVO;
|
||||
fread( Buffer, sizeof( char ), 10, fich );
|
||||
if ( strncmp( Buffer, "PRN_CNT->", 9 ) != 0 ) {
|
||||
fclose( fich );
|
||||
return ARCHIVO_INCORRECTO;
|
||||
}
|
||||
fread( Salida, sizeof( char ), 10, fich );
|
||||
fclose(fich);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Resetea todas las salidas y las pone a cero. |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
//Û
|
||||
void Reset_all(void)
|
||||
{
|
||||
char ampl;
|
||||
outportb( 888, 0x00 );
|
||||
outportb( 890, 0x03 );
|
||||
|
||||
for ( ampl=0; ampl<10; ampl++ )
|
||||
Escribe_Salidas( ampl, NULL, 0 );
|
||||
|
||||
outportb( 888, 0x00 );
|
||||
outportb( 890, 0x03 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Obtiene el estado de las salidas ( On/Off ), de la ampliacion AMPL. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, solo se devolvera el char de salida. |
|
||||
\**************************************************************************/
|
||||
//Û
|
||||
unsigned char Lee_Salidas( char ampl, ESTADOS *estados )
|
||||
{
|
||||
char desp;
|
||||
|
||||
if ( ampl < 1 || ampl > 9 )
|
||||
return 0;
|
||||
if ( estados != NULL )
|
||||
{
|
||||
estados -> Salida0 = ( ( Salida[ ampl - 1 ] & 0x01 ) != 0 );
|
||||
estados -> Salida1 = ( ( Salida[ ampl - 1 ] & 0x02 ) != 0 );
|
||||
estados -> Salida2 = ( ( Salida[ ampl - 1 ] & 0x04 ) != 0 );
|
||||
estados -> Salida3 = ( ( Salida[ ampl - 1 ] & 0x08 ) != 0 );
|
||||
estados -> Salida4 = ( ( Salida[ ampl - 1 ] & 0x10 ) != 0 );
|
||||
estados -> Salida5 = ( ( Salida[ ampl - 1 ] & 0x20 ) != 0 );
|
||||
estados -> Salida6 = ( ( Salida[ ampl - 1 ] & 0x40 ) != 0 );
|
||||
estados -> Salida7 = ( ( Salida[ ampl - 1 ] & 0x80 ) != 0 );
|
||||
}
|
||||
|
||||
return Salida[ ampl - 1 ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Obtiene el estado de una salida ( On/Off ), cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| salida ( Si 1 ampl. 0 a 7 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
//Û
|
||||
unsigned char Lee_Salida( char salida )
|
||||
{
|
||||
// estados -> Salida0 = ( ( Salida[ ampl - 1 ] & 0x01 ) != 0 );
|
||||
return ( ( Salida[ (salida / 8) ] & ( 0x01 << ( salida - ( (salida/8)*8 ) ) ) ) != 0 );
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Escribe la variable 'estados' ( On/Off ), en la ampliacion AMPL. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| estadosb 1byte con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, solo se utilizar la variable estadosb. |
|
||||
\**************************************************************************/
|
||||
//Û
|
||||
unsigned char Escribe_Salidas( char ampl, ESTADOS *estados, char estadosb )
|
||||
{
|
||||
char byte_out=0, cont;
|
||||
|
||||
if ( estados == NULL )
|
||||
{
|
||||
outportb( Port_Address[Lpt_usado-1], estadosb );
|
||||
Salida[ ampl - 1 ] = estadosb;
|
||||
} else {
|
||||
byte_out = estados -> Salida0;
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 1) );
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 2) );
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 3) );
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 4) );
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 5) );
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 6) );
|
||||
byte_out = ( byte_out | ( ( estados -> Salida1 ) << 7) );
|
||||
outportb( Port_Address[Lpt_usado-1], byte_out );
|
||||
Salida[ ampl - 1] = byte_out;
|
||||
}
|
||||
|
||||
outportb( Port_Address[Lpt_usado-1] + 2, ( 0x00 | ( ( ampl & 0x01 ) << 2) | ( !( ampl & 0x02 ) << 1) | ( !( ampl & 0x03 ) << 0) ) );
|
||||
|
||||
outportb( Port_Address[Lpt_usado-1] , 0x00 );
|
||||
outportb( Port_Address[Lpt_usado-1] + 2, 0x03 );
|
||||
|
||||
return byte_out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Escribe el estado de una salida ( On/Off ), cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| salida ( Si 1 ampl. 0 a 3 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
//Û
|
||||
unsigned char Escribe_Salida( char salida, char estado )
|
||||
{
|
||||
char ampl = (salida / 8) + 1;
|
||||
char byte_out;
|
||||
|
||||
byte_out = Lee_Salidas( ampl, NULL );
|
||||
|
||||
byte_out = ( byte_out & ~( 0x01 << ( salida - (ampl-1)*8 ) ) ) | ( estado << ( salida - (ampl-1)*8 ) );
|
||||
|
||||
Escribe_Salidas( ampl, NULL, byte_out );
|
||||
|
||||
return byte_out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Lee las entradas y la almacena en la variable estados. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
unsigned char Lee_Entradas( char ampl, ESTADOS *estados )
|
||||
{
|
||||
unsigned char byte_out=0;
|
||||
|
||||
outportb( Port_Address[Lpt_usado-1] , 0xFF );
|
||||
outportb( Port_Address[Lpt_usado-1] + 2, ( 0x08 | ( ( ampl & 0x01 ) << 2) | ( !( ampl & 0x02 ) << 1) | ( !( ampl & 0x03 ) << 0) ) );
|
||||
|
||||
|
||||
byte_out = inportb ( Port_Address[Lpt_usado-1] );
|
||||
|
||||
outportb( Port_Address[Lpt_usado-1] , 0x00 );
|
||||
outportb( Port_Address[Lpt_usado-1] + 2, 0x03 );
|
||||
|
||||
if ( estados != NULL )
|
||||
{
|
||||
estados -> Salida0 = ( 0x01 & byte_out ) != 0;
|
||||
estados -> Salida1 = ( 0x02 & byte_out ) != 0;
|
||||
estados -> Salida2 = ( 0x04 & byte_out ) != 0;
|
||||
estados -> Salida3 = ( 0x08 & byte_out ) != 0;
|
||||
estados -> Salida4 = ( 0x10 & byte_out ) != 0;
|
||||
estados -> Salida5 = ( 0x20 & byte_out ) != 0;
|
||||
estados -> Salida6 = ( 0x40 & byte_out ) != 0;
|
||||
estados -> Salida7 = ( 0x80 & byte_out ) != 0;
|
||||
}
|
||||
|
||||
return byte_out;
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
| Lee una entrada cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| entrada ( Si 1 ampl. 0 a 3 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
unsigned char Lee_Entrada( char entrada )
|
||||
{
|
||||
char byte_out;
|
||||
char ampl = (entrada / 8) + 1;
|
||||
|
||||
byte_out = Lee_Entradas( ampl, NULL );
|
||||
|
||||
// byte_out = ( byte_out & !( 0x01 << ( entrada - ampl*8 ) ) ) | ( estado << ( entrada - ampl*8 ) );
|
||||
byte_out = ( ( byte_out & ( 0x01 << ( entrada - (ampl-1)*8 ) ) ) ) != 0;
|
||||
return byte_out;
|
||||
|
||||
}
|
||||
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛFÛIÛNÛÛÛDÛEÛÛÛLÛAÛÛÛÛCÛAÛBÛEÛCÛEÛRÛAÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
|
||||
|
||||
|
||||
|
179
PRN_CNT.H
Normal file
179
PRN_CNT.H
Normal file
@ -0,0 +1,179 @@
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| CABECERA A INCLUIR EN TUS PROGRAMAS: #include "PRN_CNT.h" |
|
||||
| |
|
||||
| |
|
||||
>>> Rutinas para la comunicaci¢n USUARIO <---> PRN_CNT <<<
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
#define LEER 0
|
||||
#define ESCRIBIR 1
|
||||
#define OK 1
|
||||
#define FALLO_DESCONOCIDO -1
|
||||
#define NO_ARCHIVO -2
|
||||
#define ARCHIVO_INCORRECTO -3
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
#define ERROR_EN_ATEXIT -9
|
||||
#define FUNCION_YA_REGISTRADA 5
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Salida0; char Salida1; char Salida2; char Salida3;
|
||||
char Salida4; char Salida5; char Salida6; char Salida7;
|
||||
} ESTADOS;
|
||||
|
||||
|
||||
extern char Lpt_usado;
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Esta rutina debe ser llamada al iniciar el programa que use las librerias. |
|
||||
| |
|
||||
| Es la encargada de poner a cero todas la salidas, al principio y al salir. |
|
||||
| |
|
||||
| |
|
||||
| Parametros de Entrada: ( ninguno ) |
|
||||
| Parametros de Salida: |
|
||||
| OK Todo ha ido bien. |
|
||||
| ERROR_EN_ATEXIT Error registrando funci¢n |
|
||||
| FUNCION_YA_REGISTRADA No es la 1¦ vez |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
int Init_all(void);
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| WARNING: |
|
||||
| El uso de la siguiente funci¢n esta indicada solo para usuarios |
|
||||
| experimentados, se debe usar en lugar de la funci¢n anterior. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ( LEER/ESCRIBIR ) // L/E los registros del fich|
|
||||
| ( %s ) // _ero %s |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| 1 Ok! OK |
|
||||
| -1 Fallo desconocido FALLO_DESCONOCIDO |
|
||||
| -2 Archivo no existe NO_ARCHIVO |
|
||||
| -3 Error archivo no valido ARCHIVO_INCORRECTO |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
int Register( char leer_escribir, char *file );
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Resetea todas las salidas y las pone a cero. |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
void Reset_all(void);
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Obtiene el estado de las salidas ( On/Off ), de la ampliacion AMPL. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, solo se devolvera el char de salida. |
|
||||
\**************************************************************************/
|
||||
unsigned char Lee_Salidas( char ampl, ESTADOS *estados );
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Obtiene el estado de una salida ( On/Off ), cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| salida ( Si 1 ampl. 0 a 7 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
unsigned char Lee_Salida( char salida );
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Escribe la variable 'estados' ( On/Off ), en la ampliacion AMPL. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| estadosb Byte con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, se utilizar el char con los estados. |
|
||||
\**************************************************************************/
|
||||
unsigned char Escribe_Salidas( char ampl, ESTADOS *estados, char estadosb );
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| salida ( Si 1 ampl. 0 a 3 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| estado ( ON / OFF ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
unsigned char Escribe_Salida( char salida, char estado );
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Lee las entradas y la almacena en la variable estados. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| ampl Ampliaci¢n donde debemos mirar |
|
||||
| estados Puntero a estructura con los estados |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con los estados |
|
||||
| |
|
||||
| NOTA: si &estados es NULL, solo se devolvera el char de salida. |
|
||||
\**************************************************************************/
|
||||
|
||||
unsigned char Lee_Entradas( char ampl, ESTADOS *estados );
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
| |
|
||||
| Lee una entrada cualquiera. |
|
||||
| |
|
||||
| Parametros de Entrada: |
|
||||
| entrada ( Si 1 ampl. 0 a 7 ) |
|
||||
| ( Si 10 ampl. 0 a 80 ) |
|
||||
| |
|
||||
| Parametros de Salida: |
|
||||
| char 1Byte con el estado |
|
||||
| |
|
||||
\**************************************************************************/
|
||||
|
||||
unsigned char Lee_Entrada( char entrada );
|
||||
|
||||
|
||||
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛFÛIÛNÛÛÛDÛEÛÛÛLÛAÛÛÛÛCÛAÛBÛEÛCÛEÛRÛAÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
||||
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
||||
#PRN_CNT
|
||||
|
||||
|
||||
*10/04/1996*
|
||||
|
||||
ToDo: wwtcf?
|
||||
|
||||
|
||||

|
Loading…
x
Reference in New Issue
Block a user