//LCD module connections
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B4
#define LCD_DATA6 PIN_B5
#define LCD_DATA7 PIN_B6
//End LCD module connections
#include <16F877a.h>
#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4M)
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7)
#include <lcd.c>
#define BUFFER_SIZE 60 //Buffer size you can adjust this size
char buffer[10]; // Buffer de recepción
int sms=0;
char b=0x00; // Primer caracter recibido
int xbuff=0x00;
#int_RDA
RDA_isr()
{
if(kbhit())
{
if(b=='+')
{//Primer caracter del num de tel.
xbuff=0;//para que comience a escribir a la var buffer desde la 1º posición
}
buffer[xbuff++]=b;
if(buffer==",") //Caracter despues del numero de telefono.
{
sms=1;
break;
}
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
lcd_init();
printf(LCD_PUTC
, "\f WELCOME "); delay_ms(200);
enable_interrupts(global);
enable_interrupts(int_rda);
delay_ms(100);
printf("AT+CMGF=1\r\n"); //Habita el modo texto de los sms delay_ms(150);
printf("AT+CNMI=2,2,0,0,0\r\n");//los sms se envían directamente al puerto serie delay_ms(150);
printf("AT+CMGDA=DEL ALL\r\n"); //BORRAMOS SMS delay_ms(150);
while(true)
{
lcd_gotoxy(1,1);
printf(LCD_PUTC
, " Esperando SMS "); if(sms==1)
{
lcd_gotoxy(1,2);
printf(LCD_PUTC
, "%c",buffer
); delay_ms(1000);
sms=0;
}
delay_ms(100);
}
}