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