#include <18F4520.h>
#device PASS_STRINGS=IN_RAM
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOSTVREN
#use delay(clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)// RS232 Estándar
#include <stdlib.h>
#define LED PIN_D0
#define ON output_high
#define OFF output_low
int const maxLongBuffRX=42;
char bufferRX[maxLongBuffRX];
int indBufferRX=0x00;
char XCommand[maxLongBuffRX];
char flag_RptaCommand;
int i;
void Add_bufferRX(char c);
void SendATCommand( char *pCommandTX );
#int_rda
void serial_isr() {
if(kbhit()){
Add_bufferRX(getc());
}
flag_RptaCommand = 1;
}
void Ini_buff_rec(void){
int i;
for(i=0;i<maxLongBuffRX;i++){
bufferRX[i]=0x00;
}
indBufferRX=0x00;
}
void Add_bufferRX(char c){
switch(c){
case 0x0D:
break;
case 0x0A:
break;
default:
bufferRX[indBufferRX++]=c;
}
}
void SendATCommand( char *pCommandTX, char *pRXCommand ){
char *ptr;
Ini_buff_rec();
flag_RptaCommand = 0;
printf ("%s",pCommandTX);
putc('\r');
while ( flag_RptaCommand == 0);
//ptr=strstr(bufferRX,pRXCommand);
if(strncmp(bufferRX,pRXCommand,strlen(pRXCommand))== 0)
ON (LED);
else
OFF (LED);
}
void main(){
OFF(LED);
enable_interrupts(INT_RDA);
clear_interrupt(INT_RDA);
enable_interrupts(GLOBAL);
SendATCommand("AT", "OK");
delay_ms(200);
while (TRUE);
}