Hola qué tal compañeros!. He estado trabajando con un PIC18F4550 en PIC CCS 5.070 y un módulo SIM800. He logrado enviar SMS y realizar llamadas a números específicos, pero ahora tengo una necesidad debido a lo que quiero desarrollar: recibir SMS.
Como han de saber, cuando se recibe un sms, el módulo sim800 emite ciertos comandos y respuestas, por lo que antes de poder capturar eso decidí simplemente enviar el comando "AT" para recibir un "OK" como respuesta, y yo capturarlo y verificar que efectivamente sea eso.
Pues he estado intentando y mi algoritmo no logra capturar el \r\nOK\r\n que envía el módulo, simplemente me pone caracteres muy extraños. He leído en varios foros en español e inglés pero nada ha solucionado el problema. Espero puedan ayudarme, aquí les dejo el código:
#include <18F4550.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV21 //Brownout reset at 2.1V
#FUSES NOVREGEN //USB voltage regulator disabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTC //Configuration registers not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(crystal=12MHz)
#use rs232(baud=1200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#define boton PIN_D1 //boton
///////////////////////////LCD//////////////////////////////////////////////////
#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
char buffer;
char cmd[20] = {0};
int i=0;
/////////////////////////////INTERRUPCION POR RX///////////////////////////////
#INT_RDA
void RDA_isr(void)
{
cmd[i++] = getchar();
}
/////////////////////////////PROGRAMA PRINCIPAL////////////////////////////////
void main()
{
//Activamos interrupciones
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
//Inicio de LCD
lcd_init();
printf(lcd_putc,"Listo\n");
while(TRUE)
{
//Si presionamos el boton, envia AT:
if( input(boton) )
{
while( input(boton) ); //Rebote
delay_ms(200);
printf("AT\r"); //Envio AT
lcd_gotoxy(1,2);
for(int j = 0 ; j <= 7 ; j++) //Imprimimos
printf(lcd_putc,"%c",cmd[j]);
i = 0;
output_toggle(PIN_D0); //Indicador
}
}
}He decidido trabajarlo a 1200 baudios para tener la menor velocidad e intentar capturar ese OK, pero no lo he logrado. De igual forma les dejo una imagen de lo que captura el PIC y el módulo que estoy usando.
Cabe señalar que ya lo probé con la PC y el módulo anda bien y todo al 100%, de igual forma también pude enviar sms y realizar llamadas con el PIC, solamente el problema es al recibir los datos seriales del SIM800 al PIC.
Espero puedan ayudarme, muchas gracias!!!! saludos!

lcd.jpg(178.24 kB, 799x1420 - visto 828 veces)