C programming of sms based device control and lcd display

Discussion in 'Programmer's Corner' started by Ammy Rao, May 6, 2013.

  1. Ammy Rao

    Thread Starter New Member

    May 6, 2013
    6
    0
    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


    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include<reg51.h>
    4. #include<intrins.h>
    5. #include<string.h>
    6. sbit relay=P1^0;
    7. void data_send(unsigned char *);
    8. void delay1();
    9. void compare();
    10. void data_send1(unsigned char *);
    11. void command_mode(unsigned char );
    12. void busy();
    13. void data_res();
    14. void lcd_init();
    15. void gsm_receive();
    16. void gsm_send(unsigned char *);
    17. void delay();
    18. void data_mode(unsigned char *);
    19. void data1_mode(unsigned char);
    20. unsigned char data_receive();
    21. void intialisation();
    22. sbit rs=P0^1;
    23. sbit rw=P0^2;
    24. sbit en=P0^3;
    25. sbit en1=P2^7;
    26. unsigned char *ch="AT\r\n";
    27. unsigned char *ch1="AT+CMGF=1\r\n";
    28. unsigned char *ch2="AT+CMGS=";
    29. //unsigned char *ch3="Hi world\r\n";
    30. unsigned char *ch4="AT+CNMI=2,2,0,0,0\r\n";
    31. unsigned char *ch5="AT+CMGR=1\r\n";
    32. unsigned char *ch6="AT+CMGD=1\r\n";
    33. unsigned char *ph1="8892600919";
    34. unsigned char *msg1="MOTOR ON";
    35. unsigned char *msg2="MOTOR OFF";
    36. unsigned char *ch7="ATEO\r\n";
    37. unsigned char *ch8="AT&W\r\n";
    38. unsigned char *ch9="+918892600xxx";
    39. unsigned char a[2],cha,ph[14],msg[10],count=0,count1=0;
    40. int main()
    41. {
    42. unsigned char j=0,cha;
    43. P1=0x00;
    44. P2=0x00;
    45. rs=0;
    46. rw=0;
    47. en=0;
    48. en1=1;
    49. SCON=0x50;
    50. TMOD=0x20;
    51. TH1=0xfd;
    52. TR1=1;
    53. a[0]='"';
    54. a[1]='\0';
    55. //gsm_send();
    56. lcd_init();
    57. gsm_receive();
    58. while(1)
    59. {
    60. command_mode(0x80);
    61. cha=data_receive();
    62. //command_mode(0x01);
    63. while(cha!='+')
    64. {
    65. cha=data_receive();
    66. }
    67. //command_mode(0x01);
    68. while(cha!='+')
    69. {
    70. cha=data_receive();
    71. }
    72. while(cha!='9')
    73. {
    74. cha=data_receive();
    75. }
    76. while(cha!='1')
    77. {
    78. cha=data_receive();
    79. }
    80.  command_mode(0x01);
    81. for(j=0;j<10;j++)
    82. {
    83. cha=data_receive();
    84. ph[j]=cha;
    85. }
    86. ph[j]='\0';
    87. while(cha!='\n')
    88. {
    89. cha=data_receive();
    90. }
    91. j=0;
    92. cha=data_receive();
    93. while(cha!='\n')
    94. {
    95. msg[j]=cha;
    96. cha=data_receive();
    97. j++;
    98. }
    99. msg[j-1]='\0';
    100. compare();
    101. }
    102. return 0;
    103. }
    104.  
    105. void data_send(unsigned char *p)
    106. {
    107. while(*p!='\0')
    108. {
    109. SBUF=*p;
    110. while(TI==0);
    111. TI=0;
    112. p++;
    113. }
    114. }
    115.  
    116. unsigned char data_receive()
    117. {
    118. unsigned char i=0,j=0,ch;
    119. RI=0;
    120. while(RI==0);
    121. ch=SBUF;
    122. return ch;
    123. }
    124. void data_res()
    125. {
    126. unsigned char i=0;
    127. while(i<4)
    128. {
    129. unsigned char ch;
    130. RI=0;
    131. while(RI==0);
    132. ch=SBUF;
    133. i++;
    134. }
    135. }
    136.  
    137. void compare()
    138. {
    139. unsigned char j=0;
    140. if(strcmp(ph,ph1)==0&&strcmp(msg,msg1)==0)
    141. {
    142. data_mode("Valid msg & no");
    143. command_mode(0xc0);
    144. data_mode(msg);
    145. relay=1;
    146. count1=0;
    147. ch9=ph;
    148. if(count>0)
    149. {
    150. gsm_send("MOTOR ALREADY ON");
    151. }
    152. else
    153. {
    154. gsm_send("MOTOR ON");
    155. }
    156. count++;
    157. }
    158. else if(strcmp(ph,ph1)==0&&strcmp(msg,msg2)==0)
    159. {
    160. data_mode("Valid msg & no");
    161. command_mode(0xc0);
    162. data_mode(msg);
    163. relay=0;
    164. count=0;
    165. ch9=ph;
    166. if(count1>0)
    167. {
    168. gsm_send("MOTOR ALREADY OFF");
    169. count=0;
    170. }
    171. else
    172. {
    173. gsm_send("MOTOR OFF");
    174. }
    175. count1++;
    176. }
    177. else if(strcmp(ph,ph1)!=0&&strcmp(msg,msg1)!=0)
    178. {
    179. ch9=ph;
    180. data_mode("Invalid no & msg");
    181. gsm_send("you r not authorised");
    182. }
    183. else if(strcmp(ph,ph1)!=0||strcmp(msg,msg1)!=0)
    184. {
    185. if(strcmp(ph,ph1)!=0)
    186. {
    187. ch9=ph;
    188. data_mode("Invalid no");
    189. command_mode(0xc0);
    190. data_mode(ph);
    191. gsm_send("you r not authorised");
    192. }
    193. else{
    194. ch9=ph;
    195. data_mode("Invalid msg");
    196. command_mode(0xc0);
    197. data_mode(msg);
    198. gsm_send("Invalid msg");
    199. }
    200. }
    201. }
    202. void command_mode(unsigned char a)
    203. {
    204. busy();
    205. rs=0;
    206. rw=0;
    207. P2=a;
    208. en=1;
    209. _nop_();
    210. _nop_();
    211. en=0;
    212. }
    213.  
    214. void busy( )
    215. {
    216. en1=1;
    217. rs=0;
    218. rw=1;
    219. while(en1)
    220. {
    221. en=0;
    222. _nop_();
    223. _nop_();
    224. en=1;
    225. }
    226. }
    227.  
    228. void data_mode(unsigned char *p)
    229. {
    230. busy();
    231. rs=1;
    232. rw=0;
    233. while(*p!='\0')
    234. {
    235. P2=*p;
    236. intialisation();
    237. p++;
    238. }
    239. }
    240.  
    241. /*void data1_mode(unsigned char p)
    242. {
    243. busy();
    244. rs=1;
    245. rw=0;
    246. P2=p;
    247. intialisation();
    248. }*/
    249.  
    250. void intialisation()
    251. {
    252. en=1;
    253. _nop_();
    254. _nop_();
    255. en=0;
    256. }
    257. void gsm_send(unsigned char *ch3)
    258. {
    259. data_send(ch);
    260. data_res();
    261. data_send(ch1);
    262. data_res();
    263. data_send(ch2);
    264. data_res();
    265. data_send(a);
    266. data_send(ch9);
    267. data_send(a);
    268. data_send("\r\n");
    269. data_send(ch3);
    270. data_res();
    271. SBUF=0x1a;
    272. while(TI==0);
    273. TI=0;
    274. }
    275. void gsm_receive()
    276. {
    277. data_send(ch7);
    278. data_res();
    279. data_send(ch8);
    280. data_res();
    281. data_send(ch1);
    282. //delay();
    283. data_res();
    284. data_send(ch4);
    285. //delay();
    286. data_res();
    287. }
    288.  
    289. void lcd_init()
    290. {
    291. command_mode(0x01);
    292. command_mode(0x38);
    293. command_mode(0x06);
    294. command_mode(0x80);                                    
    295. command_mode(0x0f);
    296. }
    297.  
    298. /*void delay1()
    299. {
    300. TMOD=0x01;
    301. TH0=0x00;
    302. TL0=0x00;
    303. TR0=1;
    304. while(TF0==0);
    305. TF0=0;
    306. TR0=0;
    307. }*/
    308.  
    309. /*void delay()//10ms delay
    310. {
    311. TMOD=0x01;
    312. TH0=0xdb;
    313. TL0=0xff;
    314. TR0=1;
    315. while(TF0==0);
    316. TF0=0;
    317. TR0=0;
    318. }*/
    319.  
    Please check it and let me know as soon as possible.
    Thanks
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,364
    ok, I have checked it.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    I don't think this will work. There are no tabs in the source code.

    Tabs are a vital ingredient.
     
  4. WBahn

    Moderator

    Mar 31, 2012
    17,767
    4,801
    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.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,364
    Shucks. You just took all the fun out of annoying a newbie.
     
  6. WBahn

    Moderator

    Mar 31, 2012
    17,767
    4,801
    Yeah... I occasionally take pity. Not often, but it does happen. :D
     
  7. Ammy Rao

    Thread Starter New Member

    May 6, 2013
    6
    0
    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...
     
  8. WBahn

    Moderator

    Mar 31, 2012
    17,767
    4,801
    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 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.

    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.
     
  9. Eric007

    Senior Member

    Aug 5, 2011
    1,044
    33
    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...?
     
  10. Ammy Rao

    Thread Starter New Member

    May 6, 2013
    6
    0
    I dont think you help...if u do...then you should advice me with the codes...
     
  11. Ammy Rao

    Thread Starter New Member

    May 6, 2013
    6
    0
    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
     
  12. Eric007

    Senior Member

    Aug 5, 2011
    1,044
    33

    I Hope *no one* will help coz you are too rude and have no manners!
     
  13. Ammy Rao

    Thread Starter New Member

    May 6, 2013
    6
    0
    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
     
  14. Ammy Rao

    Thread Starter New Member

    May 6, 2013
    6
    0
    Hahaha...
    Ok...your wish...
     
  15. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What I do not understand with this thread. What is the problem, other that the obvious stated by others.
     
  16. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,364
    I can spot a real loser from the first post.
     
  17. WBahn

    Moderator

    Mar 31, 2012
    17,767
    4,801
    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.
     
Loading...