motofreek
Junior Member level 2
Hi, this is my code to control an LED via sms but it's not working.
#include <16F876A.h>
#include <string.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7,errors)
#int_rda
void dispose_chars() {
char ts;
ts=getch(); // dispose phone's replies
}
void main() {
char ch;
char s1[12];
char s2[6]="307";
char s3[7]="5603";
int i,j;
char *ptr1;
char *ptr2;
start:
delay_ms(500);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
puts("ATE0"); // phone replies "OK"
delay_ms(1000);
puts("at+csms=1"); // phone replies "OK"
delay_ms(1000);
puts("at+cnmi=1,2,0,0,1");
delay_ms(1000); //phone replies "OK"
disable_interrupts(INT_RDA);
while(true){
ch=getch();
switch(ch){
case '7': // look for '7' in incoming string
for(i=0; i<3; i++)
s1=getch();
break;
case 'C':
for(j=0; j<4; j++) //look for 'C' in incoming string
s1[j]=getch();
break;
}
ptr1=strstr(s1, s2);
ptr2=strstr(s1, s3);
if(ptr2){
output_low(pin_B7);
puts("at+cnmi=1,2,0,0,1"); // The phone responds "OK" here. But the program freezes and I am
// unable to turn the LED on again. Prog. works ok if I leave out this line !
// But I need it to re-initialise the phone !
}
if(ptr1)
output_high(pin_B7);
}
}
Can anyone check to see what I am doing wrong ?
Thanks in advance.
#include <16F876A.h>
#include <string.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7,errors)
#int_rda
void dispose_chars() {
char ts;
ts=getch(); // dispose phone's replies
}
void main() {
char ch;
char s1[12];
char s2[6]="307";
char s3[7]="5603";
int i,j;
char *ptr1;
char *ptr2;
start:
delay_ms(500);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
puts("ATE0"); // phone replies "OK"
delay_ms(1000);
puts("at+csms=1"); // phone replies "OK"
delay_ms(1000);
puts("at+cnmi=1,2,0,0,1");
delay_ms(1000); //phone replies "OK"
disable_interrupts(INT_RDA);
while(true){
ch=getch();
switch(ch){
case '7': // look for '7' in incoming string
for(i=0; i<3; i++)
s1=getch();
break;
case 'C':
for(j=0; j<4; j++) //look for 'C' in incoming string
s1[j]=getch();
break;
}
ptr1=strstr(s1, s2);
ptr2=strstr(s1, s3);
if(ptr2){
output_low(pin_B7);
puts("at+cnmi=1,2,0,0,1"); // The phone responds "OK" here. But the program freezes and I am
// unable to turn the LED on again. Prog. works ok if I leave out this line !
// But I need it to re-initialise the phone !
}
if(ptr1)
output_high(pin_B7);
}
}
Can anyone check to see what I am doing wrong ?
Thanks in advance.