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
| /*******************************************************************************
* Program for 'GPS Position Tracker for Car accident' *
* Compiler: MicroC Pro for PIC v.5.6.1 *
* Program Written by Engr. Mithun K. Das *
* e-mail: [email]mithun060@gmail.com[/email]; 01722448270 *
* MCU: PIC16F690; X-Tal:8MHz(internal) *
* 16-Dec,2014 *
*******************************************************************************/
/*
$GPGGA,025526.000,0653.409140,N,07954.150015,E,1,7 ,1.08,22.013,M,-96.608,M,,*4D
$GPGLL,0653.409140,N,07954.150015,E,025526.000,A,A *58
$GPGSA,A,3,21,29,18,24,22,25,15,,,,,,1.98,1.08,1.6 7*0F
$GPGSV,4,1,14,21,58,020,36,14,56,246,25,29,38,173, 36,18,32,354,36*7E
$GPGSV,4,2,14,24,30,071,49,22,25,317,34,06,19,304, 20,25,11,157,33*7E
$GPGSV,4,3,14,15,06,035,32,03,04,310,,31,03,205,,3 0,00,240,*78
$GPGSV,4,4,14,42,,,39,50,,,39*7F
$GPRMC,025526.000,A,0653.409140,N,07954.150015,E,0 .000,115.0,260313,,,A*6F
$GPVTG,115.0,T,,M,0.000,N,0.000,K,A*08
$GPZDA,025526.000,26,03,2013,,*57
*/
unsigned char text[64];
char *string;
int i = 0, latitude, longitude;
unsigned short ready;
short checkGPS=0;
void UART_Write_CText(const char *cptr)
{
char chr;
for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);
}
void GPS_Int(void);
void SMS_Int(void);
void interrupt()
{
if(INTF_bit)
{
checkGPS = 1;
INTF_bit = 0;//clear flag
}
if (RCIF_bit == 1)
{ // If interrupt is generated by RCIF
text[i] = UART1_Read(); // Read data and store it to txrt string
i++; // Increment string index
if (i >= 64)
{ // If index = 768,
i = 0; // set it to zero
ready = 1; // Ready for parsing GPS data
}
RCIF_bit = 0; // Set RCIF to 0
}
}
void main()
{
ANSEL = 0x00;
ANSELH = 0x00;//all digital
ADCON0 = 0x00;
ADCON1 = 0x07;//all digital
TRISA2_bit = 1;//set as input
UART1_Init(9600);//initialize UART at br 9600 bps
Delay_ms(15000);// leave some time for UART
RCIE_bit = 1; // Enable USART Receiver interrupt
GIE_bit = 1; // Enable Global interrupt
PEIE_bit = 1; // Enable Peripheral interrupt
RCIF_bit = 0;//clear flag
INTE_bit = 1;//enbalbe INT
INTEDG_bit = 0;//falling edge
INTF_bit = 0;// clear flag
UART_Write_CText("ATE0\r");//Eco OFF
UART1_Write((char)13);
UART1_Write((char)10);
SMS_Int(void);
UART_Write_CText("GPS is ready to get data. Press the key to check GPS...");// ask for GPS
Delay_ms(1000);
UART1_Write((char)26);//send Ctrl+Z
ready = 0;
while(1)
{
//OERR_bit = 0;// clear Overrun Error bit
//FERR_bit = 0;//clear Farming Error bit
// Note: If I unmask these two Error bits, result become funny characters. So it is kept masked.
if(checkGPS==1)
{
GPS_Int(void);
Delay_ms(3000);
RCIE_bit = 1; // Enable USART Receiver interrupt
RCIF_bit = 0; // Set RCIF to 0
i = 0;
ready = 0;
UART_Write_CText("AT+CGPSINF=0\r");// ask for GPS
Delay_ms(3000);
if(ready == 1)
{ // If the data in text array is ready do:
ready = 0;
RCIE_bit = 0; // Disable USART Receiver interrupt
SMS_Int(void);
UART_Write_CText("GPS response:");
for(i=0;i<64;i++)
{
UART1_Write(text[i]);//Write each character one by one
Delay_ms(10);
}
UART1_Write_Text("\r");// leave an enter
UART_Write_CText("Note: Press the button again if you wish to take another data now.");// ask for GPS
Delay_ms(1000);
UART1_Write((char)26);//send Ctrl+Z
checkGPS = 0;
}
}
}//while(1)
}//void main
void GPS_Int(void)
{
UART_Write_CText("AT+CGPSPWR=1\r");//send AT+CGPSPWR=1 and Enter
Delay_ms(500);
UART_Write_CText("AT+CGPSRST=0\r");//select GPS mode, 1 = Autonomous, 0 = Cold
UART_Write_CText("AT+CGPSOUT=0\r");//Disable nema data format
Delay_ms(3000);//leave 3sec to GPS setup
}
void SMS_Int(void)
{
UART_Write_CText("AT+cmgf=1\r");
Delay_ms(500);
UART_Write_CText("AT+cmgs=");
UART1_Write((char)'"');
UART_Write_CText("01722448270");
UART1_Write((char)'"');
UART1_Write((char)13);
UART1_Write((char)10);
Delay_ms(500);
}
//end of the program |