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