Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please help me control an LED via SMS !

Status
Not open for further replies.

motofreek

Junior Member level 2
Joined
Dec 12, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,450
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.
 

Enable the interrupt before using puts
 

I tried to re-enable the interrupt after the LED went off so that I could start over and turn it on again but the interrupt doesn't seem to be triggered at that point. Why not ? Please help...

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);
delay_ms(2000);
enable_interrupt(INT_RDA);// This doesn't seem to be triggered by the response after the puts("at+cnmi=1,2,0,0,1")
puts("at+cnmi=1,2,0,0,1"); // The phone responds "OK" here. But the program freezes and I am unable to turn 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);
}
}
 

Please help. I tried enabling the interrupt before the "puts()" but it just freezes !
 

Every time you write the separate interrupts (ex: RDA), you have to write the Global Interrupt bit after that.

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

Try with this.
 

Dear Nandu,

Hi!!
Greetings.
I HAVE YOUR CONTACT FROM THE EDABOARD.COM FORUM.
From one your posts i saw a possible salvation /solution to our problem which is described below.

We are running a not for profit social enterprise Project LAMP(Light A Million Places) of providing LED based
lighting kits to BOPand urban poor who don,t have access to grid electricity.We plan to lease our LED based
solar lighting Lanterns to the poor hawkers who use polluting sources such as kerosene lamps to light their carts.
We believe that our LED based solar lighting lantern will increase his income and improve his life besides saving
the environment .Now for this project for Urban hawkers We wish to develop:

A system-integrated micro controller and user interface that regulates the function of our Hawkers's Lantern
based on proof of payments. I.E We should be able to switch on/off the LED solar lighting kit through SMS sent thro a mobile phone.
Further we need to develop a Revenue Management System, a centralized software solution in the “cloud”, accessible via
SMS gateway and over the internet, for payment processing and accounts settlement.

If you have any solution catering to our requirement pls let us know.
Regards
Arun k Jain
M: 9810507108
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top