Rev 838 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 838 | Rev 839 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | //############################################################################ |
16 | //############################################################################ |
17 | //Initzialisieren der I2C (TWI) Schnittstelle |
17 | //Initzialisieren der I2C (TWI) Schnittstelle |
18 | void i2c_init(void) |
18 | void i2c_init(void) |
19 | //############################################################################ |
19 | //############################################################################ |
20 | { |
20 | { |
21 | TWSR = 0; |
21 | TWSR = 0; |
22 | TWBR = ((SYSCLK/SCL_CLOCK)-16)/2; |
22 | TWBR = ((SYSCLK/SCL_CLOCK)-16)/2; |
23 | } |
23 | } |
Line 24... | Line 24... | ||
24 | 24 | ||
25 | //############################################################################ |
25 | //############################################################################ |
26 | //Start I2C |
26 | //Start I2C |
Line 40... | Line 40... | ||
40 | } |
40 | } |
Line 41... | Line 41... | ||
41 | 41 | ||
42 | void i2c_reset(void) |
42 | void i2c_reset(void) |
43 | //############################################################################ |
43 | //############################################################################ |
44 | { |
44 | { |
45 | i2c_stop(); |
45 | i2c_stop(); |
46 | twi_state = 0; |
46 | twi_state = 0; |
47 | motor = TWDR; |
47 | motor = TWDR; |
48 | motor = 0; |
48 | motor = 0; |
49 | TWCR = 0x80; |
49 | TWCR = 0x80; |
50 | TWAMR = 0; |
50 | TWAMR = 0; |
51 | TWAR = 0; |
51 | TWAR = 0; |
52 | TWDR = 0; |
52 | TWDR = 0; |
53 | TWSR = 0; |
53 | TWSR = 0; |
54 | TWBR = 0; |
54 | TWBR = 0; |
55 | i2c_init(); |
55 | i2c_init(); |
56 | i2c_start(); |
56 | i2c_start(); |
57 | i2c_write_byte(0); |
57 | i2c_write_byte(0); |
Line 58... | Line 58... | ||
58 | } |
58 | } |
59 | 59 | ||
60 | //############################################################################ |
60 | //############################################################################ |
Line 77... | Line 77... | ||
77 | #if 0 |
77 | #if 0 |
78 | int motorwert = 0; |
78 | int motorwert = 0; |
79 | int scale_p = (int) (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 4.F) / 6; |
79 | int scale_p = (int) (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 4.F) / 6; |
80 | int scale_d = (int) (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 4.F) / 6; |
80 | int scale_d = (int) (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 4.F) / 6; |
81 | #endif |
81 | #endif |
82 | 82 | ||
83 | switch (twi_state++) |
83 | switch (twi_state++) |
84 | { |
84 | { |
85 | case 0: |
85 | case 0: |
86 | i2c_write_byte(0x52+(motor*2)); |
86 | i2c_write_byte(0x52+(motor*2)); |
87 | break; |
87 | break; |
88 | case 1: |
88 | case 1: |
89 | switch(motor++) |
89 | switch(motor++) |
90 | { |
90 | { |
91 | case 0: |
91 | case 0: |
92 | #if 0 |
92 | #if 0 |
93 | pd_ergebnis = (int) (scale_p* DiffNick + scale_d * (AdWertNick - AdNeutralNick - Roll_Y_Off)) / 10; |
93 | pd_ergebnis = (int) (scale_p* DiffNick + scale_d * (AdWertNick - AdNeutralNick - Roll_Y_Off)) / 10; |
94 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
94 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
95 | { |
95 | { |
96 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
96 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
97 | } |
97 | } |
98 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
98 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
99 | { |
99 | { |
100 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
100 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
101 | } |
101 | } |
102 | /* M o t o r V o r n */ |
102 | /* M o t o r V o r n */ |
103 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; |
103 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; |
104 | if ((motorwert < 0)) |
104 | if ((motorwert < 0)) |
105 | { |
105 | { |
106 | motorwert = 0; |
106 | motorwert = 0; |
107 | } |
107 | } |
108 | else if(motorwert > MAX_GAS) |
108 | else if(motorwert > MAX_GAS) |
109 | { |
109 | { |
110 | motorwert = MAX_GAS; |
110 | motorwert = MAX_GAS; |
111 | } |
111 | } |
112 | if (motorwert < MIN_GAS) |
112 | if (motorwert < MIN_GAS) |
113 | { |
113 | { |
114 | motorwert = MIN_GAS; |
114 | motorwert = MIN_GAS; |
115 | } |
115 | } |
116 | Motor_Vorne = motorwert; |
116 | Motor_Vorne = motorwert; |
117 | if(!MotorenEin) |
117 | if(!MotorenEin) |
118 | { |
118 | { |
119 | Motor_Vorne = 0; |
119 | Motor_Vorne = 0; |
120 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
120 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
121 | } |
121 | } |
122 | #endif |
122 | #endif |
123 | i2c_write_byte(Motor_Vorne); |
123 | i2c_write_byte(Motor_Vorne); |
124 | break; |
124 | break; |
125 | case 1: |
125 | case 1: |
126 | #if 0 |
126 | #if 0 |
127 | pd_ergebnis = (scale_p * DiffNick + scale_d * (AdWertNick - AdNeutralNick - Roll_Y_Off)) / 10; |
127 | pd_ergebnis = (scale_p * DiffNick + scale_d * (AdWertNick - AdNeutralNick - Roll_Y_Off)) / 10; |
128 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
128 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
129 | { |
129 | { |
130 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
130 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
131 | } |
131 | } |
132 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
132 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
133 | { |
133 | { |
134 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
134 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
135 | } |
135 | } |
136 | /* M o t o r H e c k */ |
136 | /* M o t o r H e c k */ |
137 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
137 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
138 | if ((motorwert < 0)) |
138 | if ((motorwert < 0)) |
139 | { |
139 | { |
140 | motorwert = 0; |
140 | motorwert = 0; |
141 | } |
141 | } |
142 | else if(motorwert > MAX_GAS) |
142 | else if(motorwert > MAX_GAS) |
143 | { |
143 | { |
144 | motorwert = MAX_GAS; |
144 | motorwert = MAX_GAS; |
145 | } |
145 | } |
146 | if (motorwert < MIN_GAS) |
146 | if (motorwert < MIN_GAS) |
147 | { |
147 | { |
148 | motorwert = MIN_GAS; |
148 | motorwert = MIN_GAS; |
149 | } |
149 | } |
150 | Motor_Hinten = motorwert; |
150 | Motor_Hinten = motorwert; |
151 | 151 | ||
152 | if(!MotorenEin) |
152 | if(!MotorenEin) |
153 | { |
153 | { |
154 | Motor_Hinten = 0; |
154 | Motor_Hinten = 0; |
155 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
155 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
156 | } |
156 | } |
157 | #endif |
157 | #endif |
158 | i2c_write_byte(Motor_Hinten); |
158 | i2c_write_byte(Motor_Hinten); |
159 | break; |
159 | break; |
160 | case 2: |
160 | case 2: |
161 | #if 0 |
161 | #if 0 |
162 | pd_ergebnis = (scale_p * DiffRoll + scale_d * (AdWertRoll - AdNeutralRoll - Roll_X_Off)) / 10; |
162 | pd_ergebnis = (scale_p * DiffRoll + scale_d * (AdWertRoll - AdNeutralRoll - Roll_X_Off)) / 10; |
163 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
163 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
164 | { |
164 | { |
165 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
165 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
166 | } |
166 | } |
167 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
167 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
168 | { |
168 | { |
169 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
169 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
170 | } |
170 | } |
171 | /* M o t o r R e c h t s */ |
171 | /* M o t o r R e c h t s */ |
172 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
172 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
173 | if (motorwert < 0) |
173 | if (motorwert < 0) |
174 | { |
174 | { |
175 | motorwert = 0; |
175 | motorwert = 0; |
176 | } |
176 | } |
177 | else if(motorwert > MAX_GAS) |
177 | else if(motorwert > MAX_GAS) |
178 | { |
178 | { |
179 | motorwert = MAX_GAS; |
179 | motorwert = MAX_GAS; |
180 | } |
180 | } |
181 | if (motorwert < MIN_GAS) |
181 | if (motorwert < MIN_GAS) |
182 | { |
182 | { |
183 | motorwert = MIN_GAS; |
183 | motorwert = MIN_GAS; |
184 | } |
184 | } |
185 | Motor_Rechts = motorwert; |
185 | Motor_Rechts = motorwert; |
186 | if(!MotorenEin) |
186 | if(!MotorenEin) |
187 | { |
187 | { |
188 | Motor_Rechts = 0; |
188 | Motor_Rechts = 0; |
189 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
189 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
190 | } |
190 | } |
191 | #endif |
191 | #endif |
192 | i2c_write_byte(Motor_Rechts); |
192 | i2c_write_byte(Motor_Rechts); |
193 | break; |
193 | break; |
194 | case 3: |
194 | case 3: |
195 | #if 0 |
195 | #if 0 |
196 | pd_ergebnis = (scale_p* DiffRoll + scale_d * (AdWertRoll - AdNeutralRoll - Roll_X_Off)) / 10; |
196 | pd_ergebnis = (scale_p* DiffRoll + scale_d * (AdWertRoll - AdNeutralRoll - Roll_X_Off)) / 10; |
197 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
197 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
198 | { |
198 | { |
199 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
199 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
200 | } |
200 | } |
201 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
201 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
202 | { |
202 | { |
203 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
203 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
204 | } |
204 | } |
205 | /* M o t o r L i n k s */ |
205 | /* M o t o r L i n k s */ |
206 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
206 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
207 | if (motorwert < 0) |
207 | if (motorwert < 0) |
208 | { |
208 | { |
209 | motorwert = 0; |
209 | motorwert = 0; |
210 | } |
210 | } |
211 | else if(motorwert > MAX_GAS) |
211 | else if(motorwert > MAX_GAS) |
212 | { |
212 | { |
213 | motorwert = MAX_GAS; |
213 | motorwert = MAX_GAS; |
214 | } |
214 | } |
215 | if (motorwert < MIN_GAS) |
215 | if (motorwert < MIN_GAS) |
216 | { |
216 | { |
217 | motorwert = MIN_GAS; |
217 | motorwert = MIN_GAS; |
218 | } |
218 | } |
219 | Motor_Links = motorwert; |
219 | Motor_Links = motorwert; |
220 | if(!MotorenEin) |
220 | if(!MotorenEin) |
221 | { |
221 | { |
222 | Motor_Links = 0; |
222 | Motor_Links = 0; |
223 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
223 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
224 | } |
224 | } |
225 | #endif |
225 | #endif |
226 | i2c_write_byte(Motor_Links); |
226 | i2c_write_byte(Motor_Links); |
227 | break; |
227 | break; |
228 | } |
228 | } |
229 | break; |
229 | break; |
230 | case 2: |
230 | case 2: |
231 | i2c_stop(); |
231 | i2c_stop(); |
232 | if (motor<4) twi_state = 0; |
232 | if (motor<4) twi_state = 0; |
233 | else motor = 0; |
233 | else motor = 0; |
234 | i2c_start(); |
234 | i2c_start(); |
235 | break; |
235 | break; |
236 | 236 | ||
237 | //Liest Daten von Motor |
237 | //Liest Daten von Motor |
238 | case 3: |
238 | case 3: |
239 | i2c_write_byte(0x53+(motorread*2)); |
239 | i2c_write_byte(0x53+(motorread*2)); |
240 | break; |
240 | break; |
241 | case 4: |
241 | case 4: |
242 | switch(motorread) |
242 | switch(motorread) |
243 | { |
243 | { |
244 | case 0: |
244 | case 0: |
245 | i2c_write_byte(Motor_Vorne); |
245 | i2c_write_byte(Motor_Vorne); |
246 | break; |
246 | break; |
247 | case 1: |
247 | case 1: |
248 | i2c_write_byte(Motor_Hinten); |
248 | i2c_write_byte(Motor_Hinten); |
249 | break; |
249 | break; |
250 | case 2: |
250 | case 2: |
251 | i2c_write_byte(Motor_Rechts); |
251 | i2c_write_byte(Motor_Rechts); |
252 | break; |
252 | break; |
253 | case 3: |
253 | case 3: |
254 | i2c_write_byte(Motor_Links); |
254 | i2c_write_byte(Motor_Links); |
255 | break; |
255 | break; |
256 | } |
256 | } |
257 | break; |
257 | break; |
258 | case 5: //1 Byte vom Motor lesen |
258 | case 5: //1 Byte vom Motor lesen |
259 | motor_rx[motorread] = TWDR; |
259 | motor_rx[motorread] = TWDR; |
260 | 260 | ||
261 | case 6: |
261 | case 6: |
262 | switch(motorread) |
262 | switch(motorread) |
263 | { |
263 | { |
264 | case 0: |
264 | case 0: |
265 | i2c_write_byte(Motor_Vorne); |
265 | i2c_write_byte(Motor_Vorne); |
266 | break; |
266 | break; |
267 | case 1: |
267 | case 1: |
268 | i2c_write_byte(Motor_Hinten); |
268 | i2c_write_byte(Motor_Hinten); |
269 | break; |
269 | break; |
270 | case 2: |
270 | case 2: |
271 | i2c_write_byte(Motor_Rechts); |
271 | i2c_write_byte(Motor_Rechts); |
272 | break; |
272 | break; |
273 | case 3: |
273 | case 3: |
274 | i2c_write_byte(Motor_Links); |
274 | i2c_write_byte(Motor_Links); |
275 | break; |
275 | break; |
276 | } |
276 | } |
277 | break; |
277 | break; |
278 | case 7: //2 Byte vom Motor lesen |
278 | case 7: //2 Byte vom Motor lesen |
279 | motor_rx[motorread+4] = TWDR; |
279 | motor_rx[motorread+4] = TWDR; |
280 | motorread++; |
280 | motorread++; |
281 | if (motorread>3) motorread=0; |
281 | if (motorread>3) motorread=0; |
282 | i2c_stop(); |
282 | i2c_stop(); |
283 | I2CTimeout = 10; |
283 | I2CTimeout = 10; |
284 | twi_state = 0; |
284 | twi_state = 0; |
285 | } |
285 | } |
286 | #if 0 |
286 | #if 0 |
287 | break; |
287 | break; |
288 | TriggerMagneticHeading++; |
288 | TriggerMagneticHeading++; |
289 | TriggerMagneticHeading %= 50; |
289 | TriggerMagneticHeading %= 50; |
290 | TriggerSonicReading++; |
290 | TriggerSonicReading++; |
291 | TriggerSonicReading %= 200; |
291 | TriggerSonicReading %= 200; |
292 | 292 | ||
293 | if (TriggerMagneticHeading == 1) |
293 | if (TriggerMagneticHeading == 1) |
294 | { |
294 | { |
295 | // Get Magnetic Heading |
295 | // Get Magnetic Heading |
296 | i2c_start(); |
296 | i2c_start(); |
297 | twi_state = 8; |
297 | twi_state = 8; |
298 | break; |
298 | break; |
299 | } |
299 | } |
300 | 300 | ||
301 | if (TriggerSonicReading == 1) |
301 | if (TriggerSonicReading == 1) |
302 | { |
302 | { |
303 | // Get Ultrasonic Reading |
303 | // Get Ultrasonic Reading |
304 | i2c_start(); |
304 | i2c_start(); |
305 | twi_state = 20; |
305 | twi_state = 20; |
306 | break; |
306 | break; |
307 | } |
307 | } |
308 | else if (TriggerSonicReading == 190) |
308 | else if (TriggerSonicReading == 190) |
309 | { |
309 | { |
310 | // Get Ultrasonic Reading |
310 | // Get Ultrasonic Reading |
311 | i2c_start(); |
311 | i2c_start(); |
312 | twi_state = 30; |
312 | twi_state = 30; |
313 | break; |
313 | break; |
314 | } |
314 | } |
315 | else |
315 | else |
316 | { |
- | |
317 | I2CTimeout = 10; |
- | |
318 | twi_state = 0; |
- | |
319 | break; |
- | |
320 | } |
- | |
321 | - | ||
322 | case 8: |
- | |
323 | i2c_write_byte(0xC0); |
- | |
324 | break; |
316 | { |
325 | case 9: |
- | |
326 | i2c_write_byte(0x02); |
317 | I2CTimeout = 10; |
327 | break; |
- | |
328 | case 10: |
- | |
329 | i2c_start(); |
318 | twi_state = 0; |
330 | break; |
- | |
331 | case 11: |
- | |
332 | i2c_write_byte(0xC1); |
- | |
333 | break; |
- | |
334 | case 12: |
- | |
335 | i2c_write_byte(MagneticHeading); |
- | |
336 | break; |
- | |
337 | case 13: |
- | |
338 | MagneticHeading = (0x0F & TWDR) << 8; |
- | |
339 | i2c_stop(); |
- | |
340 | i2c_start(); |
- | |
341 | break; |
- | |
342 | case 14: |
- | |
343 | i2c_write_byte(0xC0); |
- | |
344 | break; |
319 | break; |
- | 320 | } |
|
- | 321 | ||
- | 322 | case 8: |
|
- | 323 | i2c_write_byte(0xC0); |
|
- | 324 | break; |
|
- | 325 | case 9: |
|
- | 326 | i2c_write_byte(0x02); |
|
- | 327 | break; |
|
- | 328 | case 10: |
|
- | 329 | i2c_start(); |
|
- | 330 | break; |
|
- | 331 | case 11: |
|
- | 332 | i2c_write_byte(0xC1); |
|
- | 333 | break; |
|
- | 334 | case 12: |
|
- | 335 | i2c_write_byte(MagneticHeading); |
|
- | 336 | break; |
|
- | 337 | case 13: |
|
- | 338 | MagneticHeading = (0x0F & TWDR) << 8; |
|
- | 339 | i2c_stop(); |
|
- | 340 | i2c_start(); |
|
- | 341 | break; |
|
- | 342 | case 14: |
|
- | 343 | i2c_write_byte(0xC0); |
|
- | 344 | break; |
|
345 | case 15: |
345 | case 15: |
346 | i2c_write_byte(0x03); |
346 | i2c_write_byte(0x03); |
347 | break; |
347 | break; |
348 | case 16: |
348 | case 16: |
349 | i2c_start(); |
349 | i2c_start(); |
350 | break; |
350 | break; |
351 | case 17: |
351 | case 17: |
352 | i2c_write_byte(0xC1); |
352 | i2c_write_byte(0xC1); |
353 | break; |
353 | break; |
354 | case 18: |
354 | case 18: |
355 | i2c_write_byte(MagneticHeading); |
355 | i2c_write_byte(MagneticHeading); |
356 | break; |
356 | break; |
357 | case 19: |
357 | case 19: |
358 | MagneticHeading += TWDR; |
358 | MagneticHeading += TWDR; |
359 | i2c_stop(); |
359 | i2c_stop(); |
360 | I2CTimeout = 22; |
360 | I2CTimeout = 22; |
361 | twi_state = 0; |
361 | twi_state = 0; |
362 | break; |
362 | break; |
363 | 363 | ||
364 | /* Trigger Ultrasonic Ping */ |
364 | /* Trigger Ultrasonic Ping */ |
365 | case 20: /* Ping */ |
365 | case 20: /* Ping */ |
366 | i2c_write_byte(0xE0); /* Send I2C Adress */ |
366 | i2c_write_byte(0xE0); /* Send I2C Adress */ |
367 | break; |
367 | break; |
368 | case 21: |
368 | case 21: |
369 | i2c_write_byte(0x00); /* Send I2C Register */ |
369 | i2c_write_byte(0x00); /* Send I2C Register */ |
370 | break; |
370 | break; |
371 | case 22: |
371 | case 22: |
372 | i2c_write_byte(82); /* Send I2C Value */ |
372 | i2c_write_byte(82); /* Send I2C Value */ |
373 | break; |
373 | break; |
374 | case 24: |
374 | case 24: |
375 | VersionID = TWDR; |
375 | VersionID = TWDR; |
376 | i2c_stop(); |
376 | i2c_stop(); |
377 | I2CTimeout = 22; |
377 | I2CTimeout = 22; |
378 | twi_state = 0; |
378 | twi_state = 0; |
379 | UltrasonicPingCnt++; |
379 | UltrasonicPingCnt++; |
380 | break; |
380 | break; |
381 | case 30: |
381 | case 30: |
382 | i2c_write_byte(0xE0);/* Send I2C Adress */ |
382 | i2c_write_byte(0xE0);/* Send I2C Adress */ |
383 | break; |
383 | break; |
384 | case 31: |
384 | case 31: |
385 | i2c_write_byte(0x02); /* Send I2C Register */ |
385 | i2c_write_byte(0x02); /* Send I2C Register */ |
386 | break; |
386 | break; |
387 | case 32: |
387 | case 32: |
388 | i2c_start(); |
388 | i2c_start(); |
389 | break; |
389 | break; |
390 | case 33: |
390 | case 33: |
391 | i2c_write_byte(0xE1); |
391 | i2c_write_byte(0xE1); |
392 | break; |
392 | break; |
393 | case 34: |
393 | case 34: |
394 | i2c_write_byte(255); |
394 | i2c_write_byte(255); |
395 | break; |
395 | break; |
396 | case 35: |
396 | case 35: |
397 | UltrasonicRange = TWDR << 8;/* Read I2C Value */ |
397 | UltrasonicRange = TWDR << 8;/* Read I2C Value */ |
398 | UltrasonicRangeHigh = TWDR; |
398 | UltrasonicRangeHigh = TWDR; |
399 | i2c_stop(); |
399 | i2c_stop(); |
400 | i2c_start(); |
400 | i2c_start(); |
401 | break; |
401 | break; |
402 | case 36: |
402 | case 36: |
403 | i2c_write_byte(0xE0); |
403 | i2c_write_byte(0xE0); |
404 | break; |
404 | break; |
405 | case 37: |
405 | case 37: |
406 | i2c_write_byte(0x03); |
406 | i2c_write_byte(0x03); |
407 | break; |
407 | break; |
408 | case 38: |
408 | case 38: |
409 | i2c_start(); |
409 | i2c_start(); |
410 | break; |
410 | break; |
411 | case 39: |
411 | case 39: |
412 | i2c_write_byte(0xE1); |
412 | i2c_write_byte(0xE1); |
413 | break; |
413 | break; |
414 | case 40: |
414 | case 40: |
415 | i2c_write_byte(UltrasonicRangeLow); |
415 | i2c_write_byte(UltrasonicRangeLow); |
416 | break; |
416 | break; |
417 | case 41: |
417 | case 41: |
418 | UltrasonicRange += TWDR; |
418 | UltrasonicRange += TWDR; |
419 | UltrasonicRangeLow = TWDR; |
419 | UltrasonicRangeLow = TWDR; |
420 | i2c_stop(); |
420 | i2c_stop(); |
421 | I2CTimeout = 22; |
421 | I2CTimeout = 22; |
422 | twi_state = 0; |
422 | twi_state = 0; |
423 | break; |
423 | break; |
424 | } |
424 | } |
425 | #endif |
425 | #endif |
426 | TWCR |= 0x80; |
426 | TWCR |= 0x80; |
427 | } |
427 | } |