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