PIC16F877A GSM REMOTE CONTROLLER compile

Discussion in 'Embedded Systems and Microcontrollers' started by artbellson, Mar 28, 2012.

  1. artbellson

    Thread Starter New Member

    Mar 25, 2012
    1
    0
    hi there! guys please help me compile this code for my compiler is having problems. i have compiled this code already but i need different baud value to match the baud to the module. i used ccs compiler when i compile this code. please compile and upload the .hex file here. thanks.

    Code ( (Unknown Language)):
    1. #if defined(__PCB__)
    2. #include <16f877a.h>*
    3. #include <string.h>*
    4. #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT*
    5. #use delay(clock=8000000) //must be 8 MHz*
    6.  
    7. #elif defined(__PCM__)
    8. #include <16f877a.h>
    9. #include <string.h>
    10. #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
    11. #use delay(clock=8000000) //must be 8 MHz*
    12.  
    13. #use rs 232(baud=2400, xmit=PIN_C6, rcv=PIN_C7) // serial*
    14.  
    15.  
    16.  
    17. void SerialInt();
    18. int TEST_AT();
    19. int SET_MEM();
    20. int SET_PDU();
    21. int SET_CNMI();
    22. int SMSALERT();
    23. int READ_SMS();
    24. int DO_CMD();
    25. int DEL_SMS();
    26. int GET_CMD();
    27. int GET_OK(int Stop_Search);
    28.  
    29. volatile int counter_search=0;
    30. volatile int counter_read=0;
    31.  
    32. Volatile int HitCounter=0;// for string comparison*
    33. Volatile int Next_CMD=0;
    34.  
    35.  
    36. volatile Char Recieve_String[70];//buffer for incoming data*
    37.  
    38. void main()
    39. {
    40. SET_TRIS_A( 0x00 );// to avoid floating pins*
    41. SET_TRIS_B( 0x00 );
    42. OUTPUT_B(0X00);
    43. SET_TRIS_C( 0x80 );
    44. SET_TRIS_D( 0x00 );
    45. SET_TRIS_E( 0x00 );
    46.  
    47. enable_interrupts(INT_RDA);// enable RDA interrupts*
    48. enable_interrupts(GLOBAL);// enable global ints*
    49.  
    50.  
    51. output_high(PIN_D1);// blink for circuit 'ON' confirmation*
    52. delay_ms(500);
    53. output_low(PIN_D1);
    54. delay_ms(500);
    55. output_high(PIN_D1);
    56. delay_ms(500);
    57. output_low(PIN_D1);
    58. Delay_ms(1000);
    59.  
    60. while(1)
    61. {
    62. if(TEST_AT())
    63. {
    64. if(SET_MEM())
    65. {
    66. if(SET_PDU())
    67. {
    68. if(SET_CNMI())
    69. {
    70. if(SMSALERT())
    71. {
    72. if(READ_SMS())
    73. {
    74. if(GET_CMD())
    75. {
    76. if(DEL_SMS())
    77. {
    78. DO_CMD();
    79. }
    80. }
    81. else
    82. {
    83. DEL_SMS();
    84. }
    85. }
    86. }
    87. }
    88. }
    89. }
    90. }
    91. }
    92.  
    93. }
    94.  
    95.  
    96. int TEST_AT()
    97. {
    98. counter_read=0;
    99.  
    100. printf("AT");//send command*
    101. putchar(0x0D);//send return ('enter' in hyperterminal)*
    102.  
    103. output_high(PIN_D1);
    104. While(counter_read<=8)//"A T \R \R \N O K \R \N" characters returned by modem*
    105. {
    106. }
    107. output_low(PIN_D1);
    108.  
    109. counter_read=0;
    110. Delay_ms(500);// ignore all remaining characters received*
    111.  
    112. if(GET_OK(0X0A))
    113. Return(1);
    114. else return(0);
    115.  
    116. }
    117. int SET_MEM()
    118. {
    119. counter_read=0;//reset all counters.*
    120.  
    121. printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");//text part of the command.*
    122. putchar(0x0D);// enter*
    123.  
    124.  
    125. While(counter_read<25)// stay here, ignore first 25 chars*
    126. {
    127. }
    128.  
    129. counter_read=0;// start filling up the array from cero...from here on, keep the incoming text for parsing*
    130.  
    131. while(counter_read<=28)// acquire all pertinent text, I'm only looking for an "OK" but for now I'm keeping all incoming txt.*
    132. {// maybe for future use...*
    133. }
    134.  
    135. counter_read=0;
    136.  
    137. Delay_ms(500);// ignore all remaining characters received..if any.*
    138.  
    139. if(GET_OK(0X1C))
    140. Return(1);
    141. else return(0);
    142. }
    143.  
    144.  
    145. int SET_PDU()
    146. {
    147. counter_read=0;
    148.  
    149. printf("AT+CMGF=1");//send command*
    150. putchar(0x0D);//send return*
    151.  
    152. While(counter_read<=15)// get all returned text*
    153. {
    154. }
    155.  
    156. counter_read=0;
    157.  
    158. Delay_ms(500);// ignore all remaining characters recieved*
    159.  
    160. if(GET_OK(0X0E))
    161. Return(1);
    162. else return(0);
    163. }
    164.  
    165.  
    166. int SET_CNMI()
    167. {
    168. counter_read=0;//reset all counters.*
    169.  
    170. printf("AT+CNMI=2,1,2,0,0");//text part of the command.*
    171. putchar(0x0D);//send return*
    172.  
    173. While(counter_read<24)// read all data*
    174. {
    175. }
    176.  
    177. counter_read=0;
    178.  
    179. Delay_ms(500);// ignore all remaining characters recieved..if any.*
    180.  
    181. if(GET_OK(0X17))
    182. Return(1);
    183. else return(0);
    184. }
    185.  
    186. int SMSALERT()
    187. {
    188. const char StrCMTI[]={"+CMTI"};
    189.  
    190. counter_read=0;
    191.  
    192. While(counter_read<=16)// read all data*
    193. {
    194. output_high(PIN_D1);// signal ready to receive sms*
    195. }
    196. counter_read=0;
    197.  
    198. Delay_ms(500);// ignore all remaining characters recieved..if any.*
    199. output_low(PIN_D1);// off receive ready light.*
    200. counter_search=2;
    201.  
    202. HitCounter=0;
    203.  
    204. while((HitCounter!=5)&&(counter_search<8))
    205. {
    206. if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
    207. HitCounter++;
    208.  
    209. counter_search++;
    210. }
    211.  
    212. if(HitCounter==0x05)
    213. Return(1);
    214. else return(0);
    215. }
    216.  
    217.  
    218. int READ_SMS()
    219. {
    220. counter_read=0;
    221.  
    222. printf("AT+CMGR=1");// send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROSCESING*
    223. putchar(0x0D);
    224.  
    225. delay_ms(3000);// long [spam] message... so give time,* buffer will loop back one time...*
    226. // text will be on second fill.*
    227. counter_read=0;
    228.  
    229. if(GET_OK(0X45))
    230. Return(1);
    231. else return(0);
    232.  
    233. }
    234.  
    235. int GET_CMD()
    236. {
    237. const char CMD1[8][7]={"Led1 0","Led1 1","Led2 0","Led2 1","Led3 0","Led3 1","Led4 0","Led4 1"};
    238.  
    239. int offset=0;
    240. int store_counter=0;
    241. counter_search=0;
    242.  
    243.  
    244. while((Recieve_String[counter_search]!='!')&&(counter_search<69))// wait till command indicator is found '!'*
    245. {
    246. counter_search++;
    247. }
    248.  
    249. counter_search=counter_search+1;// increment one to actual first letter of command*
    250. store_Counter=counter_search;// store current position for multiple searches*
    251. NEXT_CMD=0;// NEXT_CMD keeps track of the command being read, thus used*
    252. while((HitCounter!=6)&&(NEXT_CMD<8))// compare to all commands in list.*
    253. {
    254. counter_search=store_Counter;// initialize counter search with stored counter value.*
    255. offset=0;// since value of counter is unknown use a separate counter for the const array*
    256. HitCounter=0;// counts number of equal letters found.*
    257.  
    258. while((HitCounter!=6)&&(offset<=6))// keeps the counters in check...to not overshoot. and compares the strings*
    259. {
    260. if(Recieve_String[counter_search]==CMD1[NEXT_CMD][offset])// if letter is found*
    261. HitCounter++;
    262. offset++;
    263. counter_search++;
    264. }
    265.  
    266. if(HitCounter==6)// if 6 chars found...exit..*
    267. {
    268. Return(1);
    269. }
    270.  
    271. NEXT_CMD++;// if increase to search next command.*
    272.  
    273.  
    274. }
    275.  
    276. Return(0);
    277. }
    278.  
    279.  
    280. int DO_CMD()
    281. {
    282. if(NEXT_CMD==0)output_low(PIN_B1);
    283. if(NEXT_CMD==1)output_high(PIN_B1);
    284.  
    285. if(NEXT_CMD==2)output_low(PIN_B2);
    286. if(NEXT_CMD==3)output_high(PIN_B2);
    287.  
    288. if(NEXT_CMD==4)output_low(PIN_B3);
    289. if(NEXT_CMD==5)output_high(PIN_B3);
    290.  
    291. if(NEXT_CMD==6)output_low(PIN_B4);
    292. if(NEXT_CMD==7)output_high(PIN_B4);
    293.  
    294. }
    295.  
    296. int DEL_SMS()
    297. {
    298. counter_read=0;
    299.  
    300. printf("AT+CMGD=1");//send command*
    301. putchar(0x0D);//send return*
    302.  
    303. While(counter_read<=15)// get all returned text*
    304. {
    305. }
    306.  
    307. counter_read=0;
    308.  
    309. Delay_ms(500);// ignore all remaining characters received*
    310.  
    311. if(GET_OK(0X0E))
    312. Return(1);
    313. else return(0);
    314. }
    315.  
    316.  
    317. int GET_OK(Stop_Search)
    318. {
    319. counter_search=0;
    320.  
    321. while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))//check buffer until an 'O' is found or 10 chars have been checked.*
    322. {
    323. counter_search++;//obvious*
    324. }
    325.  
    326. if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))//check for a 'K' after the 'O'*
    327. {
    328. counter_search=0;
    329. Return(1);//function returns true*
    330. }
    331. Return(0);
    332. counter_search=0;
    333. }
    334.  
    335.  
    336.  
    337. #INT_RDA
    338. void SerialInt()
    339. {
    340. Recieve_String[counter_read]=getchar();
    341. counter_read++;
    342. if(counter_read==69)counter_read=0;
    343. }
     
  2. skyliner

    New Member

    May 21, 2012
    2
    0
    i am making a project based on sim900d gsm which interfaces with pic16f877a and then turns on or off the LED depending upon the sms instruction sent from a cell phone to the gsm module!! can anyone provide me a c code for the microcontroller?? using hi tech compiler
     
  3. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    I'm not sure what happened here, I look for moderated posts at least once a week, and this thread popped out of nowhere.

    If either of you are still active, I apologize.
     
Loading...