root / trunk / code / projects / autonomous_recharging / archs / homing stop / stop.c @ 80
History | View | Annotate | Download (1.21 KB)
1 | 80 | bneuman | #include<avr/io.h> |
---|---|---|---|
2 | #include "i2c.h" |
||
3 | |||
4 | #define LED1 PB4 //Green |
||
5 | #define LED2 PB5 //Red |
||
6 | |||
7 | int main( void ) |
||
8 | { |
||
9 | DDRB = _BV(PB0) | _BV(PB5) | _BV(PB4); |
||
10 | i2c_init(); |
||
11 | |||
12 | /*tempData[0] = 'C';
|
||
13 | tempData[1] = abs_time>>8;
|
||
14 | tempData[2] = abs_time&0xFF;
|
||
15 | i2c_putpacket(0x01, tempData, 3);*/
|
||
16 | |||
17 | char data[2]; |
||
18 | data[0]=I2C_MSG_DATA;
|
||
19 | |||
20 | while(1) |
||
21 | { |
||
22 | PORTB=_BV(LED2); |
||
23 | while(1) |
||
24 | { |
||
25 | if(PINB & _BV(PB6))
|
||
26 | { |
||
27 | PORTB = _BV(LED1); |
||
28 | //This is a junk byte. For some reason the first packet is always ignored????
|
||
29 | data[1] = 'a'; |
||
30 | i2c_putpacket(0x01, data, 2); |
||
31 | data[1]=I2C_MSG_BATTERY_CHARGING;
|
||
32 | i2c_putpacket(0x01, data, 2); |
||
33 | break;
|
||
34 | } |
||
35 | else
|
||
36 | { |
||
37 | data[1]=I2C_MSG_NO_CONTACT;
|
||
38 | i2c_putpacket(0x01, data, 2); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | for(int i=0;i<5000;i++) |
||
43 | { |
||
44 | delay_ms(1);
|
||
45 | if(! PINB & _BV(PB6))
|
||
46 | { |
||
47 | PORTB = _BV(LED2); |
||
48 | data[1]=I2C_MSG_CONTACT_ERROR;
|
||
49 | i2c_putpacket(0x01, data, 2); |
||
50 | |||
51 | while(! PINB & _BV(PB6));
|
||
52 | break;
|
||
53 | } |
||
54 | |||
55 | } |
||
56 | |||
57 | data[1]=I2C_MSG_BATTERY_FULL;
|
||
58 | i2c_putpacket(0x01, data, 2); |
||
59 | } |
||
60 | |||
61 | } |