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