TODOPIC
Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: esperanzachat en 27 de Abril de 2020, 19:59:34
-
Hola a todos, estoy tratando de usar el modulo sim 800l para mandar la temperatura que mido con el sensor, pero no puedo detectar las respuestas del modulo para saber si lo tengo que resetear o no, es algo que no puedo hacer porque no soy muy inteligente. este es mi codigo. Para probar mando un sms y detector el + que recibe el modulo, en proteus funciona pero en la vida real no:
///ALARMA GSM
///SENSOR DS18B20
////RESET MODULO AT+CPOWD=1
#include <16F88.h>
#device PASS_STRINGS = IN_RAM
#FUSES NOWDT // No Watch Dog Timer
#FUSES INTRC_IO // >>> Oscilador interno, no CLKOUT
#FUSES PUT // Power Up Timer
#FUSES NOMCLR // Master Clear pin enable
#FUSES BROWNOUT // Reset when brownout detected
#FUSES PROTECT // Code not protected from reading
#FUSES NOCPD // No EE protection
//#use Fast_io(a)
#use delay(clock = 4MHz)
#use RS232(UART1, BAUD = 9600, ERRORS) // UART configuration & initialization
#include <1Wire2.c>
#include <DS1820.c>
float Temperatura=25;
int8 Intentos=0;
int1 flagcommand=0;///todavia no recibi un comando
// CONSTANTES /////////////////////////////////////////////////////////////////
int const lenbuff=75; // Longitud de buffer, Ajustar
// a lo que desees (o te sea posible)
// VARIABLES EN RAM ///////////////////////////////////////////////////////////
int xbuff=0x00; // Índice: siguiente char en cbuff
char cbuff[lenbuff]; // Buffer
char rcvchar=0x00; // último caracter recibido
// Declaración de Funciones ///////////////////////////////////////////////////
void inicbuff(void); // Borra buffer
int addcbuff(char c); // añade caracter recibido al buffer
// Desarrollo de Funciones ////////////////////////////////////////////////////
void inicbuff(void){ // Inicia a cbuff -------------------
int i;
for(i=0;i<lenbuff;i++){ // Bucle que pone a 0 todos los
cbuff[ i ]=0x00; // caracteres en el buffer
}
xbuff=0x00; // Inicializo el indice de siguiente // caracter
}
int addcbuff(char c)
{ // Añade a cbuff -----------------------
cbuff[xbuff++]=c; // Añade caracter recibido al Buffer
}
// INTERRUPCIONES /////////////////////////////////////////////////////////////
#int_rda
void serial_isr() { // Interrupción recepción serie USART
//restart_wdt();
rcvchar=0x00; // Inicializo caracter recibido
if(kbhit()){ // Si hay algo pendiente de recibir ...
rcvchar=getc(); // lo descargo y ...
addcbuff(rcvchar); // lo añado al buffer y ...
}
}
void ResetearModulo()
{
Intentos=0;
inicbuff(); // Borra buffer al inicio
printf("AT+CPOWD=1\r");
delay_ms(50000);///espera a que se inicie el modulo
printf("AT\r");
}
void ConfigurarModulo()
{
Intentos=0;
Repetir: //inicbuff(); // Borra buffer al inicio
Intentos++;
printf("AT+CMGF=1\r");
delay_ms(1000);
/*if((cbuff[0]!='O')&&(cbuff[1]!='K')&&(Intentos<5))goto Repetir;
if(Intentos>=5)
{
ResetearModulo();
goto Repetir;
}*/
}
void MandarTemperatura()
{
Intentos=0;
Repetir2: // inicbuff(); // Borra buffer al inicio
printf("AT+CMGS=\"543496508790\"\r");
Delay_ms(1000);
printf("Temperatura:");
printf("%f\r\n",Temperatura);
printf("%c", 0x1A);
delay_ms(1000);
/*if((cbuff[0]!='O')&&(cbuff[1]!='K')&&(Intentos<5))goto Repetir2;
if(Intentos>=5)
{
ResetearModulo();
goto Repetir2;
}*/
}
void Mandar_SMS_Alarma()
{
}
void main() {
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
set_tris_a(0xFF);
set_tris_b(0x27);
output_high(PIN_B3);///Habilita el modulo;
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);
DS1820_Read(0);//Lee el sensor
delay_ms(10000);///espera que pase el tiempo
ConfigurarModulo();
Temperatura=DS1820_Read(0);//Lee el sensor
MandarTemperatura();
while(TRUE) {
delay_ms(1000);///espera que pase el tiempo
//if((cbuff[0]=='+')&&(cbuff[1]=='C')&&(cbuff[2]=='M')&&(cbuff[3]=='T')&&(cbuff[4]==':'))
if((cbuff[0]=='+'))MandarTemperatura();////recibe sms
printf("NADA\r");
///if((cbuff[0]=='+')&&(cbuff[1]=='C')&&(cbuff[2]=='M')&&(cbuff[3]=='T')&&(cbuff[4]==':'))///RECIBE SMS
// {
if (flagcommand==0)inicbuff(); // Borra buffer al inicio
}
}
// End of codeSeguramente ustedes me podran ayudar, tengo todo armado en lo fisico. Gracias por su tiempo.