Rev 1213 Rev 1221
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 RX PD2 // input 39 #define USB PD5 // input
40 #define RX_DDR DDRD 40 #define USB_DDR DDRD
41 #define RX_PORT PORTD 41 #define USB_PORT PORTD
42 #define RX_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 RX_INIT RX_DDR &= ~(_BV(RX)) 82 #define USB_INIT USB_DDR &= ~(_BV(USB))
83 #define RX_INPUT (RX_PIN & _BV(RX)) 83 #define USB_INPUT (USB_PIN & _BV(USB))
84 #define RX_PULLUP RX_PORT |= _BV(RX) 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   108  
109 #define KEY1 0 109 #define KEY1 0
110 #define KEY2 1 110 #define KEY2 1
111 #define KEY3 3 111 #define KEY3 2
-   112  
-   113 #define KEY1_LONG 1
-   114 #define KEY2_LONG 2
-   115 #define KEY3_LONG 3
-   116 #define KEY1_SHORT 4
-   117 #define KEY2_SHORT 5
-   118 #define KEY3_SHORT 6
112   119  
113 #define ID_OFF 100 120 #define ID_OFF 100
114 #define ID_START 101 121 #define ID_START 101
115 #define ID_SETUP 102 122 #define ID_SETUP 102
116   123  
117 #ifndef TYPEDEF_OK 124 #ifndef TYPEDEF_OK
118 //typedef struct{uint8_t a; uint8_t b}GPS_SEND; 125 //typedef struct{uint8_t a; uint8_t b}GPS_SEND;
119 typedef struct 126 typedef struct
120 { 127 {
121 uint8_t sec; 128 uint8_t sec;
122 uint8_t min; 129 uint8_t min;
123 uint8_t hour; 130 uint8_t hour;
124 }TIME_T; 131 }TIME_T;
125   132  
126 typedef struct 133 typedef struct
127 { 134 {
128 uint8_t day; 135 uint8_t day;
129 uint8_t mon; 136 uint8_t mon;
130 uint8_t year; 137 uint8_t year;
131 }DATE_T; 138 }DATE_T;
132   139  
133 typedef struct 140 typedef struct
134 { 141 {
135 double lat; 142 double lat;
136 double lon; 143 double lon;
137 double alt; 144 double alt;
138 double speed; 145 double speed;
139 double course; 146 double course;
140 int16_t temperature; 147 int16_t temperature;
141 TIME_T time; 148 TIME_T time;
142 DATE_T date; 149 DATE_T date;
143 }POINT_T; 150 }POINT_T;
144   151  
145 typedef struct 152 typedef struct
146 { 153 {
147 uint8_t id; 154 uint8_t id;
148 uint8_t elevation; 155 uint8_t elevation;
149 uint16_t azimut; 156 uint16_t azimut;
150 uint8_t SNR; 157 uint8_t SNR;
151 }SATELITE_DETAIL; 158 }SATELITE_DETAIL;
152   159  
153 typedef struct 160 typedef struct
154 { 161 {
155 //GGA 162 //GGA
156 uint8_t fix_position; 163 uint8_t fix_position;
157 uint8_t satelites_used; 164 uint8_t satelites_used;
158 double altitude; 165 double altitude;
159 double geoid; 166 double geoid;
160 uint16_t age_diff_corr; 167 uint16_t age_diff_corr;
161 uint16_t diff_id; 168 uint16_t diff_id;
162 //GSA 169 //GSA
163 char mode1; 170 char mode1;
164 char mode2; 171 char mode2;
165 uint8_t satelite_id[12]; 172 uint8_t satelite_id[12];
166 double PDOP; 173 double PDOP;
167 double HDOP; 174 double HDOP;
168 double VDOP; 175 double VDOP;
169 //GSV 176 //GSV
170 uint8_t gsv_num_msg; 177 uint8_t gsv_num_msg;
171 uint8_t gsv_msg; 178 uint8_t gsv_msg;
172 uint8_t gsv_satelites_view; 179 uint8_t gsv_satelites_view;
173 SATELITE_DETAIL satelit_detail[12]; 180 SATELITE_DETAIL satelit_detail[12];
174 //RMC 181 //RMC
175 uint8_t second; 182 uint8_t second;
176 uint8_t minute; 183 uint8_t minute;
177 uint8_t hour; 184 uint8_t hour;
178 uint8_t day; 185 uint8_t day;
179 uint8_t month; 186 uint8_t month;
180 uint8_t year; 187 uint8_t year;
181 double latitude; 188 double latitude;
182 double longitude; 189 double longitude;
183 char ns_indicator; 190 char ns_indicator;
184 char we_indicator; 191 char we_indicator;
185 char status; 192 char status;
186 //VTG 193 //VTG
187 double course; 194 double course;
188 double speed; 195 double speed;
189 }DATA_GPS; 196 }DATA_GPS;
190   197  
191 #endif 198 #endif
192   199  
193 #define TYPEDEF_OK 200 #define TYPEDEF_OK