#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//DEFINICIONES
#define nop delay_cycles(1) // nop;
//VARIABLES GLOBALES
int1 sync = 0, fullb = 0;
int i = 0, j = 0, k = 0, b = 1;
int inbuff1[4],inbuff2[4],outbuff[4];
int32 ctr = 0;
#INT_RDA
void serial_isr()
{
if(b==1)
if(b==2)
i++;
if((i>3)&&(b==1))
{
i = 0;
outbuff[0] = inbuff1[0];
outbuff[1] = inbuff1[1];
outbuff[2] = inbuff1[2];
outbuff[3] = inbuff1[3];
fullb = 1;
b = 2;
}
if((i>3)&&(b==2))
{
i = 0;
outbuff[0] = inbuff2[0];
outbuff[1] = inbuff2[1];
outbuff[2] = inbuff2[2];
outbuff[3] = inbuff2[3];
fullb = 1;
b = 1;
}
}
//PROTOTIPOS DE FUNCIONES
//LAZO PRINCIPAL
void main(void)
{
//Habilitar interrupciones necesarias
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
while(1)
{
nop;
if(sync)
{
//k++;
sync = 0;
}
if(fullb)
{
ctr++;
j++;
if(j==4)
{
j = 0;
fullb = 0;
}
if(!(ctr%16))
sync = 1;
}
}
}