TODOPIC
Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: cguzman en 14 de Marzo de 2013, 17:07:15
-
Buenas Tardes companeros
Soy nuevo en el foro y me llamo Cesar
Me dieron un proyecto con unos PICS 18F452 para mejorarlo y esta programado en PIC C de CCS el problema es que esta disenados 4 como esclavos y un maestro que se comunica con una PC el maestro se comunica mediante RS232 con la PC pero no se como es la comunicacion de los esclavos con el maestro.
En los programas de los 4 esclavos es el mismo y el maestro distinto y en e programa de los esclavos no aparece alguna comunicacion como PSP,I2C o SPI habilitada.
El maestro y los esclavos tiene en comun los pines 29,20 y 19.
Pero del maestro sale el pin 24 al 25 del esclavo.
pin 23 al 25 del esclavo.
pin 22 al 25 del esclavo.
pin 21 al 25 del esclavo.
29=RX/DT/RC7
20=SCL/SCK/RC3
19=CCP1/RC2/
25=SD1/SDA/RC4
24=RD3/PSP3
23=RD2/PSP2
22=RD1/PSP1
21=RD0/PSP0
Estas son las funciones de cada pin.
-
Debe de ser SPI, 3 hilos comunes (SDI, SDO, SCK) y 1 hilo único por esclavo para el Chip Select (CS).
PSP es un puerto paralelo de 8 bits, tendrías que tener 8 hilos comunes.
I2C, solo usa 2 hilos, y el programa para cada esclavo debe de incluir una dirección distinta.
El patillaje que hayan utilizado, no es relevante, pueden haber implementado el SPI por software.
-
gracias planeta9999
cometi un error al decir que pines tienen en comun voy a especificar mejor.
29=RX/DT/RC7
20=SCL/SCK/RC3
19=CCP1/RC2/
25=SD1/SDA/RC4
24=RD3/PSP3
23=RD2/PSP2
22=RD1/PSP1
21=RD0/PSP0
El maestro y los esclavos tienen las siguientes terminales comunes.
Maestro Esclavo1 Esclavo2 Esclavo3 Esclavo4
29=RX/DT/RC7 29=RX/DT/RC7 29=RX/DT/RC7 29=RX/DT/RC7 29=RX/DT/RC7
20=SCL/SCK/RC3 20=SCL/SCK/RC3 20=SCL/SCK/RC3 20=SCL/SCK/RC3 20=SCL/SCK/RC
19=CCP1/RC2 19=CCP1/RC2/ 19=CCP1/RC2/ 19=CCP1/RC2/ 19=CCP1/RC2/
24=RD3/PSP3 25=SD1/SDA/RC4
23=RD2/PSP2 25=SD1/SDA/RC4
22=RD1/PSP1 25=SD1/SDA/RC4
21=RD0/PSP0 25=SD1/SDA/RC4
pero en el programa de los esclavos no veo como envia la informacion al maestro y no esta especificado que usa I2C
-
Tiene que ser SPI.
-
Tiene que ser SPI.
Opino lo mismo, añadiendo que esta implementado por software.
-
Gracias por su ayuda.
Solo si me pudieran dar mas de informacion sobre esta comunicacion en CCS
-
Gracias por su ayuda.
Solo si me pudieran dar mas de informacion sobre esta comunicacion en CCS
La primera respuesta que me dio san google fue ESTA (http://es.wikipedia.org/wiki/Serial_Peripheral_Interface), y fijate que coincidencia en la segunda imagen se muestra tal cual tienes tu circuito.
En el foro usa el buscador con la palabra SPI y veras ya codigo y diagramas.
Saludos.
-
Gracias por su ayuda KALLITOS
-
Disculpen solo algo que me tiene desconcertado es que ni en el programa de los esclavos ni en el del maestro estre configurado el SPI, entonces como es que usa este comunicacion.
-
Tiene que ser SPI.
Opino lo mismo, añadiendo que esta implementado por software.
Coloca tu codigo, y te podremos dar mas luces.
-
ESTE ES EL CODIGO DE LOS 4 ESCLAVOS
#include <18F452.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(clock=18432000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define LEN_BUFF 488
#define Active 1
#define Entrada 3
#define Salida_Alto 4
#define Salida_Bajo 5
#define Define_Entrada 1
#define Define_Salida 2
#include <string.h>
BYTE buffer[500] ;
int8 xstate ;
int16 nrx ;
int16 ntx ;
int8 xId ;
int8 ni ;
int8 xcmd ;
int8 xbuffer[20];
int8 xinput[24];
int8 xread ;
int8 xmachine ;
int8 nporta ;
int8 nportb ;
int8 nportc ;
int8 nportd ;
int8 nporte ;
int8 xpin[24] ;
int8 xAnd ;
int8 xOr ;
int8 xTmp ;
int8 xptr;
#int_RDA
void RDA_isr()
{
buffer[nrx] = getc() ;
nrx = nrx + 1;
if( nrx > LEN_BUFF ) nrx = 0 ;
}
void CheckId()
{
xId = 0 ;
if( ( input( PIN_C0) == 0 ) && ( input(PIN_C1 ) == 0 ) ) { xId = 1 ; }
if( ( input( PIN_C0) == 1 ) && ( input(PIN_C1 ) == 0 ) ) { xId = 2 ; }
if( ( input( PIN_C0) == 0 ) && ( input(PIN_C1 ) == 1 ) ) { xId = 3 ; }
if( ( input( PIN_C0) == 1 ) && ( input(PIN_C1 ) == 1 ) ) { xId = 4 ; }
}
void MakeAnd()
{
xAnd = 0xFF ;
if(( xbuffer[0] == Define_Salida ) || ( xbuffer[0] == Salida_Bajo ) || ( xbuffer[0] == Salida_Alto ) ) xAnd = xAnd - 1 ;
if(( xbuffer[1] == Define_Salida ) || ( xbuffer[1] == Salida_Bajo ) || ( xbuffer[1] == Salida_Alto ) ) xAnd = xAnd - 2 ;
if(( xbuffer[2] == Define_Salida ) || ( xbuffer[2] == Salida_Bajo ) || ( xbuffer[2] == Salida_Alto ) ) xAnd = xAnd - 4 ;
if(( xbuffer[3] == Define_Salida ) || ( xbuffer[3] == Salida_Bajo ) || ( xbuffer[3] == Salida_Alto ) ) xAnd = xAnd - 8 ;
if(( xbuffer[4] == Define_Salida ) || ( xbuffer[4] == Salida_Bajo ) || ( xbuffer[4] == Salida_Alto ) ) xAnd = xAnd - 16 ;
if(( xbuffer[5] == Define_Salida ) || ( xbuffer[5] == Salida_Bajo ) || ( xbuffer[5] == Salida_Alto ) ) xAnd = xAnd - 32 ;
if(( xbuffer[6] == Define_Salida ) || ( xbuffer[6] == Salida_Bajo ) || ( xbuffer[6] == Salida_Alto ) ) xAnd = xAnd - 64 ;
if(( xbuffer[7] == Define_Salida ) || ( xbuffer[7] == Salida_Bajo ) || ( xbuffer[7] == Salida_Alto ) ) xAnd = xAnd - 128 ;
}
void MakeOr()
{
xOr = 0 ;
if(( xbuffer[0] == Define_Entrada ) || ( xbuffer[0] == Entrada ) ) xOr = xOr + 1 ;
if(( xbuffer[1] == Define_Entrada ) || ( xbuffer[1] == Entrada ) ) xOr = xOr + 2 ;
if(( xbuffer[2] == Define_Entrada ) || ( xbuffer[2] == Entrada ) ) xOr = xOr + 4 ;
if(( xbuffer[3] == Define_Entrada ) || ( xbuffer[3] == Entrada ) ) xOr = xOr + 8 ;
if(( xbuffer[4] == Define_Entrada ) || ( xbuffer[4] == Entrada ) ) xOr = xOr + 16 ;
if(( xbuffer[5] == Define_Entrada ) || ( xbuffer[5] == Entrada ) ) xOr = xOr + 32 ;
if(( xbuffer[6] == Define_Entrada ) || ( xbuffer[6] == Entrada ) ) xOr = xOr + 64 ;
if(( xbuffer[7] == Define_Entrada ) || ( xbuffer[7] == Entrada ) ) xOr = xOr + 128 ;
}
void MakeAndA()
{
xAnd = 0xFF ;
if( ( xbuffer[0] == Define_Salida ) || ( xbuffer[0] == Salida_Bajo ) || ( xbuffer[0] == Salida_Alto ) ) xAnd = xAnd - 1 ;
if( ( xbuffer[1] == Define_Salida ) || ( xbuffer[1] == Salida_Bajo ) || ( xbuffer[1] == Salida_Alto ) ) xAnd = xAnd - 2 ;
if( ( xbuffer[2] == Define_Salida ) || ( xbuffer[2] == Salida_Bajo ) || ( xbuffer[2] == Salida_Alto ) ) xAnd = xAnd - 4 ;
if( ( xbuffer[3] == Define_Salida ) || ( xbuffer[3] == Salida_Bajo ) || ( xbuffer[3] == Salida_Alto ) ) xAnd = xAnd - 8 ;
if( ( xbuffer[4] == Define_Salida ) || ( xbuffer[4] == Salida_Bajo ) || ( xbuffer[4] == Salida_Alto ) ) xAnd = xAnd - 32 ;
}
void MakeAndE()
{
xAnd = 0xFF ;
if(( xbuffer[5] == Define_Salida ) || ( xbuffer[5] == Salida_Bajo ) || ( xbuffer[5] == Salida_Alto ) ) xAnd = xAnd - 1;
if(( xbuffer[6] == Define_Salida ) || ( xbuffer[6] == Salida_Bajo ) || ( xbuffer[6] == Salida_Alto ) ) xAnd = xAnd - 2;
if(( xbuffer[7] == Define_Salida ) || ( xbuffer[7] == Salida_Bajo ) || ( xbuffer[7] == Salida_Alto ) ) xAnd = xAnd - 4;
}
void MakeOrA()
{
xOr = 0 ;
if(( xbuffer[0] == Define_Entrada ) || ( xbuffer[0] == Entrada ) ) xOr = xOr + 1 ;
if(( xbuffer[1] == Define_Entrada ) || ( xbuffer[1] == Entrada ) ) xOr = xOr + 2 ;
if(( xbuffer[2] == Define_Entrada ) || ( xbuffer[2] == Entrada ) ) xOr = xOr + 4 ;
if(( xbuffer[3] == Define_Entrada ) || ( xbuffer[3] == Entrada ) ) xOr = xOr + 8 ;
if(( xbuffer[4] == Define_Entrada ) || ( xbuffer[4] == Entrada ) ) xOr = xOr + 32 ;
}
void MakeOrE()
{
xAnd = 0 ;
if(( xbuffer[5] == Define_Entrada ) || ( xbuffer[5] == Entrada ) ) xOr = xOr + 1;
if(( xbuffer[6] == Define_Entrada ) || ( xbuffer[6] == Entrada ) ) xOr = xOr + 2;
if(( xbuffer[7] == Define_Entrada ) || ( xbuffer[7] == Entrada ) ) xOr = xOr + 4;
}
void Refresh_xPin()
{
if( xpin[0] == Salida_Bajo ) output_bit( PIN_D0 , 0 ) ;
if( xpin[0] == Salida_Alto ) output_bit( PIN_D0 , 1 ) ;
if( xpin[1] == Salida_Bajo ) output_bit( PIN_D1 , 0 ) ;
if( xpin[1] == Salida_Alto ) output_bit( PIN_D1 , 1 ) ;
if( xpin[2] == Salida_Bajo ) output_bit( PIN_D2 , 0 ) ;
if( xpin[2] == Salida_Alto ) output_bit( PIN_D2 , 1 ) ;
if( xpin[3] == Salida_Bajo ) output_bit( PIN_D3 , 0 ) ;
if( xpin[3] == Salida_Alto ) output_bit( PIN_D3 , 1 ) ;
if( xpin[4] == Salida_Bajo ) output_bit( PIN_D4 , 0 ) ;
if( xpin[4] == Salida_Alto ) output_bit( PIN_D4 , 1 ) ;
if( xpin[5] == Salida_Bajo ) output_bit( PIN_D5 , 0 ) ;
if( xpin[5] == Salida_Alto ) output_bit( PIN_D5 , 1 ) ;
if( xpin[6] == Salida_Bajo ) output_bit( PIN_D6 , 0 ) ;
if( xpin[6] == Salida_Alto ) output_bit( PIN_D6 , 1 ) ;
if( xpin[7] == Salida_Bajo ) output_bit( PIN_D7 , 0 ) ;
if( xpin[7] == Salida_Alto ) output_bit( PIN_D7 , 1 ) ;
if( xpin[8] == Salida_Bajo ) output_bit( PIN_B0 , 0 ) ; if( xpin[8] == Salida_Alto ) output_bit( PIN_B0 , 1 ) ;
if( xpin[9] == Salida_Bajo ) output_bit( PIN_B1 , 0 ) ; if( xpin[9] == Salida_Alto ) output_bit( PIN_B1 , 1 ) ;
if( xpin[10] == Salida_Bajo ) output_bit( PIN_B2 , 0 ) ; if( xpin[10] == Salida_Alto ) output_bit( PIN_B2 , 1 ) ;
if( xpin[11] == Salida_Bajo ) output_bit( PIN_B3 , 0 ) ; if( xpin[11] == Salida_Alto ) output_bit( PIN_B3 , 1 ) ;
if( xpin[12] == Salida_Bajo ) output_bit( PIN_B4 , 0 ) ; if( xpin[12] == Salida_Alto ) output_bit( PIN_B4 , 1 ) ;
if( xpin[13] == Salida_Bajo ) output_bit( PIN_B5 , 0 ) ; if( xpin[13] == Salida_Alto ) output_bit( PIN_B5 , 1 ) ;
if( xpin[14] == Salida_Bajo ) output_bit( PIN_B6 , 0 ) ; if( xpin[14] == Salida_Alto ) output_bit( PIN_B6 , 1 ) ;
if( xpin[15] == Salida_Bajo ) output_bit( PIN_B7 , 0 ) ; if( xpin[15] == Salida_Alto ) output_bit( PIN_B7 , 1 ) ;
if( xpin[16] == Salida_Bajo ) output_bit( PIN_A0 , 0 ) ; if( xpin[16] == Salida_Alto ) output_bit( PIN_A0 , 1 ) ;
if( xpin[17] == Salida_Bajo ) output_bit( PIN_A1 , 0 ) ; if( xpin[17] == Salida_Alto ) output_bit( PIN_A1 , 1 ) ;
if( xpin[18] == Salida_Bajo ) output_bit( PIN_A2 , 0 ) ; if( xpin[18] == Salida_Alto ) output_bit( PIN_A2 , 1 ) ;
if( xpin[19] == Salida_Bajo ) output_bit( PIN_A3 , 0 ) ; if( xpin[19] == Salida_Alto ) output_bit( PIN_A3 , 1 ) ;
if( xpin[20] == Salida_Bajo ) output_bit( PIN_A5 , 0 ) ; if( xpin[20] == Salida_Alto ) output_bit( PIN_A5 , 1 ) ;
if( xpin[21] == Salida_Bajo ) output_bit( PIN_E0 , 0 ) ; if( xpin[21] == Salida_Alto ) output_bit( PIN_E0 , 1 ) ;
if( xpin[22] == Salida_Bajo ) output_bit( PIN_E1 , 0 ) ; if( xpin[22] == Salida_Alto ) output_bit( PIN_E1 , 1 ) ;
if( xpin[23] == Salida_Bajo ) output_bit( PIN_E2 , 0 ) ; if( xpin[23] == Salida_Alto ) output_bit( PIN_E2 , 1 ) ;
}
void Update_xPin(int8 xvalue)
{
xTmp = ( xvalue - 1 ) * 8 ;
for(ni = 0 ; ni < 8 ; ni ++ )
{
if(xbuffer[ni] == Define_Salida) { xpin[ni + xTmp] = Salida_Alto ; }
if(xbuffer[ni] == Define_Entrada) { xpin[ni + xTmp] = Entrada ; }
}
Refresh_xPin() ;
}
void PreparePort( int8 xconfig , int8 xapuntador )
{
if( xapuntador == 1 )
{
xAnd = 0xFF ;
for( ni = 0 ; ni < 8 ; ni ++ ) xPin[ni] = Entrada ;
if( ( xConfig & 0x01 ) == 0x01 ) { xAnd = xAnd - 1 ; xPin[0] = Salida_Bajo ; }
if( ( xConfig & 0x02 ) == 0x02 ) { xAnd = xAnd - 2 ; xPin[1] = Salida_Bajo ; }
if( ( xConfig & 0x04 ) == 0x04 ) { xAnd = xAnd - 4 ; xPin[2] = Salida_Bajo ; }
if( ( xConfig & 0x08 ) == 0x08 ) { xAnd = xAnd - 8 ; xPin[3] = Salida_Bajo ; }
if( ( xConfig & 0x10 ) == 0x10 ) { xAnd = xAnd - 16 ; xPin[4] = Salida_Bajo ; }
if( ( xConfig & 0x20 ) == 0x20 ) { xAnd = xAnd - 32 ; xPin[5] = Salida_Bajo ; }
if( ( xConfig & 0x40 ) == 0x40 ) { xAnd = xAnd - 64 ; xPin[6] = Salida_Bajo ; }
if( ( xConfig & 0x80 ) == 0x80 ) { xAnd = xAnd - 128 ; xPin[7] = Salida_Bajo ; }
nportd = xAnd ;
set_tris_d(nportd);
}
if( xapuntador == 2 )
{
xAnd = 0xFF ;
for( ni = 8 ; ni < 16 ; ni ++ ) xPin[ni] = Entrada ;
if( ( xConfig & 0x01 ) == 0x01 ) { xAnd = xAnd - 1 ; xPin[8] = Salida_Bajo ; }
if( ( xConfig & 0x02 ) == 0x02 ) { xAnd = xAnd - 2 ; xPin[9] = Salida_Bajo ; }
if( ( xConfig & 0x04 ) == 0x04 ) { xAnd = xAnd - 4 ; xPin[10] = Salida_Bajo ; }
if( ( xConfig & 0x08 ) == 0x08 ) { xAnd = xAnd - 8 ; xPin[11] = Salida_Bajo ; }
if( ( xConfig & 0x10 ) == 0x10 ) { xAnd = xAnd - 16 ; xPin[12] = Salida_Bajo ; }
if( ( xConfig & 0x20 ) == 0x20 ) { xAnd = xAnd - 32 ; xPin[13] = Salida_Bajo ; }
if( ( xConfig & 0x40 ) == 0x40 ) { xAnd = xAnd - 64 ; xPin[14] = Salida_Bajo ; }
if( ( xConfig & 0x80 ) == 0x80 ) { xAnd = xAnd - 128 ; xPin[15] = Salida_Bajo ; }
nportb = xAnd ;
set_tris_b( nportb );
}
if( xapuntador == 3 )
{
xAnd = 0xFF ;
for( ni = 16 ; ni < 24 ; ni ++ ) xPin[ni] = Entrada ;
if( ( xConfig & 0x01 ) == 0x01 ) { xAnd = xAnd - 1 ; xPin[16] = Salida_Bajo ; }
if( ( xConfig & 0x02 ) == 0x02 ) { xAnd = xAnd - 2 ; xPin[17] = Salida_Bajo ; }
if( ( xConfig & 0x04 ) == 0x04 ) { xAnd = xAnd - 4 ; xPin[18] = Salida_Bajo ; }
if( ( xConfig & 0x08 ) == 0x08 ) { xAnd = xAnd - 8 ; xPin[19] = Salida_Bajo ; }
if( ( xConfig & 0x10 ) == 0x10 ) { xAnd = xAnd - 32 ; xPin[20] = Salida_Bajo ; }
nporta = xAnd ;
set_tris_a(nporta);
if( ( xConfig & 0x20 ) == 0x20 ) { xAnd = xAnd - 1 ; xPin[21] = Salida_Bajo ; }
if( ( xConfig & 0x40 ) == 0x40 ) { xAnd = xAnd - 2 ; xPin[22] = Salida_Bajo ; }
if( ( xConfig & 0x80 ) == 0x80 ) { xAnd = xAnd - 4 ; xPin[23] = Salida_Bajo ; }
nporte = xAnd ;
set_tris_e( nporte );
}
}
void SetConfig()
{
if( xstate == 5 )
{
xbuffer[xptr] = buffer[ntx];
xptr++;
if( xptr == 12 )
{
xstate = 0 ;
if( xId == 1 ) { PreparePort( xbuffer[0] , 1 ) ; PreparePort( xbuffer[1] , 2 ) ; PreparePort( xbuffer[2] , 3 ) ; Refresh_xPin() ; }
if( xId == 2 ) { PreparePort( xbuffer[3] , 1 ) ; PreparePort( xbuffer[4] , 2 ) ; PreparePort( xbuffer[5] , 3 ) ; Refresh_xPin() ; }
if( xId == 3 ) { PreparePort( xbuffer[6] , 1 ) ; PreparePort( xbuffer[7] , 2 ) ; PreparePort( xbuffer[8] , 3 ) ; Refresh_xPin() ; }
if( xId == 4 ) { PreparePort( xbuffer[9] , 1 ) ; PreparePort( xbuffer[10] , 2 ) ; PreparePort( xbuffer[11] , 3 ) ; Refresh_xPin() ; }
}
}
if( xstate == 4 )
{
xbuffer[xptr] = 0 ;
if( ( xcmd == 1 ) || ( xcmd == 4 ) || ( xcmd == 7 ) || ( xcmd == 10 ) ) { xTmp = xptr ; }
if( ( xcmd == 2 ) || ( xcmd == 5 ) || ( xcmd == 8 ) || ( xcmd == 11 ) ) { xTmp = 8 + xptr ; }
if( ( xcmd == 3 ) || ( xcmd == 6 ) || ( xcmd == 9 ) || ( xcmd == 12 ) ) { xTmp = 16 + xptr ; }
if( ( buffer[ntx] == 'W' ) || ( buffer[ntx] == 'w' ) ) { xbuffer[xptr] = Define_Salida ; }
if( ( buffer[ntx] == 'r' ) || ( buffer[ntx] == 'R' ) ) { xbuffer[xptr] = Define_Entrada ; }
if( ( buffer[ntx] == 'x' ) || ( buffer[ntx] == 'X' ) ) { xbuffer[xptr] = xpin[ xTmp ] ; } ;
xptr ++ ;
if( xptr == 8 )
{
xstate = 0 ;
if( xId == 1 )
{
if( xcmd == 1 ) { MakeAnd() ; nportd = nportd & xAnd ; MakeOr() ; nportd = nportd | xOr ; set_tris_d(nportd); Update_xPin( 1 ) ; }
if( xcmd == 2 ) { MakeAnd() ; nportb = nportb & xAnd ; MakeOr() ; nportb = nportb | xOr ; set_tris_b(nportd); Update_xPin( 2 ) ; }
if( xcmd == 3 )
{
MakeAndA() ; nporta = nporta & xAnd ; MakeOrA() ; nporta = nporta | xOr ; set_tris_a(nportd);
MakeAndE() ; nporte = nporte & xAnd ; MakeOrE() ; nporte = nporte | xOr ; set_tris_e(nportd);
Update_xPin(3);
}
}
if( xId == 2 )
{
if( xcmd == 4 ) { MakeAnd() ; nportd = nportd & xAnd ; MakeOr() ; nportd = nportd | xOr ; set_tris_d(nportd); Update_xPin( 1 ) ; }
if( xcmd == 5 ) { MakeAnd() ; nportb = nportb & xAnd ; MakeOr() ; nportb = nportb | xOr ; set_tris_b(nportd); Update_xPin( 2 ) ; }
if( xcmd == 6 )
{
MakeAndA() ; nporta = nporta & xAnd ; MakeOrA() ; nporta = nporta | xOr ; set_tris_a(nportd);
MakeAndE() ; nporte = nporte & xAnd ; MakeOrE() ; nporte = nporte | xOr ; set_tris_e(nportd);
Update_xPin(3);
}
}
if( xId == 3 )
{
if( xcmd == 7 ) { MakeAnd() ; nportd = nportd & xAnd ; MakeOr() ; nportd = nportd | xOr ; set_tris_d(nportd); Update_xPin( 1 ) ; }
if( xcmd == 8 ) { MakeAnd() ; nportb = nportb & xAnd ; MakeOr() ; nportb = nportb | xOr ; set_tris_b(nportd); Update_xPin( 2 ) ; }
if( xcmd == 9 )
{
MakeAndA() ; nporta = nporta & xAnd ; MakeOrA() ; nporta = nporta | xOr ; set_tris_a(nportd);
MakeAndE() ; nporte = nporte & xAnd ; MakeOrE() ; nporte = nporte | xOr ; set_tris_e(nportd);
Update_xPin(3);
}
}
if( xId == 4 )
{
if( xcmd == 10 ) { MakeAnd() ; nportd = nportd & xAnd ; MakeOr() ; nportd = nportd | xOr ; set_tris_d(nportd); Update_xPin( 1 ) ; }
if( xcmd == 11 ) { MakeAnd() ; nportb = nportb & xAnd ; MakeOr() ; nportb = nportb | xOr ; set_tris_b(nportd); Update_xPin( 2 ) ; }
if( xcmd == 12 )
{
MakeAndA() ; nporta = nporta & xAnd ; MakeOrA() ; nporta = nporta | xOr ; set_tris_a(nportd);
MakeAndE() ; nporte = nporte & xAnd ; MakeOrE() ; nporte = nporte | xOr ; set_tris_e(nportd);
Update_xPin(3);
}
}
}
}
if( xstate == 3 )
{
xstate = 0 ;
xptr = 0 ;
if( ( buffer[ntx] == 'A' ) || ( buffer[ntx] == 'a' ) ) { xstate = 4 ; xcmd = 1 ; }
if( ( buffer[ntx] == 'B' ) || ( buffer[ntx] == 'b' ) ) { xstate = 4 ; xcmd = 2 ; }
if( ( buffer[ntx] == 'C' ) || ( buffer[ntx] == 'c' ) ) { xstate = 4 ; xcmd = 3 ; }
if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) ) { xstate = 4 ; xcmd = 4 ; }
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xstate = 4 ; xcmd = 5 ; }
if( ( buffer[ntx] == 'F' ) || ( buffer[ntx] == 'f' ) ) { xstate = 4 ; xcmd = 6 ; }
if( ( buffer[ntx] == 'G' ) || ( buffer[ntx] == 'g' ) ) { xstate = 4 ; xcmd = 7 ; }
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) { xstate = 4 ; xcmd = 8 ; }
if( ( buffer[ntx] == 'I' ) || ( buffer[ntx] == 'i' ) ) { xstate = 4 ; xcmd = 9 ; }
if( ( buffer[ntx] == 'J' ) || ( buffer[ntx] == 'j' ) ) { xstate = 4 ; xcmd = 10 ;}
if( ( buffer[ntx] == 'K' ) || ( buffer[ntx] == 'k' ) ) { xstate = 4 ; xcmd = 11 ;}
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) { xstate = 4 ; xcmd = 12 ;}
if( ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) ) { xstate = 5 ; xptr = 0 ; }
}
if( xstate == 2 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'T' ) || ( buffer[ntx] == 't' ) ) { xstate = 3 ; }
}
if( xstate == 1 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xstate = 2 ; }
}
}
void Write_xPin(int8 xvalue)
{
xTmp = ( xvalue - 1 ) * 8 ;
for(ni = 0 ; ni < 8 ; ni ++ )
{
if(xbuffer[ni] == Salida_Bajo ) { xpin[ni + xTmp] = Salida_Bajo ; }
if(xbuffer[ni] == Salida_Alto ) { xpin[ni + xTmp] = Salida_Alto ; }
}
Refresh_xPin() ;
}
void Write_One_Pin()
{
if(( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) xpin[xcmd] = Salida_Alto ;
if(( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) xpin[xcmd] = Salida_Bajo ;
Refresh_xPin();
}
void EvaluateWrite(int8 xConfig , int8 xapuntador )
{
xcmd = ( xapuntador - 1 ) * 8 ;
xTmp = 0x01 ;
for( ni = 0 ; ni < 8 ; ni ++ )
{
if( xpin[xcmd] != Entrada )
{
if( ( xConfig & xTmp ) == xTmp ) { xpin[xcmd] = Salida_Alto ; } else { xpin[xcmd] = Salida_Bajo ; }
}
xcmd ++ ;
xTmp = xTmp << 1 ;
}
}
void CommandWR()
{
if( xstate == 15 )
{
xbuffer[xptr] = buffer[ntx] ;
xptr ++ ;
if( xptr == 12 )
{
xstate = 0 ;
if( xId == 1 )
{
EvaluateWrite( xbuffer[0] , 1 ) ; EvaluateWrite( xbuffer[1] , 2 ) ; EvaluateWrite( xbuffer[2] , 3 ) ; Refresh_xPin();
}
if( xId == 2 )
{
EvaluateWrite( xbuffer[3] , 1 ) ; EvaluateWrite( xbuffer[4] , 2 ) ; EvaluateWrite( xbuffer[5] , 3 ) ; ; Refresh_xPin();
}
if( xId == 3 )
{
EvaluateWrite( xbuffer[6] , 1 ) ; EvaluateWrite( xbuffer[7] , 2 ) ; EvaluateWrite( xbuffer[8] , 3 ) ; ; Refresh_xPin();
}
if( xId == 4 )
{
EvaluateWrite( xbuffer[9] , 1 ) ; EvaluateWrite( xbuffer[10] , 2 ) ; EvaluateWrite( xbuffer[11] , 3 ) ; ; Refresh_xPin();
}
}
}
if( xstate == 14 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) || ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) )
{
if( xId == 1 )
{
if( ( xcmd > 0 ) && ( xcmd < 25 ) ) { xcmd = xcmd - 1; Write_One_Pin(); }
}
if( xId == 2 )
{
if( ( xcmd > 24 ) && ( xcmd < 49 ) ) { xcmd = xcmd - 25; Write_One_Pin(); }
}
if( xId == 3 )
{
if( ( xcmd > 48 ) && ( xcmd < 73 ) ) { xcmd = xcmd - 49; Write_One_Pin(); }
}
if( xId == 4 )
{
if( ( xcmd > 72 ) && ( xcmd < 97 ) ) { xcmd = xcmd - 73; Write_One_Pin(); }
}
}
}
if( xstate == 13 )
{
xstate = 0 ;
if( ( buffer[ntx] > 47 ) && ( buffer[ntx] < 58 ) ) { xcmd = xcmd + ( buffer[ntx] - 48 ) ; xstate = 14 ; }
}
if( xstate == 12 )
{
xbuffer[xptr] = Entrada;
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) { xbuffer[xptr] = Salida_Alto ; }
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) { xbuffer[xptr] = Salida_Bajo ; }
xptr ++ ;
if( xptr == 8 )
{
xstate = 0 ;
if( xId == 1 )
{
if( xcmd == 1 ) { Write_xPin(1) ; }
if( xcmd == 2 ) { Write_xPin(2) ; }
if( xcmd == 3 ) { Write_xPin(3) ; }
}
if( xId == 2 )
{
if( xcmd == 4 ) { Write_xPin(1) ; }
if( xcmd == 5 ) { Write_xPin(2) ; }
if( xcmd == 6 ) { Write_xPin(3) ; }
}
if( xId == 3 )
{
if( xcmd == 7 ) { Write_xPin(1) ; }
if( xcmd == 8 ) { Write_xPin(2) ; }
if( xcmd == 9 ) { Write_xPin(3) ; }
}
if( xId == 4 )
{
if( xcmd == 10 ) { Write_xPin(1) ; }
if( xcmd == 11 ) { Write_xPin(2) ; }
if( xcmd == 12 ) { Write_xPin(3) ; }
}
}
}
if( xstate == 11 )
{
xstate = 0 ;
xptr = 0 ;
if( ( buffer[ntx] == 'A' ) || ( buffer[ntx] == 'a' ) ) { xstate = 12 ; xcmd = 1 ; }
if( ( buffer[ntx] == 'B' ) || ( buffer[ntx] == 'b' ) ) { xstate = 12 ; xcmd = 2 ; }
if( ( buffer[ntx] == 'C' ) || ( buffer[ntx] == 'c' ) ) { xstate = 12 ; xcmd = 3 ; }
if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) ) { xstate = 12 ; xcmd = 4 ; }
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xstate = 12 ; xcmd = 5 ; }
if( ( buffer[ntx] == 'F' ) || ( buffer[ntx] == 'f' ) ) { xstate = 12 ; xcmd = 6 ; }
if( ( buffer[ntx] == 'G' ) || ( buffer[ntx] == 'g' ) ) { xstate = 12 ; xcmd = 7 ; }
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) { xstate = 12 ; xcmd = 8 ; }
if( ( buffer[ntx] == 'I' ) || ( buffer[ntx] == 'i' ) ) { xstate = 12 ; xcmd = 9 ; }
if( ( buffer[ntx] == 'J' ) || ( buffer[ntx] == 'j' ) ) { xstate = 12 ; xcmd = 10 ; }
if( ( buffer[ntx] == 'K' ) || ( buffer[ntx] == 'k' ) ) { xstate = 12 ; xcmd = 11 ; }
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) { xstate = 12 ; xcmd = 12 ; }
if( ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) ) { xstate = 15 ; xptr = 0 ; }
if( ( buffer[ntx] > 47 ) && ( buffer[ntx] < 58 ) ) { xcmd = buffer[ntx] - 48 ; xcmd = xcmd * 10 ; xstate = 13 ; }
}
if( xstate == 10 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 11 ; }
}
}
void Evaluate_Input()
{
if( xpin[0] == Entrada ) { xinput[0] = input( PIN_D0 ) ; } else { xinput[0] = 1 ; }
if( xpin[1] == Entrada ) { xinput[1] = input( PIN_D1 ) ; } else { xinput[1] = 1 ; }
if( xpin[2] == Entrada ) { xinput[2] = input( PIN_D2 ) ; } else { xinput[2] = 1 ; }
if( xpin[3] == Entrada ) { xinput[3] = input( PIN_D3 ) ; } else { xinput[3] = 1 ; }
if( xpin[4] == Entrada ) { xinput[4] = input( PIN_D4 ) ; } else { xinput[4] = 1 ; }
if( xpin[5] == Entrada ) { xinput[5] = input( PIN_D5 ) ; } else { xinput[5] = 1 ; }
if( xpin[6] == Entrada ) { xinput[6] = input( PIN_D6 ) ; } else { xinput[6] = 1 ; }
if( xpin[7] == Entrada ) { xinput[7] = input( PIN_D7 ) ; } else { xinput[7] = 1 ; }
if( xpin[8] == Entrada ) { xinput[8] = input( PIN_B0 ) ; } else { xinput[8] = 1 ; }
if( xpin[9] == Entrada ) { xinput[9] = input( PIN_B1 ) ; } else { xinput[9] = 1 ; }
if( xpin[10] == Entrada ) { xinput[10] = input( PIN_B2 ) ; } else { xinput[10] = 1 ; }
if( xpin[11] == Entrada ) { xinput[11] = input( PIN_B3 ) ; } else { xinput[11] = 1 ; }
if( xpin[12] == Entrada ) { xinput[12] = input( PIN_B4 ) ; } else { xinput[12] = 1 ; }
if( xpin[13] == Entrada ) { xinput[13] = input( PIN_B5 ) ; } else { xinput[13] = 1 ; }
if( xpin[14] == Entrada ) { xinput[14] = input( PIN_B6 ) ; } else { xinput[14] = 1 ; }
if( xpin[15] == Entrada ) { xinput[15] = input( PIN_B7 ) ; } else { xinput[15] = 1 ; }
if( xpin[16] == Entrada ) { xinput[16] = input( PIN_A0 ) ; } else { xinput[16] = 1 ; }
if( xpin[17] == Entrada ) { xinput[17] = input( PIN_A1 ) ; } else { xinput[17] = 1 ; }
if( xpin[18] == Entrada ) { xinput[18] = input( PIN_A2 ) ; } else { xinput[18] = 1 ; }
if( xpin[19] == Entrada ) { xinput[19] = input( PIN_A3 ) ; } else { xinput[19] = 1 ; }
if( xpin[20] == Entrada ) { xinput[20] = input( PIN_A5 ) ; } else { xinput[20] = 1 ; }
if( xpin[21] == Entrada ) { xinput[21] = input( PIN_E0 ) ; } else { xinput[21] = 1 ; }
if( xpin[22] == Entrada ) { xinput[22] = input( PIN_E1 ) ; } else { xinput[22] = 1 ; }
if( xpin[23] == Entrada ) { xinput[23] = input( PIN_E2 ) ; } else { xinput[23] = 1 ; }
if( xmachine == 3 )
{
if( input(PIN_C2) == 0 )
{
xread ++ ;
if( xread > 23 ){ xread = 0 ; }
xmachine = 1 ;
}
}
if( xmachine == 2 )
{
if( input(PIN_C2 ) == 1 ) xmachine = 3 ;
}
if( xmachine == 1 )
{
output_bit( PIN_C4 , xinput[xread]) ; xmachine = 2 ;
}
if( input(PIN_C3) == 1 ){ xread = 0 ; xmachine = 1 ; }
}
void Reset()
{
if( xstate == 72 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'T' ) || ( buffer[ntx] == 't' ) )
{
nporta = 0xFF ;
nportb = 0xFF ;
nportc = 0xAF ;
nportd = 0xFF ;
nporte = 0xFF ;
set_tris_a( nporta );
set_tris_b( nportb );
set_tris_c( nportc );
set_tris_d( nportd );
set_tris_e( nporte );
for( ni =0 ; ni < 24 ; ni ++ ) { xpin[ni] = Entrada ; }
}
}
if( xstate == 71 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'S' ) || ( buffer[ntx] == 's' ) ) { xstate = 72 ; }
}
if( xstate == 70 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 71 ; }
}
}
void evaluate()
{
while ( nrx != ntx )
{
Evaluate_Input();
SetConfig();
CommandWR();
Reset();
if( xstate == 0 )
{
if( ( buffer[ntx] == '*' )) { xstate = 70 ; }
if( ( buffer[ntx] == 'W' ) || ( buffer[ntx] == 'w' ) ) { xstate = 10 ; }
if( ( buffer[ntx] == 'S' ) || ( buffer[ntx] == 's' ) ) { xstate = 1 ; }
}
ntx = ntx + 1 ;
if( ntx > LEN_BUFF ) ntx = 0 ;
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_oscillator(False);
nporta = 0xFF ;
nportb = 0xFF ;
nportc = 0xAF ;
nportd = 0xFF ;
nporte = 0xFF ;
ntx = 0 ;
nrx = 0 ;
xmachine = 0 ;
if( input(PIN_C2) == 1 ) xread = 99 ; else { xread = 0 ; xmachine = 1 ; }
xstate = 0 ;
set_tris_a( nporta );
set_tris_b( nportb );
set_tris_c( nportc );
set_tris_d( nportd );
set_tris_e( nporte );
for( ni =0 ; ni < 24 ; ni ++ ) { xpin[ni] = Entrada ; }
CheckId();
while( True )
{
Evaluate_Input();
evaluate();
}
}
-
Y ESTE ES EL CODIGO DEL MAESTRO
#include <18F452.h>
#device adc=8
#use delay(clock=18432000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, STVREN, NODEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define LEN_BUFF 397
#define Active 1
#define T_SERIAL 5
#define TICKS 60
#include <string.h>
BYTE buffer[400] ;
BYTE bprint[200] ;
BYTE cstring[50] ;
BYTE crlf[3] ;
int8 wserial ;
int8 xstate ;
int16 nrx ;
int16 ntx ;
int8 ni ;
int8 xcmd ;
int8 xptr ;
int8 xact ;
int8 bptr;
int8 nporta[8] ;
int8 nportb[8] ;
int8 nportc[8] ;
int8 nportd[8] ;
int8 nporte[8] ;
int8 nportf[8] ;
int8 nportg[8] ;
int8 nporth[8] ;
int8 nporti[8] ;
int8 nportj[8] ;
int8 nportk[8] ;
int8 nportl[8] ;
int8 ntemp[8] ;
int8 xread ;
int8 xpointer ;
int32 xticks ;
int8 xchip1[24]; //INTERESANTE
int8 xchip2[24]; //INTERESANTE
int8 xchip3[24];
int8 xchip4[24];
int8 nt ;
#int_RDA
void RDA_isr()
{
buffer[nrx] = getc() ;
nrx = nrx + 1;
if( nrx > LEN_BUFF ) nrx = 0 ;
}
int8 checkpoint(int8 xque)
{
if( ( xque == 3) || ( xque == 2 ) || ( xque == 4) ) return(0);
else return(1);
}
void evalpoint()
{
buffer[ntx] = buffer[ntx] - 48 ;
xcmd = xcmd + buffer[ntx] ;
putc('R') ; putc('D') ;
ni = 0 ;
// Puerto A
if(( xcmd > 0 ) && ( xcmd <9 ) )
{
putc('0' ) ; ni = buffer[ntx] + 48 ; putc(ni); ni = xcmd - 1 ; nt = ni ; ni = nporta[ni];
if( checkpoint(ni) == 1 ) ni = xchip1[nt] ;
}
// Puerto B
if(( xcmd > 8 ) && ( xcmd < 17 ) )
{
if( xcmd < 10 ) putc('0') ; else putc('1');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 9 ;
nt = ni ; ni = nportb[ni];
if( checkpoint(ni) == 1 ) ni = xchip1[nt+8] ;
}
// Puerto C
if(( xcmd > 16 ) && ( xcmd < 25 ) )
{
if( xcmd < 20 ) putc('1') ; else putc('2');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 17 ; nt = ni ; ni = nportc[ni];
if( checkpoint(ni) == 1 ) ni = xchip1[nt+16] ;
}
// Puerto D
if(( xcmd > 24 ) && ( xcmd < 33 ) )
{
if( xcmd < 30 ) putc('2') ; else putc('3');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 25 ; nt = ni ; ni = nportd[ni];
if( checkpoint(ni) == 1 ) ni = xchip2[nt] ;
}
// Puerto E
if(( xcmd > 32 ) && ( xcmd < 41 ) )
{
if( xcmd < 40 ) putc('3') ; else putc('4');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 33 ; nt = ni ; ni = nporte[ni];
if( checkpoint(ni) == 1 ) ni = xchip2[nt+8] ;
}
// Puerto F
if(( xcmd > 40 ) && ( xcmd < 49 ) )
{
putc('4') ;
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 41 ; nt = ni ; ni = nportf[ni];
if( checkpoint(ni) == 1 ) ni = xchip2[nt+16] ;
}
// Puerto G
if(( xcmd > 48 ) && ( xcmd < 57 ) )
{
if( xcmd < 50 ) putc('4') ; else putc('5');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 49 ; nt = ni ; ni = nportg[ni];
if( checkpoint(ni) == 1 ) ni = xchip3[nt] ;
}
// Puerto H
if(( xcmd > 56 ) && ( xcmd < 65 ) )
{
if( xcmd < 60 ) putc('5') ; else putc('6');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 57 ; nt = ni ; ni = nporth[ni];
if( checkpoint(ni) == 1 ) ni = xchip3[nt+8] ;
}
// Puerto I
if(( xcmd > 64 ) && ( xcmd < 73 ) )
{
if( xcmd < 70 ) putc('6') ; else putc('7');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 65 ; nt = ni ; ni = nporti[ni];
if( checkpoint(ni) == 1 ) ni = xchip3[nt+16] ;
}
// Puerto J
if(( xcmd > 72 ) && ( xcmd < 81 ) )
{
if( xcmd < 80 ) putc('7') ; else putc('8');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 73 ; nt = ni ; ni = nportj[ni];
if( checkpoint(ni) == 1 ) ni = xchip4[nt] ;
}
// Puerto K
if(( xcmd > 80 ) && ( xcmd < 89 ) )
{
putc('8') ;
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 81 ; nt = ni ; ni = nportk[ni];
if( checkpoint(ni) == 1 ) ni = xchip4[nt+8] ;
}
// Puerto L
if(( xcmd > 88 ) && ( xcmd < 97 ) )
{
if( xcmd < 90 ) putc('8') ; else putc('9');
ni = buffer[ntx] + 48 ;
putc( ni ) ;
ni = xcmd - 89 ; nt = ni ; ni = nportl[ni];
if( checkpoint(ni) == 1 ) ni = xchip4[nt+16] ;
}
if( ( ni == 3) ) { putc('L' ); }
else
{
if( ( ni == 4) || ( ni == 2 ) ) putc('H' );
else putc( ni + 48 );
}
putc(13) ;
}
void MakeByte()
{
int8 nmake ;
nmake = 0 ;
if( ntemp[0] == 1 ) nmake = nmake + 0x01 ;
if( ntemp[1] == 1 ) nmake = nmake + 0x02 ;
if( ntemp[2] == 1 ) nmake = nmake + 0x04 ;
if( ntemp[3] == 1 ) nmake = nmake + 0x08 ;
if( ntemp[4] == 1 ) nmake = nmake + 0x10 ;
if( ntemp[5] == 1 ) nmake = nmake + 0x20 ;
if( ntemp[6] == 1 ) nmake = nmake + 0x40 ;
if( ntemp[7] == 1 ) nmake = nmake + 0x80 ;
ni = nmake ;
}
void CommandWR()
{
if( xstate == 25 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) || ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) )
{
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) ni = 3 ; else ni = 4 ;
if( xcmd < 9 ) { xptr = xcmd - 1 ; if( ( nporta[xptr]> 1 ) && ( nporta[xptr] < 5 ) ) nporta[xptr] = ni ; }
if( ( xcmd > 8 ) && ( xcmd < 17 ) ) { xptr = xcmd - 9 ; if( ( nportb[xptr]> 1 ) && ( nportb[xptr] < 5 ) ) nportb[xptr] = ni ; }
if( ( xcmd > 16 ) && ( xcmd < 25 ) ) { xptr = xcmd - 17 ; if( ( nportc[xptr]> 1 ) && ( nportc[xptr] < 5 ) ) nportc[xptr] = ni ; }
if( ( xcmd > 24 ) && ( xcmd < 33 ) ) { xptr = xcmd - 25 ; if( ( nportd[xptr]> 1 ) && ( nportd[xptr] < 5 ) ) nportd[xptr] = ni ; }
if( ( xcmd > 32 ) && ( xcmd < 41 ) ) { xptr = xcmd - 33 ; if( ( nporte[xptr]> 1 ) && ( nporte[xptr] < 5 ) ) nporte[xptr] = ni ; }
if( ( xcmd > 40 ) && ( xcmd < 49 ) ) { xptr = xcmd - 41 ; if( ( nportf[xptr]> 1 ) && ( nportf[xptr] < 5 ) ) nportf[xptr] = ni ; }
if( ( xcmd > 48 ) && ( xcmd < 57 ) ) { xptr = xcmd - 49 ; if( ( nportg[xptr]> 1 ) && ( nportg[xptr] < 5 ) ) nportg[xptr] = ni ; }
if( ( xcmd > 56 ) && ( xcmd < 65 ) ) { xptr = xcmd - 57 ; if( ( nporth[xptr]> 1 ) && ( nporth[xptr] < 5 ) ) nporth[xptr] = ni ; }
if( ( xcmd > 64 ) && ( xcmd < 73 ) ) { xptr = xcmd - 65 ; if( ( nporti[xptr]> 1 ) && ( nporti[xptr] < 5 ) ) nporti[xptr] = ni ; }
if( ( xcmd > 72 ) && ( xcmd < 81 ) ) { xptr = xcmd - 73 ; if( ( nportj[xptr]> 1 ) && ( nportj[xptr] < 5 ) ) nportj[xptr] = ni ; }
if( ( xcmd > 80 ) && ( xcmd < 89 ) ) { xptr = xcmd - 81 ; if( ( nportk[xptr]> 1 ) && ( nportk[xptr] < 5 ) ) nportk[xptr] = ni ; }
if( ( xcmd > 88 ) && ( xcmd < 97 ) ) { xptr = xcmd - 89 ; if( ( nportl[xptr]> 1 ) && ( nportl[xptr] < 5 ) ) nportl[xptr] = ni ; }
sprintf( cstring , "OK") ; puts(cstring);
}
}
if( xstate == 24 )
{
xstate = 0 ;
if(( buffer[ntx] > 47 ) && ( buffer[ntx] < 58 ) )
{
xstate = 25 ;
buffer[ntx] = buffer[ntx] - 48 ;
xcmd = xcmd + buffer[ntx] ;
}
}
if( xstate == 23 )
{
ni = buffer[ntx] ;
if( ( ni & 0x01 ) == 0x01 ) ntemp[0] = 4 ; else ntemp[0] = 3 ;
if( ( ni & 0x02 ) == 0x02 ) ntemp[1] = 4 ; else ntemp[1] = 3 ;
if( ( ni & 0x04 ) == 0x04 ) ntemp[2] = 4 ; else ntemp[2] = 3 ;
if( ( ni & 0x08 ) == 0x08 ) ntemp[3] = 4 ; else ntemp[3] = 3 ;
if( ( ni & 0x10 ) == 0x10 ) ntemp[4] = 4 ; else ntemp[4] = 3 ;
if( ( ni & 0x20 ) == 0x20 ) ntemp[5] = 4 ; else ntemp[5] = 3 ;
if( ( ni & 0x40 ) == 0x40 ) ntemp[6] = 4 ; else ntemp[6] = 3 ;
if( ( ni & 0x80 ) == 0x80 ) ntemp[7] = 4 ; else ntemp[7] = 3 ;
for(ni = 0 ; ni < 8 ; ni ++ )
{
if( ( xptr == 0 ) && ( nporta[ni] > 1 ) && ( nporta[ni] < 5 ) ) nporta[ni] = ntemp[ni];
if( ( xptr == 1 ) && ( nportb[ni] > 1 ) && ( nportb[ni] < 5 ) ) nportb[ni] = ntemp[ni];
if( ( xptr == 2 ) && ( nportc[ni] > 1 ) && ( nportc[ni] < 5 ) ) nportc[ni] = ntemp[ni];
if( ( xptr == 3 ) && ( nportd[ni] > 1 ) && ( nportd[ni] < 5 ) ) nportd[ni] = ntemp[ni];
if( ( xptr == 4 ) && ( nporte[ni] > 1 ) && ( nporte[ni] < 5 ) ) nporte[ni] = ntemp[ni];
if( ( xptr == 5 ) && ( nportf[ni] > 1 ) && ( nportf[ni] < 5 ) ) nportf[ni] = ntemp[ni];
if( ( xptr == 6 ) && ( nportg[ni] > 1 ) && ( nportg[ni] < 5 ) ) nportg[ni] = ntemp[ni];
if( ( xptr == 7 ) && ( nporth[ni] > 1 ) && ( nporth[ni] < 5 ) ) nporth[ni] = ntemp[ni];
if( ( xptr == 8 ) && ( nporti[ni] > 1 ) && ( nporti[ni] < 5 ) ) nporti[ni] = ntemp[ni];
if( ( xptr == 9 ) && ( nportj[ni] > 1 ) && ( nportj[ni] < 5 ) ) nportj[ni] = ntemp[ni];
if( ( xptr == 10 ) && ( nportk[ni] > 1 ) && ( nportk[ni] < 5 ) ) nportk[ni] = ntemp[ni];
if( ( xptr == 11 ) && ( nportl[ni] > 1 ) && ( nportl[ni] < 5 ) ) nportl[ni] = ntemp[ni];
}
xptr ++ ;
if( xptr> 11 )
{
xstate = 0 ;
sprintf( cstring , "OK") ; puts(cstring);
}
}
if( xstate == 22 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) ) { ntemp[xptr] = 9 ; xstate = 22 ; }
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) { ntemp[xptr] = 4 ; xstate = 22 ; }
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) { ntemp[xptr] = 3 ; xstate = 22 ; }
if ( buffer[ntx] == '0' ) { ntemp[xptr] = 5 ; xstate = 22 ; }
if ( buffer[ntx] == '1' ) { ntemp[xptr] = 6 ; xstate = 22 ; }
xptr ++ ;
if( xptr == 8 )
{
xstate = 0;
sprintf( cstring , "OK") ; puts(cstring);
for( ni = 0 ; ni < 8 ; ni ++ )
{
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 1 ) ) nporta[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 2 ) ) nportb[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 3 ) ) nportc[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 4 ) ) nportd[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 5 ) ) nporte[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 6 ) ) nportf[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 7 ) ) nportg[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 8 ) ) nporth[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 9 ) ) nporti[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 10 ) ) nportj[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 11 ) ) nportk[ni] = ntemp[ni];
if( ( ntemp[ni] > 2 ) && ( ntemp[ni] < 7 ) && ( xcmd == 12 ) ) nportl[ni] = ntemp[ni];
}
}
}
if( xstate == 21 )
{
xstate = 0 ;
xptr = 0 ;
if( ( buffer[ntx] == 'A' ) || ( buffer[ntx] == 'a' ) ) { xcmd = 1 ; xstate = 22 ; }
if( ( buffer[ntx] == 'B' ) || ( buffer[ntx] == 'b' ) ) { xcmd = 2 ; xstate = 22 ; }
if( ( buffer[ntx] == 'C' ) || ( buffer[ntx] == 'c' ) ) { xcmd = 3 ; xstate = 22 ; }
if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) ) { xcmd = 4 ; xstate = 22 ; }
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xcmd = 5 ; xstate = 22 ; }
if( ( buffer[ntx] == 'F' ) || ( buffer[ntx] == 'f' ) ) { xcmd = 6 ; xstate = 22 ; }
if( ( buffer[ntx] == 'G' ) || ( buffer[ntx] == 'g' ) ) { xcmd = 7 ; xstate = 22 ; }
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) { xcmd = 8 ; xstate = 22 ; }
if( ( buffer[ntx] == 'I' ) || ( buffer[ntx] == 'i' ) ) { xcmd = 9 ; xstate = 22 ; }
if( ( buffer[ntx] == 'J' ) || ( buffer[ntx] == 'j' ) ) { xcmd = 10 ; xstate = 22 ; }
if( ( buffer[ntx] == 'K' ) || ( buffer[ntx] == 'k' ) ) { xcmd = 11 ; xstate = 22 ; }
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) { xcmd = 12 ; xstate = 22 ; }
if( ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) ) { xstate = 23 ; }
if( ( buffer[ntx] == 'Y' ) || ( buffer[ntx] == 'y' ) ) { xstate = 26 ; }
if(( buffer[ntx] > 47 ) && ( buffer[ntx] < 58 ) )
{
xstate = 24 ;
xcmd = buffer[ntx] - 48 ;
xcmd = xcmd * 10 ;
}
}
if( xstate == 20 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 21 ; }
}
}
void lputc( int8 x_gprint )
{
bprint[bptr] = x_gprint ;
bptr ++ ;
bprint[bptr] = 0 ;
}
void AjusteRD( int8 xajuste )
{
int8 nbuu ; int8 lbuu ; int8 lchip ;
if( ( xajuste == 1 ) || ( xajuste == 2 ) || ( xajuste == 3 ) ) { nbuu = ( xajuste - 1 ) * 8 ; lchip = 1 ; }
if( ( xajuste == 4 ) || ( xajuste == 5 ) || ( xajuste == 6 ) ) { nbuu = ( xajuste - 4 ) * 8 ; lchip = 2 ; }
if( ( xajuste == 7 ) || ( xajuste == 8 ) || ( xajuste == 9 ) ) { nbuu = ( xajuste - 7 ) * 8 ; lchip = 3 ; }
if( ( xajuste == 10 ) || ( xajuste == 11 ) || ( xajuste == 12 ) ) { nbuu = ( xajuste - 10 ) * 8 ; lchip = 4 ; }
for( ni = 0 ; ni < 8 ; ni ++ )
{
lbuu = 0 ;
if( ntemp[ni] == 3) { lputc('L' ); lbuu = 1 ; }
if( ( ntemp[ni] == 4) || ( ntemp[ni] == 2 ) ) { lputc('H' ); lbuu = 1 ; }
if( lbuu == 0 )
{
if( lchip == 1 )
{
if( xchip1[nbuu] == 0 ) { lputc('0' ) ; } else { lputc('1'); }
}
if( lchip == 2 )
{
if( xchip2[nbuu] == 0 ) { lputc('0' ) ; } else { lputc('1'); }
}
if( lchip == 3 )
{
if( xchip3[nbuu] == 0 ) { lputc('0' ) ; } else { lputc('1'); }
}
if( lchip == 4 )
{
if( xchip4[nbuu] == 0 ) { lputc('0' ) ; } else { lputc('1'); }
}
}
nbuu++ ;
}
}
void CommandRD()
{
if( xstate == 12 )
{
if(( buffer[ntx] > 47 ) && ( buffer[ntx] < 58 ) )
{
xstate = 0 ;
evalpoint();
}
}
if( xstate == 11 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'A' ) || ( buffer[ntx] == 'a' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('A') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporta[ni] ; AjusteRD(1); puts( bprint );
}
if( ( buffer[ntx] == 'B' ) || ( buffer[ntx] == 'b' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('B') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportb[ni] ; AjusteRD(2); puts( bprint );
}
if( ( buffer[ntx] == 'C' ) || ( buffer[ntx] == 'c' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('C') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportc[ni] ; AjusteRD(3); puts( bprint );
}
if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('D') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportd[ni] ; AjusteRD(4); puts( bprint );
}
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('E') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporte[ni] ; AjusteRD(5); puts( bprint );
}
if( ( buffer[ntx] == 'F' ) || ( buffer[ntx] == 'f' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('F') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportf[ni] ; AjusteRD(6); puts( bprint );
}
if( ( buffer[ntx] == 'G' ) || ( buffer[ntx] == 'g' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('G') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportg[ni] ; AjusteRD(7); puts( bprint );
}
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('H') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporth[ni] ; AjusteRD(8); puts( bprint );
}
if( ( buffer[ntx] == 'I' ) || ( buffer[ntx] == 'i' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('I') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporti[ni] ; AjusteRD(9); puts( bprint );
}
if( ( buffer[ntx] == 'J' ) || ( buffer[ntx] == 'j' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('J') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportj[ni] ; AjusteRD(10); puts( bprint );
}
if( ( buffer[ntx] == 'K' ) || ( buffer[ntx] == 'k' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('K') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportk[ni] ; AjusteRD(11); puts( bprint );
}
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('L') ; for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportl[ni] ; AjusteRD(12); puts( bprint );
}
if( ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) )
{
xstate = 0 ;
bptr = 0 ;
lputc('R');
lputc('D');
lputc('X');
for( xcmd = 0 ; xcmd < 12 ; xcmd ++ )
{
for( ni = 0 ; ni < 8 ; ni ++ )
{
if( xcmd == 0 ) ntemp[ni] = xchip1[ni];
if( xcmd == 1 ) ntemp[ni] = xchip1[ni+8];
if( xcmd == 2 ) ntemp[ni] = xchip1[ni+16];
if( xcmd == 3 ) ntemp[ni] = xchip2[ni];
if( xcmd == 4 ) ntemp[ni] = xchip2[ni+8];
if( xcmd == 5 ) ntemp[ni] = xchip2[ni+16];
if( xcmd == 6 ) ntemp[ni] = xchip3[ni];
if( xcmd == 7 ) ntemp[ni] = xchip3[ni+8];
if( xcmd == 8 ) ntemp[ni] = xchip3[ni+16];
if( xcmd == 9 ) ntemp[ni] = xchip4[ni];
if( xcmd == 10 ) ntemp[ni] = xchip4[ni+8];
if( xcmd == 11 ) ntemp[ni] = xchip4[ni+16];
}
MakeByte();
lputc(ni);
}
puts( bprint) ;
}
if( ( buffer[ntx] == 'Y' ) || ( buffer[ntx] == 'y' ) )
{
bptr = 0 ; lputc('R') ; lputc('D') ; lputc('Y') ;
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporta[ni] ; AjusteRD(1);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportb[ni] ; AjusteRD(2);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportc[ni] ; AjusteRD(3);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportd[ni] ; AjusteRD(4);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporte[ni] ; AjusteRD(5);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportf[ni] ; AjusteRD(6);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportg[ni] ; AjusteRD(7);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporth[ni] ; AjusteRD(8);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nporti[ni] ; AjusteRD(9);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportj[ni] ; AjusteRD(10);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportk[ni] ; AjusteRD(11);
for( ni = 0 ; ni < 8 ; ni ++ ) ntemp[ni] = nportl[ni] ; AjusteRD(12);
puts( bprint ) ;
}
if(( buffer[ntx] > 47 ) && ( buffer[ntx] < 58 ) )
{
xstate = 12 ;
xcmd = buffer[ntx] - 48 ;
xcmd = xcmd * 10 ;
}
}
if( xstate == 10 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) ) { xstate = 11 ; }
}
}
void SetConfig()
{
// Numero de Serie
if( xstate == 6 )
{
xstate = 0 ;
if( buffer[ntx] == '?' )
{
if ( wserial == 1 ) { sprintf( cstring , "H-M81019-001" ); }
if ( wserial == 2 ) { sprintf( cstring , "H-M81019-002" ); }
if ( wserial == 3 ) { sprintf( cstring , "H-M81019-003" ); }
if ( wserial == 4 ) { sprintf( cstring , "H-M81019-004" ); }
if ( wserial == 5 ) { sprintf( cstring , "H-M81019-005" ); }
puts( cstring );
}
}
if( xstate == 5 )
{
ni = buffer[ntx] ;
if( ( ni & 0x01 ) == 0x01 ) ntemp[0] = 2 ; else ntemp[0] = 1 ;
if( ( ni & 0x02 ) == 0x02 ) ntemp[1] = 2 ; else ntemp[1] = 1 ;
if( ( ni & 0x04 ) == 0x04 ) ntemp[2] = 2 ; else ntemp[2] = 1 ;
if( ( ni & 0x08 ) == 0x08 ) ntemp[3] = 2 ; else ntemp[3] = 1 ;
if( ( ni & 0x10 ) == 0x10 ) ntemp[4] = 2 ; else ntemp[4] = 1 ;
if( ( ni & 0x20 ) == 0x20 ) ntemp[5] = 2 ; else ntemp[5] = 1 ;
if( ( ni & 0x40 ) == 0x40 ) ntemp[6] = 2 ; else ntemp[6] = 1 ;
if( ( ni & 0x80 ) == 0x80 ) ntemp[7] = 2 ; else ntemp[7] = 1 ;
if( xptr == 0 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nporta[ni] = ntemp[ni] ; }
if( xptr == 1 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportb[ni] = ntemp[ni] ; }
if( xptr == 2 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportc[ni] = ntemp[ni] ; }
if( xptr == 3 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportd[ni] = ntemp[ni] ; }
if( xptr == 4 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nporte[ni] = ntemp[ni] ; }
if( xptr == 5 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportf[ni] = ntemp[ni] ; }
if( xptr == 6 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportg[ni] = ntemp[ni] ; }
if( xptr == 7 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nporth[ni] = ntemp[ni] ; }
if( xptr == 8 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nporti[ni] = ntemp[ni] ; }
if( xptr == 9 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportj[ni] = ntemp[ni] ; }
if( xptr == 10 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportk[ni] = ntemp[ni] ; }
if( xptr == 11 ) { for( ni = 0 ; ni < 8 ; ni ++ ) nportl[ni] = ntemp[ni] ; }
xptr ++ ;
if( xptr == 12 ) { xstate = 0 ; sprintf( cstring , "OK" ); puts(cstring); }
}
if( xstate == 4 )
{
if( ( buffer[ntx] == 'W' ) || ( buffer[ntx] == 'w' ) || ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) || ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) )
{
if( ( buffer[ntx] == 'W' ) || ( buffer[ntx] == 'w' ) || ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) )
{
if(( buffer[ntx] == 'W' ) || ( buffer[ntx] == 'w' ) ) xact = 2 ;
else xact = 1 ;
if( xcmd == 1 ) nporta[xptr] = xact ;
if( xcmd == 2 ) nportb[xptr] = xact ;
if( xcmd == 3 ) nportc[xptr] = xact ;
if( xcmd == 4 ) nportd[xptr] = xact ;
if( xcmd == 5 ) nporte[xptr] = xact ;
if( xcmd == 6 ) nportf[xptr] = xact ;
if( xcmd == 7 ) nportg[xptr] = xact ;
if( xcmd == 8 ) nporth[xptr] = xact ;
if( xcmd == 9 ) nporti[xptr] = xact ;
if( xcmd == 10 ) nportj[xptr] = xact ;
if( xcmd == 11 ) nportk[xptr] = xact ;
if( xcmd == 12 ) nportl[xptr] = xact ;
}
xptr ++ ;
if( xptr == 8 ) { sprintf( cstring , "OK" ); puts(cstring); xstate = 0 ; buffer[ntx] = 0 ; }
}
else { xstate = 0 ; }
}
if( xstate == 3 )
{
xstate = 0 ;
xptr = 0 ;
if( ( buffer[ntx] == 'A' ) || ( buffer[ntx] == 'a' ) ) { xstate = 4 ; xcmd = 1 ; }
if( ( buffer[ntx] == 'B' ) || ( buffer[ntx] == 'b' ) ) { xstate = 4 ; xcmd = 2 ; }
if( ( buffer[ntx] == 'C' ) || ( buffer[ntx] == 'c' ) ) { xstate = 4 ; xcmd = 3 ; }
if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) ) { xstate = 4 ; xcmd = 4 ; }
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xstate = 4 ; xcmd = 5 ; }
if( ( buffer[ntx] == 'F' ) || ( buffer[ntx] == 'f' ) ) { xstate = 4 ; xcmd = 6 ; }
if( ( buffer[ntx] == 'G' ) || ( buffer[ntx] == 'g' ) ) { xstate = 4 ; xcmd = 7 ; }
if( ( buffer[ntx] == 'H' ) || ( buffer[ntx] == 'h' ) ) { xstate = 4 ; xcmd = 8 ; }
if( ( buffer[ntx] == 'I' ) || ( buffer[ntx] == 'i' ) ) { xstate = 4 ; xcmd = 9 ; }
if( ( buffer[ntx] == 'J' ) || ( buffer[ntx] == 'j' ) ) { xstate = 4 ; xcmd = 10 ; }
if( ( buffer[ntx] == 'K' ) || ( buffer[ntx] == 'k' ) ) { xstate = 4 ; xcmd = 11 ; }
if( ( buffer[ntx] == 'L' ) || ( buffer[ntx] == 'l' ) ) { xstate = 4 ; xcmd = 12 ; }
if( ( buffer[ntx] == 'X' ) || ( buffer[ntx] == 'x' ) ) { xstate = 5 ; xptr = 0 ; }
}
if( xstate == 2 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'T' ) || ( buffer[ntx] == 't' ) ) { xstate = 3 ; }
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 6 ; }
}
if( xstate == 1 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xstate = 2 ; }
}
}
void Lectura_Pines()
{
xticks ++ ;
if( xticks > TICKS )
{
if( xread == 2 )
{
xread = 0 ;
}
if( xread == 1 )
{
xchip1[xpointer] = input(PIN_D0);
xchip2[xpointer] = input(PIN_D1);
xchip3[xpointer] = input(PIN_D2);
xchip4[xpointer] = input(PIN_D3);
xread ++ ;
xticks = 0 ;
output_bit(PIN_C2 , 0 );
xpointer ++ ;
if( xpointer > 23 )
{
xpointer = 0 ;
output_bit(PIN_C3, 1 );
delay_ms(2);
output_bit(PIN_C3, 0 );
}
}
if( xread == 0 )
{
xread ++ ;
output_bit(PIN_C2 , 1 );
xticks = 0 ;
}
}
}
void Reset()
{
if( xstate == 72 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'T' ) || ( buffer[ntx] == 't' ) )
{
for( ni = 0 ; ni < 8 ; ni ++ )
{
nporta[ni] = 0 ;
nportb[ni] = 0 ;
nportc[ni] = 0 ;
nportd[ni] = 0 ;
nporte[ni] = 0 ;
nportf[ni] = 0 ;
nportg[ni] = 0 ;
nporth[ni] = 0 ;
nporti[ni] = 0 ;
nportj[ni] = 0 ;
nportk[ni] = 0 ;
nportl[ni] = 0 ;
}
}
}
if( xstate == 71 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'S' ) || ( buffer[ntx] == 's' ) ) { xstate = 72 ; }
}
if( xstate == 70 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 71 ; }
}
}
void evaluate()
{
Lectura_Pines();
while ( nrx != ntx )
{
Lectura_Pines();
if( xstate == 62 )
{
xstate = 0 ;
if( buffer[ntx] == '?' )
{
sprintf( cstring , "Profit Manufacturing" );
puts(cstring);
if ( wserial == 1 ) { sprintf( cstring , "H-M81019-001" ); }
if ( wserial == 2 ) { sprintf( cstring , "H-M81019-002" ); }
if ( wserial == 3 ) { sprintf( cstring , "H-M81019-003" ); }
if ( wserial == 4 ) { sprintf( cstring , "H-M81019-004" ); }
if ( wserial == 5 ) { sprintf( cstring , "H-M81019-005" ); }
puts( cstring );
sprintf( cstring , "Version 1.81019" );
puts(cstring);
sprintf( cstring , "96-Test-Point" );
puts(cstring);
}
}
if( xstate == 61 )
{
xstate = 0 ; if( ( buffer[ntx] == 'N' ) || ( buffer[ntx] == 'n' ) ) { xstate = 62 ;}
}
if( xstate == 60 )
{
xstate = 0 ; if( ( buffer[ntx] == 'D' ) || ( buffer[ntx] == 'd' ) ) { xstate = 61 ;}
}
if( xstate == 32 )
{
xstate = 0 ;
if( buffer[ntx] == '?' ) { sprintf( cstring , "Version 1.81019" ); puts( cstring ); }
}
if( xstate == 31 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 32 ; }
}
if( xstate == 30 )
{
xstate = 0 ;
if( ( buffer[ntx] == 'E' ) || ( buffer[ntx] == 'e' ) ) { xstate = 31 ; }
}
CommandWR();
CommandRD();
SetConfig();
Reset();
if( xstate == 0 )
{
if( ( buffer[ntx] == 'S' ) || ( buffer[ntx] == 's' ) ) { xstate = 1 ; }
if( ( buffer[ntx] == 'R' ) || ( buffer[ntx] == 'r' ) ) { xstate = 10 ;}
if( ( buffer[ntx] == 'W' ) || ( buffer[ntx] == 'w' ) ) { xstate = 20 ;}
if( ( buffer[ntx] == 'V' ) || ( buffer[ntx] == 'v' ) ) { xstate = 30 ;}
if( ( buffer[ntx] == 'I' ) || ( buffer[ntx] == 'i' ) ) { xstate = 60 ;}
if( ( buffer[ntx] == '*' ) ) { xstate = 70 ;}
}
// Seccion de Donde va ir a Escribir ( Estado 10 ) o a Leer ( Estado 1 )
ntx = ntx + 1 ;
if( ntx > LEN_BUFF ) ntx = 0 ;
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
// setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(ccp_off);
setup_ccp2(ccp_off);
// setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
set_tris_a(0xFF);
set_tris_e(0xFF);
set_tris_c(0xB0);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
// Definicion de Puertos de Salida
set_tris_b(0x00);
set_tris_d(0xFF);
output_b(0x00);
output_d(0x00);
port_b_pullups (TRUE);
wserial = T_SERIAL ;
ntx = 0 ;
nrx = 0 ;
xstate = 0 ;
crlf[0] = 13 ; crlf[1] = 10 ; crlf[2] = 0 ;
for( ni = 0 ; ni < 8 ; ni ++ )
{
nporta[ni] = 0 ;
nportb[ni] = 0 ;
nportc[ni] = 0 ;
nportd[ni] = 0 ;
nporte[ni] = 0 ;
nportf[ni] = 0 ;
nportg[ni] = 0 ;
nporth[ni] = 0 ;
nporti[ni] = 0 ;
nportj[ni] = 0 ;
nportk[ni] = 0 ;
nportl[ni] = 0 ;
}
output_bit( PIN_C2 , 0 );
xread = 0 ;
xpointer = 0 ;
xticks = 0 ;
output_bit(PIN_C3, 1 );
delay_ms(250);
output_bit(PIN_C3, 0 );
sprintf( cstring , "Profit Manufacturing" );
puts(cstring);
sprintf( cstring , "Hecho en Mexico" );
puts(cstring);
sprintf( cstring , "Version 1.81019" );
puts(cstring);
while(1)
{
evaluate();
}
}
-
Hola, por lo que se ve es comunicacion serial rs232, la cuestion me parece está asi: el maestro se recibe ordenes de otro dispositivo al parecer una PC y éste lo transmite a los esclavos segun sea el caso, pero los esclavos no le responden, por lo menos via rs232 no, los esclavos sacan por sus puertos las ordenes recibidas.
En el codigo del maestro se ve bastante putc();, mas en los esclavos no.
saludos.