1 |
//***************************************************************************** |
1 |
//***************************************************************************** |
2 |
// File Name : gpstest.c |
2 |
// File Name : gpstest.c |
3 |
// |
3 |
// |
4 |
// Title : example usage of gps processing library functions |
4 |
// Title : example usage of gps processing library functions |
5 |
// Revision : 1.0 |
5 |
// Revision : 1.0 |
6 |
// Notes : |
6 |
// Notes : |
7 |
// Target MCU : Atmel AVR series |
7 |
// Target MCU : Atmel AVR series |
8 |
// Editor Tabs : 4 |
8 |
// Editor Tabs : 4 |
9 |
// |
9 |
// |
10 |
// Revision History: |
10 |
// Revision History: |
11 |
// When Who Description of change |
11 |
// When Who Description of change |
12 |
// ----------- ----------- ----------------------- |
12 |
// ----------- ----------- ----------------------- |
13 |
// 10-Sep-2002 pstang Created the program |
13 |
// 10-Sep-2002 pstang Created the program |
14 |
//***************************************************************************** |
14 |
//***************************************************************************** |
15 |
|
15 |
|
16 |
//----- Include Files --------------------------------------------------------- |
16 |
//----- Include Files --------------------------------------------------------- |
17 |
#include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
17 |
#include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
18 |
#include <avr/interrupt.h> // include interrupt support |
18 |
#include <avr/interrupt.h> // include interrupt support |
19 |
//#include <math.h> |
19 |
//#include <math.h> |
20 |
#include <stdlib.h> |
20 |
#include <stdlib.h> |
21 |
#include <stdio.h> |
21 |
#include <stdio.h> |
22 |
|
22 |
|
23 |
#include "global.h" // include our global settings |
23 |
#include "global.h" // include our global settings |
24 |
#include "uart2.h" // include dual-uart function library |
24 |
#include "uart2.h" // include dual-uart function library |
25 |
#include "rprintf.h" // include printf function library |
25 |
#include "rprintf.h" // include printf function library |
26 |
#include "timer.h" // include timer function library (timing, PWM, etc) |
26 |
#include "timer.h" // include timer function library (timing, PWM, etc) |
27 |
#include "gps.h" // include gps data support |
27 |
#include "gps.h" // include gps data support |
28 |
//#include "tsip.h" // include TSIP gps packet handling |
28 |
//#include "tsip.h" // include TSIP gps packet handling |
29 |
#include "nmea.h" // include NMEA gps packet handling |
29 |
#include "nmea.h" // include NMEA gps packet handling |
30 |
#include "vt100.h" // include VT100 terminal commands |
30 |
#include "vt100.h" // include VT100 terminal commands |
31 |
//#include "utm.h" // Lat Lon to UTM conversion |
31 |
//#include "utm.h" // Lat Lon to UTM conversion |
32 |
|
32 |
|
33 |
#include <util/delay.h> |
33 |
#include <util/delay.h> |
34 |
|
34 |
|
35 |
// LCD Library |
35 |
// LCD Library |
36 |
#include "lcd_hd44780.h" |
36 |
#include "lcd_hd44780.h" |
37 |
|
37 |
|
38 |
static int lcd_putc_stream(char c, FILE *unused) |
38 |
static int lcd_putc_stream(char c, FILE *unused) |
39 |
{ |
39 |
{ |
40 |
return lcd_putc(c); |
40 |
return lcd_putc(c); |
41 |
} |
41 |
} |
42 |
|
42 |
|
43 |
// Define Output Stream to LCD |
43 |
// Define Output Stream to LCD |
44 |
static FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putc_stream, NULL, _FDEV_SETUP_WRITE); |
44 |
static FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putc_stream, NULL, _FDEV_SETUP_WRITE); |
45 |
|
45 |
|
46 |
// uartRxOverflow is a global variable defined in uart.c/uart2.c |
46 |
// uartRxOverflow is a global variable defined in uart.c/uart2.c |
47 |
// we define it here as <extern> here so that we can use its value |
47 |
// we define it here as <extern> here so that we can use its value |
48 |
// in code contained in this file |
48 |
// in code contained in this file |
49 |
extern unsigned short uartRxOverflow[2]; |
49 |
extern unsigned short uartRxOverflow[2]; |
50 |
|
50 |
|
51 |
void gpsTsipTest(void); |
51 |
void gpsTsipTest(void); |
52 |
void gpsNmeaTest(void); |
52 |
void gpsNmeaTest(void); |
53 |
|
53 |
|
54 |
|
54 |
|
55 |
//----- Begin Code ------------------------------------------------------------ |
55 |
//----- Begin Code ------------------------------------------------------------ |
56 |
int main(void) |
56 |
int main(void) |
57 |
{ |
57 |
{ |
58 |
sbi(DDRC, 0); // sets PC0 to be an output |
58 |
sbi(DDRC, 0); // sets PC0 to be an output |
59 |
cbi(PORTC, 0); // sets PC0 to output a HIGH |
59 |
cbi(PORTC, 0); // sets PC0 to output a HIGH |
60 |
_delay_ms(100); |
60 |
_delay_ms(100); |
61 |
sbi(PORTC, 0); // sets PC0 to output a LOW |
61 |
sbi(PORTC, 0); // sets PC0 to output a LOW |
62 |
_delay_ms(100); |
62 |
_delay_ms(100); |
63 |
cbi(PORTC, 0); // sets PC0 to output a HIGH |
63 |
cbi(PORTC, 0); // sets PC0 to output a HIGH |
64 |
_delay_ms(100); |
64 |
_delay_ms(100); |
65 |
sbi(PORTC, 0); // sets PC0 to output a LOW |
65 |
sbi(PORTC, 0); // sets PC0 to output a LOW |
66 |
_delay_ms(100); |
66 |
_delay_ms(100); |
67 |
// initialize our libraries |
67 |
// initialize our libraries |
68 |
// initialize the UART (serial port) |
68 |
// initialize the UART (serial port) |
69 |
// uartInit(); |
69 |
// uartInit(); |
70 |
uart1Init(); |
70 |
uart1Init(); |
71 |
|
71 |
|
72 |
sbi(DDRC, 1); // sets PC0 to be an output |
72 |
sbi(DDRC, 1); // sets PC0 to be an output |
73 |
cbi(PORTC, 1); // sets PC0 to output a HIGH |
73 |
cbi(PORTC, 1); // sets PC0 to output a HIGH |
74 |
_delay_ms(100); |
74 |
_delay_ms(100); |
75 |
sbi(PORTC, 1); // sets PC0 to output a LOW |
75 |
sbi(PORTC, 1); // sets PC0 to output a LOW |
76 |
_delay_ms(100); |
76 |
_delay_ms(100); |
77 |
cbi(PORTC, 1); // sets PC0 to output a HIGH |
77 |
cbi(PORTC, 1); // sets PC0 to output a HIGH |
78 |
_delay_ms(100); |
78 |
_delay_ms(100); |
79 |
sbi(PORTC, 1); // sets PC0 to output a LOW |
79 |
sbi(PORTC, 1); // sets PC0 to output a LOW |
80 |
_delay_ms(100); |
80 |
_delay_ms(100); |
81 |
|
81 |
|
82 |
// set the baud rate of UART 0 for our debug/reporting output |
82 |
// set the baud rate of UART 0 for our debug/reporting output |
83 |
// uartSetBaudRate(0,9600); |
83 |
// uartSetBaudRate(0,9600); |
84 |
// set uart0SendByte as the output for all rprintf statements |
84 |
// set uart0SendByte as the output for all rprintf statements |
85 |
// rprintfInit(uart0SendByte); |
85 |
// rprintfInit(uart0SendByte); |
86 |
|
86 |
|
87 |
// initialize the timer system |
87 |
// initialize the timer system |
88 |
timerInit(); |
88 |
timerInit(); |
89 |
// initialize vt100 library |
89 |
// initialize vt100 library |
90 |
// vt100Init(); |
90 |
// vt100Init(); |
91 |
|
91 |
|
92 |
// print a little intro message so we know things are working |
92 |
// print a little intro message so we know things are working |
93 |
// vt100ClearScreen(); |
93 |
// vt100ClearScreen(); |
94 |
// rprintf("\r\nWelcome to GPS Test!\r\n"); |
94 |
// rprintf("\r\nWelcome to GPS Test!\r\n"); |
95 |
// timerPause(1000); |
95 |
// timerPause(1000); |
96 |
|
96 |
|
97 |
lcd_init(); // Init LCD (interface and display module) |
97 |
lcd_init(); // Init LCD (interface and display module) |
98 |
rprintfInit(lcd_putc); |
98 |
rprintfInit(lcd_putc); |
99 |
rprintfProgStrM("Ahoj..."); rprintfCRLF(); |
99 |
rprintfProgStrM("Ahoj...xxxxx"); rprintfCRLF(); |
100 |
_delay_ms(500); |
100 |
_delay_ms(500); |
101 |
lcd_clear(); |
101 |
lcd_clear(); |
102 |
|
102 |
|
103 |
// run example gps processing loop |
103 |
// run example gps processing loop |
104 |
// (pick the one appropriate for your GPS packet format) |
104 |
// (pick the one appropriate for your GPS packet format) |
105 |
gpsNmeaTest(); |
105 |
gpsNmeaTest(); |
106 |
|
106 |
|
107 |
return 0; |
107 |
return 0; |
108 |
} |
108 |
} |
109 |
|
109 |
|
110 |
|
110 |
|
111 |
void gpsNmeaTest(void) |
111 |
void gpsNmeaTest(void) |
112 |
{ |
112 |
{ |
113 |
// set the baud rate of UART 1 for NMEA |
113 |
// set the baud rate of UART 1 for NMEA |
114 |
uartSetBaudRate(1,4800); |
114 |
uartSetBaudRate(1,4800); |
115 |
|
115 |
|
116 |
// clear screen |
116 |
// clear screen |
117 |
// vt100ClearScreen(); |
117 |
// vt100ClearScreen(); |
118 |
// initialize gps library |
118 |
// initialize gps library |
119 |
gpsInit(); |
119 |
gpsInit(); |
120 |
// initialize gps packet decoder |
120 |
// initialize gps packet decoder |
121 |
nmeaInit(); |
121 |
nmeaInit(); |
122 |
|
122 |
|
123 |
DDRD = 0b10100000; // sets PD7 O, PD6 I, PD5 O |
123 |
DDRD = 0b10100000; // sets PD7 O, PD6 I, PD5 O |
124 |
cbi(PORTD, 7); // sets PD7 to output a LOW |
124 |
cbi(PORTD, 7); // sets PD7 to output a LOW |
125 |
sbi(PORTD, 5); // sets PD5 to output a HIGH |
125 |
sbi(PORTD, 5); // sets PD5 to output a HIGH |
126 |
|
126 |
|
127 |
// begin gps packet processing loop |
127 |
// begin gps packet processing loop |
128 |
while(1) |
128 |
while(1) |
129 |
{ |
129 |
{ |
130 |
// process received gps packets until receive buffer is exhausted |
130 |
// process received gps packets until receive buffer is exhausted |
131 |
while( nmeaProcess(uartGetRxBuffer(1))== NMEA_NODATA); |
131 |
while( nmeaProcess(uartGetRxBuffer(1))== NMEA_NODATA); |
132 |
if((inb(PIND) & 0b01000000)==0) |
132 |
if((inb(PIND) & 0b01000000)==0) |
133 |
gpsInfoPrintLCD(); |
133 |
gpsInfoPrintLCD(); |
134 |
else |
134 |
else |
135 |
gpsInfoPrintLCD2(); |
135 |
gpsInfoPrintLCD2(); |
136 |
|
136 |
|
- |
|
137 |
/* |
137 |
sbi(DDRC, 0); // sets PC0 to be an output |
138 |
sbi(DDRC, 0); // sets PC0 to be an output |
138 |
cbi(PORTC, 0); // sets PC0 to output a LOW |
139 |
cbi(PORTC, 0); // sets PC0 to output a LOW |
139 |
_delay_ms(5); |
140 |
_delay_ms(5); |
140 |
sbi(PORTC, 0); // sets PC0 to output a HIGH |
141 |
sbi(PORTC, 0); // sets PC0 to output a HIGH |
- |
|
142 |
*/ |
141 |
} |
143 |
} |
142 |
} |
144 |
} |
143 |
|
145 |
|