#include<16F628A.h>
#fuses XT,PUT,NOMCLR
#use delay(clock=4M)
#use rs232(baud=300, xmit=pin_b2, rcv=pin_b1, bits=8, parity=N, stream=ModuloRF)
#use rs232(baud=9600, xmit=pin_a0, rcv=pin_a1, bits=8, parity=N, stream=PortPC)
#zero_ram
#include <string.h>
#define on output_high
#define off output_low
#define LED pin_a3
//Constantes
const int8 SizeBufer = 16;
struct BytesSerial
{
int8 ContBufer;
char Bufer[SizeBufer];
char DatoRx;
int1 CmdProcesado;
}RF;
char ComandoRF[7]="DatoOK";
char Identificador[4]="OK.";
char BuferData[16];
void RF_Process(char DatoRF);
#int_RDA
void Serial_isr(void)
{
RF.DatoRx=0;
if(kbhit(ModuloRF))
{
RF.DatoRx=getc(ModuloRF);
RF_Process(RF.DatoRx);
}
}
void main(void)
{
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(true)
{
if(RF.CmdProcesado)
{
if(!strncmp(ComandoRF,RF.Bufer,6))
{
*BuferData = strstr(RF.Bufer,Identificador);
fprintf(PortPC,"%s",RF.Bufer);
}
}
}
}
void RF_Process(char DatoRF)
{
if(!RF.CmdProcesado)
{
if(RF.ContBufer>=SizeBufer)
RF.ContBufer=0;
RF.Bufer[RF.ContBufer++]=DatoRF;
switch(DatoRF)
{
case 'c' :
break;
case '!' :
RF.CmdProcesado=1;
RF.ContBufer=0;
break;
}
}
}