C programming of sms based device control and lcd display

Thread Starter

Ammy Rao

Joined May 6, 2013
6
hii all
i m doing a project, sms based device control with lcd display
so here's i m sharing a programming code of that so please help me by checking it if that's correct


Rich (BB code):
#include<reg51.h>
#include<intrins.h>
#include<string.h>
sbit relay=P1^0;
void data_send(unsigned char *);
void delay1();
void compare();
void data_send1(unsigned char *);
void command_mode(unsigned char );
void busy();
void data_res();
void lcd_init();
void gsm_receive();
void gsm_send(unsigned char *);
void delay();
void data_mode(unsigned char *);
void data1_mode(unsigned char);
unsigned char data_receive();
void intialisation();
sbit rs=P0^1;
sbit rw=P0^2;
sbit en=P0^3;
sbit en1=P2^7;
unsigned char *ch="AT\r\n";
unsigned char *ch1="AT+CMGF=1\r\n";
unsigned char *ch2="AT+CMGS=";
//unsigned char *ch3="Hi world\r\n";
unsigned char *ch4="AT+CNMI=2,2,0,0,0\r\n";
unsigned char *ch5="AT+CMGR=1\r\n";
unsigned char *ch6="AT+CMGD=1\r\n";
unsigned char *ph1="8892600919";
unsigned char *msg1="MOTOR ON";
unsigned char *msg2="MOTOR OFF";
unsigned char *ch7="ATEO\r\n";
unsigned char *ch8="AT&W\r\n";
unsigned char *ch9="+918892600xxx";
unsigned char a[2],cha,ph[14],msg[10],count=0,count1=0;
int main()
{
unsigned char j=0,cha;
P1=0x00;
P2=0x00;
rs=0;
rw=0;
en=0;
en1=1;
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
a[0]='"';
a[1]='\0';
//gsm_send();
lcd_init();
gsm_receive();
while(1)
{
command_mode(0x80);
cha=data_receive();
//command_mode(0x01);
while(cha!='+')
{
cha=data_receive();
}
//command_mode(0x01);
while(cha!='+')
{
cha=data_receive();
}
while(cha!='9')
{
cha=data_receive();
}
while(cha!='1')
{
cha=data_receive();
}
 command_mode(0x01);
for(j=0;j<10;j++)
{
cha=data_receive();
ph[j]=cha;
}
ph[j]='\0';
while(cha!='\n')
{
cha=data_receive();
}
j=0;
cha=data_receive();
while(cha!='\n')
{
msg[j]=cha;
cha=data_receive();
j++;
}
msg[j-1]='\0';
compare();
}
return 0;
}

void data_send(unsigned char *p)
{
while(*p!='\0')
{
SBUF=*p;
while(TI==0);
TI=0;
p++;
}
}

unsigned char data_receive()
{
unsigned char i=0,j=0,ch;
RI=0;
while(RI==0);
ch=SBUF;
return ch;
}
void data_res()
{
unsigned char i=0;
while(i<4)
{
unsigned char ch;
RI=0;
while(RI==0);
ch=SBUF;
i++;
}
}

void compare()
{
unsigned char j=0;
if(strcmp(ph,ph1)==0&&strcmp(msg,msg1)==0)
{
data_mode("Valid msg & no");
command_mode(0xc0);
data_mode(msg);
relay=1;
count1=0;
ch9=ph;
if(count>0)
{
gsm_send("MOTOR ALREADY ON");
}
else
{
gsm_send("MOTOR ON");
}
count++;
}
else if(strcmp(ph,ph1)==0&&strcmp(msg,msg2)==0)
{
data_mode("Valid msg & no");
command_mode(0xc0);
data_mode(msg);
relay=0;
count=0;
ch9=ph;
if(count1>0)
{
gsm_send("MOTOR ALREADY OFF");
count=0;
}
else
{
gsm_send("MOTOR OFF");
}
count1++;
}
else if(strcmp(ph,ph1)!=0&&strcmp(msg,msg1)!=0)
{
ch9=ph;
data_mode("Invalid no & msg");
gsm_send("you r not authorised");
}
else if(strcmp(ph,ph1)!=0||strcmp(msg,msg1)!=0)
{
if(strcmp(ph,ph1)!=0)
{
ch9=ph;
data_mode("Invalid no");
command_mode(0xc0);
data_mode(ph);
gsm_send("you r not authorised");
}
else{
ch9=ph;
data_mode("Invalid msg");
command_mode(0xc0);
data_mode(msg);
gsm_send("Invalid msg");
} 
}
}
void command_mode(unsigned char a)
{
busy();
rs=0;
rw=0;
P2=a;
en=1;
_nop_();
_nop_();
en=0;
}

void busy( )
{
en1=1;
rs=0;
rw=1;
while(en1)
{
en=0;
_nop_();
_nop_();
en=1;
}
}

void data_mode(unsigned char *p)
{
busy();
rs=1;
rw=0;
while(*p!='\0')
{
P2=*p;
intialisation();
p++;
}
} 

/*void data1_mode(unsigned char p)
{
busy();
rs=1;
rw=0;
P2=p;
intialisation();
}*/ 

void intialisation()
{
en=1;
_nop_();
_nop_();
en=0;
}
void gsm_send(unsigned char *ch3)
{
data_send(ch);
data_res();
data_send(ch1);
data_res();
data_send(ch2);
data_res();
data_send(a);
data_send(ch9);
data_send(a);
data_send("\r\n");
data_send(ch3);
data_res();
SBUF=0x1a;
while(TI==0);
TI=0;
}
void gsm_receive()
{
data_send(ch7);
data_res();
data_send(ch8);
data_res();
data_send(ch1);
//delay();
data_res();
data_send(ch4);
//delay();
data_res();
}

void lcd_init()
{
command_mode(0x01);
command_mode(0x38);
command_mode(0x06);
command_mode(0x80);										
command_mode(0x0f);
}

/*void delay1()
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}*/

/*void delay()//10ms delay
{
TMOD=0x01;
TH0=0xdb;
TL0=0xff;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}*/
Please check it and let me know as soon as possible.
Thanks
 

WBahn

Joined Mar 31, 2012
30,088
And for those not yet getting the hint, when you post over three hundred lines of unformatted, uncommented code and instruct people to check it and report back ASAP, you generally can't expect a very favorable response. This is especially true when the description of what the code is supposed to do is some nebulous statement and you don't even specify what device is being targeted.

So how about taking a step back and coming at it form a more reasonable direction. Test YOUR code that is supposed to be a solution to YOUR project assignment, and then post specific issues you are having, what parts of the code are supposed to do something that is not happening, a clear description of what is happening instead, and what steps you have taken to track the problem down. Then we can have a meaningful discussion and help YOU solve YOUR problem.
 

Thread Starter

Ammy Rao

Joined May 6, 2013
6
I think you all are here for fun.., not to help somebody
And Mr. WBahn...I have mentioned that its a program about sms based device control using lcd...so if u cant understand the codes don't blame on me...
Go and do some real work...because everybody dnt have enough time to waste here like you guys do...
 

WBahn

Joined Mar 31, 2012
30,088
I think you all are here for fun.., not to help somebody
Obviously you haven't bothered to peruse some of the other threads and seen how much time and effort many people on this form spend helping students and others -- and exactly none of it paid.

But we don't cater to those that feel a sense of entitlement.
And Mr. WBahn...I have mentioned that its a program about sms based device control using lcd...so if u cant understand the codes don't blame on me...
And here I was, the one person that was trying to give you some advice you could act on in order to make some headway. Oh well, live and learn. Some people want to learn and others want to whine.

Go and do some real work...because everybody dnt have enough time to waste here like you guys do...
This is actually a pretty absurd statement, when you stop to think about it. You are telling US to go and do some "real work" because not everybody has time to waste here. Well, if you don't have time to waste here, then perhaps it is YOU that should go do some real work instead of wasting OUR time. If we choose to "waste" our time here, that is a choice for US to make -- and judging from the nearly 3000 "thanks" that just the three people that have replied to this thread have received, it would appear that many other people don't see our time here as "wasted". We are just fine.

So, if you want to go have a pity party, by all means go ahead. If and when you want to learn something and take some responsibility for doing so, we will probably still be here and more than willing to help.
 

Eric007

Joined Aug 5, 2011
1,158
Go and do some real work...because everybody dnt have enough time to waste here like you guys do...
This is really rude!!!:mad: And besides that your are a newbie.
Do you really think people waste time here!? I am not going to comment much on this but this is a really bad start...why don't you just help yourself then with your sms whatever...?
 

Thread Starter

Ammy Rao

Joined May 6, 2013
6
STEP 1: Declare Variable i , and set value to 0
STEP 2: Initializing Serial Communication
STEP 3: Initializing LCD
STEP 4: Display Message "HOME AUTOMATION"
STEP 5: Set LCD Cursor To Second Line
STEP 6: Display Message " DEVELOPED BY "
STEP 7: Wait for 400 ms
STEP 8: Clear the LCD
STEP 9: Display Message "NIPAN KALITA "
STEP 10: Set LCD Cursor To Second Line
STEP 11: Display Message "KANGKAN KASHYAP "
STEP 12: Wait for 400 ms
STEP 13: Clear LCD
STEP 14: Set LCD Cursor To Second Line
STEP 15: Display Message "ALPANA DEKA "
STEP 16: Display Message "VIJAYLAKSHMI "
STEP 17: Wait for 400 ms
STEP 18: Clear LCD
STEP 19: Display "System Ready.."
STEP 20: Wait for 200 ms
STEP 21Send AT to GSM MODEM
STEP 22: Wait for 30 ms
STEP 23: Send AT+CMGF=1 to GSM Modem , it Specify ASCII Text Format
STEP 24: Wait for 40 ms
STEP 25: Send AT+CNMI=1,2,0,0,0 to Modem, it specify that, the modem will autometically send New sms to Microcontroller
STEP 26: Wait for 30 ms
STEP 27: Clear LCD
STEP 28: Set Status to FALSE
STEP 29: IF TRUE (indefinite Loop)
STEP 30 Read received character to c
STEP 31 Check , if the receive character is #
STEP 32: if true GOTO STEP 33
STEP 33 Set Status to True
STEP 34; Read the next character
STEP 35: if Status is TRUE GOTO STEP 36
STEP 36: check, if the receive character is *, if True GOTO STEP 37
STEP 37: add NULL character to buffer, so that it create a string
STEP 38: Clear LCD
STEP 39: Display Received Command to LCD
STEP 40: if Receive Command is "LIGHT ON" GOTO STEP 41 Else GOTO STEP 42
STEP 41: Set P0_0 to High , it will switch on the Relay of Light
STEP 42: if Receive Command is "LIGHT OFF" GOTO STEP 43 Else Goto STEP 44
STEP 43: Set P0_0 to Low , it will switch off the Relay of LIGHT
STEP 44: if Receive Command is "FAN ON" GOTO STEP 45 ELSE GOTO STEP 46
STEP 45: Set P0_1 to High , it will switch on the Relay of FAN
STEP 46: if Receive Command is "FAN OFF" GOTO STEP 47 ELSE GOTO STEP 48
STEP 47: Set P0_1 to Low , it will switch off the Relay of FAN
STEP 48: Set Status to False, so that , the system is ready to read next command
STEP 49: Append the receive character to Buffer
STEP 50: GOTO STEP 30
STEP 51: STOP
 

Thread Starter

Ammy Rao

Joined May 6, 2013
6
STEP 1: Declare Variable i , and set value to 0
STEP 2: Initializing Serial Communication
STEP 3: Initializing LCD
STEP 4: Display Message "HOME AUTOMATION"
STEP 5: Set LCD Cursor To Second Line
STEP 6: Display Message " DEVELOPED BY "
STEP 7: Wait for 400 ms
STEP 8: Clear the LCD
STEP 9: Display Message "NIPAN KALITA "
STEP 10: Set LCD Cursor To Second Line
STEP 11: Display Message "KANGKAN KASHYAP "
STEP 12: Wait for 400 ms
STEP 13: Clear LCD
STEP 14: Set LCD Cursor To Second Line
STEP 15: Display Message "ALPANA DEKA "
STEP 16: Display Message "VIJAYLAKSHMI "
STEP 17: Wait for 400 ms
STEP 18: Clear LCD
STEP 19: Display "System Ready.."
STEP 20: Wait for 200 ms
STEP 21Send AT to GSM MODEM
STEP 22: Wait for 30 ms
STEP 23: Send AT+CMGF=1 to GSM Modem , it Specify ASCII Text Format
STEP 24: Wait for 40 ms
STEP 25: Send AT+CNMI=1,2,0,0,0 to Modem, it specify that, the modem will autometically send New sms to Microcontroller
STEP 26: Wait for 30 ms
STEP 27: Clear LCD
STEP 28: Set Status to FALSE
STEP 29: IF TRUE (indefinite Loop)
STEP 30 Read received character to c
STEP 31 Check , if the receive character is #
STEP 32: if true GOTO STEP 33
STEP 33 Set Status to True
STEP 34; Read the next character
STEP 35: if Status is TRUE GOTO STEP 36
STEP 36: check, if the receive character is *, if True GOTO STEP 37
STEP 37: add NULL character to buffer, so that it create a string
STEP 38: Clear LCD
STEP 39: Display Received Command to LCD
STEP 40: if Receive Command is "LIGHT ON" GOTO STEP 41 Else GOTO STEP 42
STEP 41: Set P0_0 to High , it will switch on the Relay of Light
STEP 42: if Receive Command is "LIGHT OFF" GOTO STEP 43 Else Goto STEP 44
STEP 43: Set P0_0 to Low , it will switch off the Relay of LIGHT
STEP 44: if Receive Command is "FAN ON" GOTO STEP 45 ELSE GOTO STEP 46
STEP 45: Set P0_1 to High , it will switch on the Relay of FAN
STEP 46: if Receive Command is "FAN OFF" GOTO STEP 47 ELSE GOTO STEP 48
STEP 47: Set P0_1 to Low , it will switch off the Relay of FAN
STEP 48: Set Status to False, so that , the system is ready to read next command
STEP 49: Append the receive character to Buffer
STEP 50: GOTO STEP 30
STEP 51: STOP
 

WBahn

Joined Mar 31, 2012
30,088
I dont think you help...if u do...then you should advice me with the codes...
I did. I advised you to format and comment your code so that others that aren't familiar with it can understand it more easily. You chose to ignore that advise and feel that you have a right to demand that people that aren't getting paid should have to wade through your mess and figure out what you are trying to do as well as what you are actually doing. Fine. Perhaps you supervisor when, and if, you get a job will be willing to do it because you don't feel writing code well is YOUR responsibility. Or, more likely, they will be more interested in just hiring someone that does and sending you packing.
 
Top