-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.c
289 lines (274 loc) · 7.51 KB
/
Code.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include <reg51.h> //Library file
#include <stdio.h>
#include <string.h>
#define lcd_data P1 //Data pins connected to Port 1 of 8051 microcontroller
sbit rs=P2^0; //RS pin of LCD connected to pin 0 of Port 2
sbit rw=P2^1; //RW pin of LCD connected to pin 1 of Port 2
sbit en=P2^2; //RS pin of LCD connected to pin 2 of Port 2
void lcd_init(); //Function to initialize LCD
void cmd(unsigned char a); //Function to send command instructions to LCD
void dat(unsigned char b); //Function to send display data to LCD
void show(unsigned char *s); //Function to display data
void lcd_delay(); //Function to create delay on LCD
void delay1(unsigned int time); //Function to create delay
unsigned char rx(); //Function to store received input
char time[5];
char namegps[7], name1gps[7] = "GPRMC,",gpsdat[63];
char msggps , checkgps;
int h;
int x,y,z;
char a,b,c;
unsigned char f;
void main() //Main function
{
TMOD = 0x20; //Timer 1 in mode 2 (auto reload mode)
TH1 = TL1=0xfd; //baud rate=9600
SCON = 0x50; //Serial mode 1, 8 bit data, 1 stop bit and 1 start bit
TR1 = 1; //Start timer 1
lcd_init();
cmd(0x80); //Force cursor to beginning of first line
show("***WELCOME TO***");
cmd(0xc0); //Force cursor to beginning of second line
show("***GPS SYSTEM***");
delay1(500); //Delay of 500ms
cmd(0x01); //Clear display screen
cmd(0x80);
show("WAITING FOR");
cmd(0xc0);
show("GPS CONNECTION");
delay1(1000); //Delay of 1000ms
while(1) //If the above conditions are satisfied proceed
{
AGAIN:
loop:
while(RI==0); //Receiver Interrupt
RI=0;
if(SBUF!='$') //Starting character
{
goto loop;
}
for(f=0;f<=5;f++) //To receive 6 successive characters
{
namegps[f]=rx(); //Store received characters in the function rx()
}
checkgps=strcmp(namegps,name1gps); //String comparison (checkgps = 0; strings are equal)
if(checkgps==0)
{
for(f=0;f<=62;f++) //Get next 63 characters
{
gpsdat[f]=rx();
}
}
if(gpsdat[10]=='A') //If character 'A' is received it means that GPS is activated
{
cmd(0x01);
cmd(0x80);
show("GPS CONNECTED");
cmd(0xc0);
show("****************");
delay1(200);
}
else
{
goto AGAIN;
}
cmd(0x01);
cmd(0x80);
show("LAT:"); //Displaying Latitude values
cmd(0x84); //Cursor line 1 position 4
for(h=12;h<14;h++) //To get Latitude value in degree
{
dat(gpsdat[h]);
}
dat(223);
for(h=14;h<=15;h++) //To get Latitude value in minute
{
dat(gpsdat[h]);
}
dat(39);
for(h=17;h<=18;h++) //To get Latitude value in seconds
{
dat(gpsdat[h]);
}
dat(34);
dat('N');
cmd(0xc0);
show("LON:"); //To display Longitude values
cmd(0xc4); //Jump to second line, position 4
for(h=26;h<28;h++) //To get Longitude value in degree
{
dat(gpsdat[h]);
}
dat(223);
for(h=28;h<30;h++) //To get Longitude value in minutes
{
dat(gpsdat[h]);
}
dat(39);
for(h=31;h<=32;h++) //To get Longitude value in seconds
{
dat(gpsdat[h]);
}
dat(34);
dat('E');
delay1(2000);
cmd(0x01);
cmd(0x80);
show(" DATE "); //To display date
cmd(0xc4);
for(h=46;h<=47;h++)
{
dat(gpsdat[h]);
}
dat('/');
for(h=48;h<=49;h++)
{
dat(gpsdat[h]);
}
dat('/');
for(h=50;h<=51;h++)
{
dat(gpsdat[h]);
}
delay1(1000);
cmd(0x01);
cmd(0x80);
show(" TIME "); //To display time
cmd(0xc6);
//To display time in UTC format
dat(gpsdat[0]);
dat(gpsdat[1]);
dat(':');
dat(gpsdat[2]);
dat(gpsdat[3]);
dat(':');
dat(gpsdat[4]);
dat(gpsdat[5]);
delay1(2000);
/* Program to convert time from UTC format to IST format
x = gpsdat[2]-48;
y=gpsdat[1]-48;
z=gpsdat[0]-48;
x=x+3;
if(x>=6)
{
x=x-6;
y=y+1;
}
y=y+5;
if(y>=10)
{
y=y%10;
z=z+1;
}
if(z==2 & y>4)
{
y=y-4;
z=0;
}
if(z==1 & y>2 )
{
z=0;
y=y-2;
}
if(z==2 & y>=0)
{
if(y==0)
{
z=0;
y=8;
}
else if(y==1)
{
z=0;
y=9;
}
else if(y==2)
{
z=1;
y=0;
}
else if(y==3)
{
z=1;
y=1;
}
else if(y==4)
{
z=0;
y=0;
}
}
a = x+48;
b = y+48;
c = z+48;
cmd(0xc6);
dat(c);
dat(b);
dat(':') ;
dat(a);
dat(gpsdat[3]);
delay1(2000);
*/
}
}
unsigned char rx()
{
while(RI==0);
RI=0;
return SBUF;
}
void lcd_init()
{
cmd(0x38); //2 lines and 5x7 matrix
cmd(0x0e); //Display ON, cursor blinking
cmd(0x01); //Clear display screen
cmd(0x06); //Increment cursor (shift cursor to right)
cmd(0x0c); //Display ON, cursor OFF
cmd(0x80); //Force cursor to beginning of first line
}
void cmd(unsigned char a)
{
lcd_data=a;
rs=0; //Command register
rw=0; //Write operation
en=1; //Enable Pulse
lcd_delay();
en=0;
}
void dat(unsigned char b)
{
lcd_data=b;
rs=1; //Data register
rw=0; //Write operation
en=1; //Enable pulse
lcd_delay();
en=0;
}
void show(unsigned char *s) //Display string
{
while(*s)
{
dat(*s++);
}
}
void delay1(unsigned int time)
{
unsigned int i;
unsigned int j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
/* DELAY CALCULATIONS
f=11.0592 MHz
The timer works with a clock frequency of 1/12 of the XTAL frequency.
f/12 = 11.0592 MHz / 12 = 921.6 kHz
T =1/921.6kHz = 1.085us. This is the one machine cycle time.
1000us = 1ms
so that 1.085us X 1275 = 1.383 ms (appx 1ms delay)
*/
void lcd_delay()
{
unsigned int lcd_delay;
for(lcd_delay=0; lcd_delay<=6000; lcd_delay++); //Delay of 6ms
}