Rev 1221 Rev 1361
1 /* mija 2008 1 /* mija 2008
2 demo for LCD NOKIA5110 and MCP9800 and GPS modul 2 demo for LCD NOKIA5110 and MCP9800 and GPS modul
3   3  
4 CPU ATMEGA644P 4 CPU ATMEGA644P
5 fcpu = 1MHz 5 fcpu = 1MHz
6   6  
7 !! define PIN,PORT,DDR for IOpin !! 7 !! define PIN,PORT,DDR for IOpin !!
8 */ 8 */
9   9  
10 #include <stdint.h> 10 #include <stdint.h>
11   11  
12 #define MAX_RX_BUF 150 12 #define MAX_RX_BUF 150
13 #define MAX_NMEA_LOAD 100 13 #define MAX_NMEA_LOAD 100
14   14  
15 // PIN TL1 15 // PIN TL1
16 #define TL1 PB4 // input 16 #define TL1 PB4 // input
17 #define TL1_DDR DDRB 17 #define TL1_DDR DDRB
18 #define TL1_PORT PORTB 18 #define TL1_PORT PORTB
19 #define TL1_PIN PINB 19 #define TL1_PIN PINB
20   20  
21 // PIN TL2 21 // PIN TL2
22 #define TL2 PB2 // input //int2 22 #define TL2 PB2 // input //int2
23 #define TL2_DDR DDRB 23 #define TL2_DDR DDRB
24 #define TL2_PORT PORTB 24 #define TL2_PORT PORTB
25 #define TL2_PIN PINB 25 #define TL2_PIN PINB
26   26  
27 // PIN TL3 27 // PIN TL3
28 #define TL3 PB3 // input 28 #define TL3 PB3 // input
29 #define TL3_DDR DDRB 29 #define TL3_DDR DDRB
30 #define TL3_PORT PORTB 30 #define TL3_PORT PORTB
31 #define TL3_PIN PINB 31 #define TL3_PIN PINB
32   32  
33 // PIN GPS 33 // PIN GPS
34 #define GPS PD4 34 #define GPS PD4
35 #define GPS_DDR DDRD 35 #define GPS_DDR DDRD
36 #define GPS_PORT PORTD 36 #define GPS_PORT PORTD
37   37  
38 // UART SW 38 // UART SW
39 #define USB PD5 // input 39 #define USB PD5 // input
40 #define USB_DDR DDRD 40 #define USB_DDR DDRD
41 #define USB_PORT PORTD 41 #define USB_PORT PORTD
42 #define USB_PIN PIND 42 #define USB_PIN PIND
43   43  
44 // i2C SW 44 // i2C SW
45 #define SDA PC1 45 #define SDA PC1
46 #define SDA_PORT PORTC 46 #define SDA_PORT PORTC
47 #define SDA_DDR DDRC 47 #define SDA_DDR DDRC
48 #define SDA_PIN PINC 48 #define SDA_PIN PINC
49   49  
50 #define SCL PC0 50 #define SCL PC0
51 #define SCL_PORT PORTC 51 #define SCL_PORT PORTC
52 #define SCL_DDR DDRC 52 #define SCL_DDR DDRC
53   53  
54 // LED 54 // LED
55 #define LED PD7 55 #define LED PD7
56 #define LED_PORT PORTD 56 #define LED_PORT PORTD
57 #define LED_DDR DDRD 57 #define LED_DDR DDRD
58   58  
59 // Vref 59 // Vref
60 #define REF PA0 60 #define REF PA0
61 #define REF_PORT PORTA 61 #define REF_PORT PORTA
62 #define REF_DDR DDRA 62 #define REF_DDR DDRA
63   63  
64 // interni 64 // interni
65 #define TL1_INIT TL1_DDR &= ~(_BV(TL1)) 65 #define TL1_INIT TL1_DDR &= ~(_BV(TL1))
66 #define TL1_INPUT (TL1_PIN & _BV(TL1)) 66 #define TL1_INPUT (TL1_PIN & _BV(TL1))
67 #define TL1_PULLUP TL1_PORT |= _BV(TL1) 67 #define TL1_PULLUP TL1_PORT |= _BV(TL1)
68   68  
69 #define TL2_INIT TL2_DDR &= ~(_BV(TL2)) 69 #define TL2_INIT TL2_DDR &= ~(_BV(TL2))
70 #define TL2_INPUT (TL2_PIN & _BV(TL2)) 70 #define TL2_INPUT (TL2_PIN & _BV(TL2))
71 #define TL2_PULLUP TL2_PORT |= _BV(TL2) 71 #define TL2_PULLUP TL2_PORT |= _BV(TL2)
72   72  
73 #define TL3_INIT TL3_DDR &= ~(_BV(TL3)) 73 #define TL3_INIT TL3_DDR &= ~(_BV(TL3))
74 #define TL3_INPUT (TL3_PIN & _BV(TL3)) 74 #define TL3_INPUT (TL3_PIN & _BV(TL3))
75 #define TL3_PULLUP TL3_PORT |= _BV(TL3) 75 #define TL3_PULLUP TL3_PORT |= _BV(TL3)
76   76  
77 #define GPS_OFF GPS_PORT |= _BV(GPS) 77 #define GPS_OFF GPS_PORT |= _BV(GPS)
78 #define GPS_ON GPS_PORT &= (~(_BV(GPS))) 78 #define GPS_ON GPS_PORT &= (~(_BV(GPS)))
79 #define GPS_INIT GPS_DDR |= _BV(GPS) 79 #define GPS_INIT GPS_DDR |= _BV(GPS)
80 #define GPS_INPUT (!(GPS_PORT & _BV(GPS))) 80 #define GPS_INPUT (!(GPS_PORT & _BV(GPS)))
81   81  
82 #define USB_INIT USB_DDR &= ~(_BV(USB)) 82 #define USB_INIT USB_DDR &= ~(_BV(USB))
83 #define USB_INPUT (USB_PIN & _BV(USB)) 83 #define USB_INPUT (USB_PIN & _BV(USB))
84 #define USB_PULLUP USB_PORT |= _BV(USB) 84 #define USB_PULLUP USB_PORT |= _BV(USB)
85   85  
86 #define SCL_INIT SCL_DDR |= _BV(SCL) 86 #define SCL_INIT SCL_DDR |= _BV(SCL)
87 #define SCL_L SCL_PORT &= ~(_BV(SCL)) 87 #define SCL_L SCL_PORT &= ~(_BV(SCL))
88 #define SCL_H SCL_PORT |= _BV(SCL) 88 #define SCL_H SCL_PORT |= _BV(SCL)
89   89  
90 #define SDA_OUT SDA_DDR |= _BV(SDA) 90 #define SDA_OUT SDA_DDR |= _BV(SDA)
91 #define SDA_L SDA_PORT &= ~(_BV(SDA)) 91 #define SDA_L SDA_PORT &= ~(_BV(SDA))
92 #define SDA_H SDA_PORT |= _BV(SDA) 92 #define SDA_H SDA_PORT |= _BV(SDA)
93 #define SDA_IN SDA_DDR &= ~(_BV(SDA)) 93 #define SDA_IN SDA_DDR &= ~(_BV(SDA))
94 #define SDA_INPUT (SDA_PIN & _BV(SDA)) 94 #define SDA_INPUT (SDA_PIN & _BV(SDA))
95 #define SDA_FLOAT SDA_IN;SDA_L 95 #define SDA_FLOAT SDA_IN;SDA_L
96   96  
97 #define LED_ON LED_PORT |= _BV(LED) 97 #define LED_ON LED_PORT |= _BV(LED)
98 #define LED_OFF LED_PORT &= (~(_BV(LED))) 98 #define LED_OFF LED_PORT &= (~(_BV(LED)))
99 #define LED_INIT LED_DDR |= _BV(LED) 99 #define LED_INIT LED_DDR |= _BV(LED)
100 #define LED_INPUT (LED_PORT & _BV(LED)) 100 #define LED_INPUT (LED_PORT & _BV(LED))
101   101  
102 #define REF_ON REF_PORT |= _BV(REF) 102 #define REF_ON REF_PORT |= _BV(REF)
103 #define REF_OFF REF_PORT &= (~(_BV(REF))) 103 #define REF_OFF REF_PORT &= (~(_BV(REF)))
104 #define REF_INIT REF_DDR |= _BV(REF) 104 #define REF_INIT REF_DDR |= _BV(REF)
105   105  
106 #define ADC_ON ADCSRA |= _BV(ADEN) 106 #define ADC_ON ADCSRA |= _BV(ADEN)
107 #define ADC_OFF ADCSRA &= ~(_BV(ADEN)) 107 #define ADC_OFF ADCSRA &= ~(_BV(ADEN))
-   108  
-   109 #define USART_PC_ON UCSR1B = _BV(RXCIE1) | _BV(RXEN1) | _BV(TXEN1)
-   110 #define USART_PC_OFF UCSR1B = 0
108   111  
109 #define KEY1 0 112 #define KEY1 0
110 #define KEY2 1 113 #define KEY2 1
111 #define KEY3 2 114 #define KEY3 2
112   115  
113 #define KEY1_LONG 1 116 #define KEY1_LONG 1
114 #define KEY2_LONG 2 117 #define KEY2_LONG 2
115 #define KEY3_LONG 3 118 #define KEY3_LONG 3
116 #define KEY1_SHORT 4 119 #define KEY1_SHORT 4
117 #define KEY2_SHORT 5 120 #define KEY2_SHORT 5
118 #define KEY3_SHORT 6 121 #define KEY3_SHORT 6
119   122  
120 #define ID_OFF 100 123 #define ID_OFF 100
121 #define ID_START 101 124 #define ID_START 101
122 #define ID_SETUP 102 125 #define ID_SETUP 102
123   126  
124 #ifndef TYPEDEF_OK 127 #ifndef TYPEDEF_OK
125 //typedef struct{uint8_t a; uint8_t b}GPS_SEND; 128 //typedef struct{uint8_t a; uint8_t b}GPS_SEND;
126 typedef struct 129 typedef struct
127 { 130 {
128 uint8_t sec; 131 uint8_t sec;
129 uint8_t min; 132 uint8_t min;
130 uint8_t hour; 133 uint8_t hour;
131 }TIME_T; 134 }TIME_T;
132   135  
133 typedef struct 136 typedef struct
134 { 137 {
135 uint8_t day; 138 uint8_t day;
136 uint8_t mon; 139 uint8_t mon;
137 uint8_t year; 140 uint8_t year;
138 }DATE_T; 141 }DATE_T;
139   142  
140 typedef struct 143 typedef struct
141 { 144 {
142 double lat; 145 double lat;
143 double lon; 146 double lon;
144 double alt; 147 double alt;
145 double speed; 148 double speed;
146 double course; 149 double course;
147 int16_t temperature; 150 int16_t temperature;
148 TIME_T time; 151 TIME_T time;
149 DATE_T date; 152 DATE_T date;
150 }POINT_T; 153 }POINT_T;
151   154  
152 typedef struct 155 typedef struct
153 { 156 {
154 uint8_t id; 157 uint8_t id;
155 uint8_t elevation; 158 uint8_t elevation;
156 uint16_t azimut; 159 uint16_t azimut;
157 uint8_t SNR; 160 uint8_t SNR;
158 }SATELITE_DETAIL; 161 }SATELITE_DETAIL;
159   162  
160 typedef struct 163 typedef struct
161 { 164 {
162 //GGA 165 //GGA
163 uint8_t fix_position; 166 uint8_t fix_position;
164 uint8_t satelites_used; 167 uint8_t satelites_used;
165 double altitude; 168 double altitude;
166 double geoid; 169 double geoid;
167 uint16_t age_diff_corr; 170 uint16_t age_diff_corr;
168 uint16_t diff_id; 171 uint16_t diff_id;
169 //GSA 172 //GSA
170 char mode1; 173 char mode1;
171 char mode2; 174 char mode2;
172 uint8_t satelite_id[12]; 175 uint8_t satelite_id[12];
173 double PDOP; 176 double PDOP;
174 double HDOP; 177 double HDOP;
175 double VDOP; 178 double VDOP;
176 //GSV 179 //GSV
177 uint8_t gsv_num_msg; 180 uint8_t gsv_num_msg;
178 uint8_t gsv_msg; 181 uint8_t gsv_msg;
179 uint8_t gsv_satelites_view; 182 uint8_t gsv_satelites_view;
180 SATELITE_DETAIL satelit_detail[12]; 183 SATELITE_DETAIL satelit_detail[12];
181 //RMC 184 //RMC
182 uint8_t second; 185 uint8_t second;
183 uint8_t minute; 186 uint8_t minute;
184 uint8_t hour; 187 uint8_t hour;
185 uint8_t day; 188 uint8_t day;
186 uint8_t month; 189 uint8_t month;
187 uint8_t year; 190 uint8_t year;
188 double latitude; 191 double latitude;
189 double longitude; 192 double longitude;
190 char ns_indicator; 193 char ns_indicator;
191 char we_indicator; 194 char we_indicator;
192 char status; 195 char status;
193 //VTG 196 //VTG
194 double course; 197 double course;
195 double speed; 198 double speed;
196 }DATA_GPS; 199 }DATA_GPS;
197   200  
198 #endif 201 #endif
199   202  
200 #define TYPEDEF_OK 203 #define TYPEDEF_OK