100% found this document useful (1 vote)
112 views6 pages

#Include #Device #Include #Include #Include #Fuses #Use #Use #Include #Define #Define #Define #Define #Define #Define #Define #Include

This code is the main file for a GSM project that controls an embedded system via SMS commands. It initializes an LCD, modem communications, and I/O pins. The main loop waits for SMS messages, parses the text for commands, and takes actions like turning outputs on/off. If no SMS is received, it sends status updates until receiving a shutdown command, at which point it powers everything down in an orderly fashion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
112 views6 pages

#Include #Device #Include #Include #Include #Fuses #Use #Use #Include #Define #Define #Define #Define #Define #Define #Define #Include

This code is the main file for a GSM project that controls an embedded system via SMS commands. It initializes an LCD, modem communications, and I/O pins. The main loop waits for SMS messages, parses the text for commands, and takes actions like turning outputs on/off. If no SMS is received, it sends status updates until receiving a shutdown command, at which point it powers everything down in an orderly fashion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

F:\Projects\GSM PROJ\Source files\Main.

c
1: #include <16f877a.h>
2: #device adc=10
3: #include <stdio.h>
4: #include <stdlib.h>
5: #include <string.h>
6:
7: #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG,NOPUT
8: #use delay(clock=8000000)
9:
10: #use rs232(baud=1200, bits=8,xmit=PIN_C6, rcv=PIN_C7,PARITY=N,STOP=1,ERRORS)
11:
12: #include "GSM.c"
13:
14: #define LCD_ENABLE_PIN PIN_D1
15: #define LCD_RS_PIN PIN_D2
16: #define LCD_RW_PIN PIN_D3
17: #define LCD_DATA4 PIN_D4
18: #define LCD_DATA5 PIN_D5
19: #define LCD_DATA6 PIN_D6
20: #define LCD_DATA7 PIN_D7
21:
22: #include "lcdd.c"
23:
24: void main()
25: {
26:
27: lcd_init();
28: lcd_putc("\fBUFFER CLEARED\n");
29: delay_ms(1000);
30: set_tris_a(0X03);
31: set_tris_b(0XF0);
32: port_b_pullups(0XFF);
33: CLEAR_BUFFER();
34:
35: setup_adc(ADC_CLOCK_DIV_2);
36: setup_adc_ports(RA0_RA1_RA3_ANALOG);
37:
38:
39: output_low(PIN_B1);
40: output_low(PIN_B0);
41: output_low(PIN_A5);
42: output_low(PIN_B2);
43: output_low(PIN_B3);
44:
45: lcd_gotoxy(1,1);
46:
47: for(i=21;i>0;i--)
48: {
49: lcd_putc("\f");
50: lcd_gotoxy(i,1);
51: lcd_putc("Welcome To EEE");
52: delay_ms(300);
53:
54: }
55:
56: lcd_putc("\f");
57:
58: for(i=0;i<21;i++)
59: {
60: lcd_putc("\f");
61: lcd_gotoxy(i,1);
62: lcd_putc("MK ELECTRONICS");
63: delay_ms(300);

1
F:\Projects\GSM PROJ\Source files\Main.c
64:
65: }
66:
67: for(i=7;i>0;i--)
68: {
69: lcd_putc("\f THIS IS MK \n");
70: printf(lcd_putc,"Let's start..%d ",i);
71: delay_ms(300);
72: }
73:
74:
75:
76: output_high(PIN_B1); //multicolour
77:
78: while(1) // OUTER WHILE LOOP
79: {
80:
81: ENABLE_INTERRUPTS(GLOBAL);
82: ENABLE_INTERRUPTS(INT_RDA);
83:
84: delay_ms(1000);
85:
86: if(CHECK_COM())
87: {
88: CLEAR_BUFFER();
89: lcd_putc("\fCOMMS ARE GOOD\n");
90: lcd_putc("\MOVING ON...\n");
91: delay_ms(1000);
92: }
93: else
94: {
95: lcd_putc("\fCOMMS FAILED\n");
96: delay_ms(1000);
97: while(!CHECK_COM())
98: {
99: lcd_putc("\RETRYING - STUCK IN LOOP\n" );
100: delay_ms(1000);
101: CLEAR_BUFFER();
102: }
103: lcd_putc("\fCOMMS ARE GOOD\n");
104:
105: }
106: delay_ms(1000);
107: CLEAR_BUFFER();
108:
109: lcd_putc("\fSET MODEM TO TXT MODE\n");
110: delay_ms(1000);
111: if(SET_PDU())
112: {
113:
114: CLEAR_BUFFER();
115: lcd_putc("\OK! - MOVING ON...\n");
116: delay_ms(1000);
117: }
118: else
119: {
120: lcd_putc("\ERROR - STUCK IN LOOP...\n" );
121: while(1);
122: }
123:
124: delay_ms(1000);
125: CLEAR_BUFFER();
126:

2
F:\Projects\GSM PROJ\Source files\Main.c
127: lcd_putc("\fSETTING SMS MEMORY\n");
128: delay_ms(1000);
129:
130: if(SET_MEM())
131: {
132:
133: CLEAR_BUFFER();
134: lcd_putc("\OK! - MOVING ON...\n");
135: delay_ms(1000);
136: }
137: else
138: {
139: lcd_putc("\ERROR - STUCK IN LOOP...\n" );
140: while(1);
141: }
142:
143: delay_ms(1000);
144: CLEAR_BUFFER();
145:
146:
147: lcd_putc("\fSETTING SMS ALERT\n");
148: delay_ms(1000);
149: if(SET_CNMI())
150: {
151: CLEAR_BUFFER();
152: lcd_putc("\OK! - MOVING ON...\n");
153: delay_ms(1000);
154: }
155: else
156: {
157: lcd_putc("\ERROR - STUCK IN LOOP...\n" );
158: while(1);
159: }
160:
161: lcd_putc("\fMODEM SETUP DONE\n");
162: lcd_putc("\CLEARING BUFFER...\n");
163: CLEAR_BUFFER();
164: lcd_putc("\NEXT ---> RUN PROG\n");
165:
166: delay_ms(1000);
167: output_low(PIN_B1);
168: CLEAR_BUFFER();
169: delay_ms(1000);
170:
171: while(1) // INNER WHILE LOOP
172: {
173: delay_ms(1000);
174: lcd_putc("\f");
175: lcd_putc("\fWAITING FOR SMS\n");
176: output_low(PIN_B1);
177: output_high(PIN_B0); // blue colour
178: output_low(PIN_A5); // green colour
179: delay_ms(1000);
180:
181: OLR=input(PIN_B5); // OLR-> 1 OPN NO OLR OPT
182: VOL=input(PIN_B6); // VOL-> 0 CLS NC No supply
183:
184:
185: // if((VOL==0) && (l<3))
186: Halt: while((!VOL) || (OLR))
187: {
188: if(l<3)
189: {

3
F:\Projects\GSM PROJ\Source files\Main.c
190:
191: l++;
192: delay_ms(1000);
193: printf("AT+CMGS=\"%s\"\r",MASTER);
194: delay_ms(500);
195: if(VOL==0) printf(" SUPPLY NOT AVAILABLE\n"); // NC contact
196: if(OLR==1) printf(" PERMISSIVE NOT AVAILABLE\n" ); // NO contact
197: putchar(0x1A);
198: delay_ms(3000);
199:
200: }
201:
202: else
203: {
204: LOV=1;
205: delay_ms(1500);
206: lcd_putc("\f");
207: printf(lcd_putc,"Sleeping !!!");
208: delay_ms(1000);
209: VOL=input(PIN_B6);
210: OLR=input(PIN_B5);
211: delay_ms(3000);
212: if((VOL==1)&&(OLR==0)) goto RESTART;
213: }
214: }
215:
216: RESTART: delay_ms(1000);
217: flag=READ_SMS();
218: if (flag !=0)
219: {
220:
221: lcd_putc("\fSMS RECEIVED!!\n");
222: delay_ms(1000);
223: output_low(PIN_B0);
224: output_high(PIN_A5);
225: string_parse();
226: delay_ms(3000);
227: DISABLE_INTERRUPTS(INT_RDA);
228:
229: if((phone[0]!='+') || (phone[1] !='9') || (phone[2] !='1'))
230: goto EXIT;
231: End_Prog=0;
232:
233: if (STRING_SEARCH(CON) && (!strcmp(phone,MASTER)))
234: {
235: output_high(PIN_B3);
236: delay_ms(4000);
237: output_low (PIN_B3);
238:
239:
240: }
241: else if (STRING_SEARCH(COFF) && (!strcmp(phone,MASTER)))
242: {
243: output_high(PIN_B2);
244: delay_ms(4000);
245: output_low(PIN_B2);
246:
247:
248: }
249: else ;
250:
251:
252: delay_ms(3000);

4
F:\Projects\GSM PROJ\Source files\Main.c
253:
254:
255: CLEAR_BUFFER();
256: if (input(PIN_B4)==0) STS=1;
257: else if (input(PIN_B4)==1) STS=0;
258: else;
259:
260: READ_CURRENT();
261: delay_ms(1000);
262:
263: READ_TEMP();
264: delay_ms(1000);
265:
266:
267: lcd_putc("\f");
268: printf(lcd_putc,"%s",phone);
269: delay_ms(1000);
270: SEND_SMS(phone,msg,STS);
271: if (End_Prog==1) GOTO OUTLOOP;
272: CLEAR_BUFFER();
273: flag=0;
274:
275: } // END OF IF FLAG CONDITION
276:
277: EXIT: if(count>8)
278: {
279: DEL_SMS();
280: CLEAR_BUFFER();
281: count=0;
282: }
283: CLEAR_BUFFER();
284: memset(msg,NULL,15);
285:
286: ENABLE_INTERRUPTS(INT_RDA);
287:
288: while(!CHECK_COM())
289: {
290: lcd_putc("\Communicating....\n");
291: delay_ms(1000);
292: CLEAR_BUFFER();
293: output_high(PIN_B1);
294: output_low(PIN_A5);
295: output_low(PIN_B0);
296:
297: }
298: lcd_putc("\fCOMMS ARE GOOD\n");
299:
300: } // END OF INNER WHILE
301:
302: } // END OF OUTER WHILE
303:
304:
305: OUTLOOP: delay_ms(500);
306: lcd_putc("\f");
307: printf(lcd_putc,"Remote Shutdown");
308: delay_ms(500);
309: disable_interrupts (GLOBAL);
310: setup_adc(ADC_OFF);
311: output_low(PIN_B1);
312: output_low(PIN_B0);
313: output_low(PIN_B2);
314: output_low(PIN_B3);
315: output_low(PIN_A5);

5
F:\Projects\GSM PROJ\Source files\Main.c
316:
317:
318: } // END OF MAIN
319:
320:
321:

You might also like