Revision 703
fixed hanging issues in stop.c, should work now NEEDS TESTING
updated to newer version of i2c.c
stop.c | ||
---|---|---|
2 | 2 |
#include <avr/interrupt.h> |
3 | 3 |
#include "i2c.h" |
4 | 4 |
|
5 |
#define LED1 PB4 //Green
|
|
6 |
#define LED2 PB5 //Red
|
|
5 |
#define LEDG PB4 //Green
|
|
6 |
#define LEDR PB5 //Red
|
|
7 | 7 |
|
8 | 8 |
// for i2c_byte coming from charge board |
9 | 9 |
//I2C Message Codes |
... | ... | |
38 | 38 |
{ |
39 | 39 |
uint8_t count = 0; |
40 | 40 |
|
41 |
PORTB|=_BV(LED2);
|
|
41 |
PORTB|=_BV(LEDR);
|
|
42 | 42 |
while(read_homing()) |
43 | 43 |
{ |
44 | 44 |
delay_ms(1); |
... | ... | |
47 | 47 |
if (count >= 100) |
48 | 48 |
return 1; |
49 | 49 |
} //wait a beacon cycle to make sure we aren't starting the count in the middle of one |
50 |
PORTB&=~_BV(LED2);
|
|
50 |
PORTB &= ~_BV(LEDR);
|
|
51 | 51 |
count = 0; |
52 |
PORTB|=_BV(LED1);
|
|
52 |
PORTB |= _BV(LEDG);
|
|
53 | 53 |
while(!read_homing()) |
54 | 54 |
{ |
55 | 55 |
delay_ms(1); |
... | ... | |
57 | 57 |
if(count==255) |
58 | 58 |
return 2; |
59 | 59 |
} |
60 |
PORTB&=~_BV(LED1);
|
|
60 |
PORTB &= ~_BV(LEDG);
|
|
61 | 61 |
|
62 | 62 |
/*RECH_PUTS("\n\rCount: "); |
63 | 63 |
RECH_PUTI(count); |
... | ... | |
68 | 68 |
|
69 | 69 |
int main( void ) |
70 | 70 |
{ |
71 |
int count;
|
|
71 |
uint8_t count;
|
|
72 | 72 |
|
73 |
DDRB = _BV(PB0) | _BV(PB5) | _BV(PB4); |
|
74 |
i2c_init(); |
|
73 |
|
|
74 |
DDRB |= /*_BV(PB0) |*/ _BV(LEDR) | _BV(LEDG); //what is PB0 for? |
|
75 |
DDRB &= ~_BV(DETECT_12V); |
|
76 |
|
|
77 |
i2c_init(); |
|
78 |
|
|
75 | 79 |
|
76 | 80 |
/*tempData[0] = 'C'; |
77 | 81 |
tempData[1] = abs_time>>8; |
78 | 82 |
tempData[2] = abs_time&0xFF; |
79 | 83 |
i2c_putpacket(0x01, tempData, 3);*/ |
80 | 84 |
|
81 |
char data[2];
|
|
85 |
char data[4];
|
|
82 | 86 |
data[0]=I2C_MSG_DATA; |
87 |
|
|
83 | 88 |
|
84 | 89 |
|
85 | 90 |
while(1) |
86 | 91 |
{ |
87 |
PORTB=_BV(LED2); |
|
92 |
|
|
93 |
PORTB |=_BV(LEDG); |
|
94 |
PORTB |=_BV(LEDR); |
|
95 |
delay_ms(500); |
|
96 |
PORTB &= ~_BV(LEDG); |
|
97 |
PORTB &= ~_BV(LEDR); |
|
98 |
|
|
99 |
|
|
88 | 100 |
while(1) |
89 | 101 |
{ |
90 |
if(PINB & _BV(DETECT_12V)) |
|
102 |
|
|
103 |
if((PINB & _BV(DETECT_12V))) |
|
91 | 104 |
{ |
92 |
PORTB = _BV(LED1); |
|
105 |
PORTB |= _BV(LEDG); |
|
106 |
|
|
93 | 107 |
//This is a junk byte. For some reason the first packet is always ignored???? |
94 | 108 |
data[1] = 'a'; |
95 | 109 |
i2c_putpacket(0x01, data, 2); |
... | ... | |
99 | 113 |
} |
100 | 114 |
else |
101 | 115 |
{ |
116 |
count = 0; |
|
102 | 117 |
data[1]=I2C_MSG_NO_CONTACT; |
103 | 118 |
|
104 | 119 |
get_delay(); //reject the first reading //homing import stuff, uncomment this!!!!!! |
105 | 120 |
count = get_delay(); |
106 | 121 |
if(count>2){ |
107 | 122 |
data[2]=I2C_MSG_HOMING; |
108 |
data[3]=count; |
|
123 |
data[3]= count; |
|
124 |
|
|
109 | 125 |
i2c_putpacket(0x01, data, 4); |
126 |
|
|
110 | 127 |
} |
111 | 128 |
else{ |
112 | 129 |
i2c_putpacket(0x01, data, 2); |
... | ... | |
116 | 133 |
|
117 | 134 |
count = 0; |
118 | 135 |
|
119 |
for(int i=0;i<60000;i++) |
|
136 |
PORTB &= ~_BV(LEDG); |
|
137 |
PORTB |= _BV(LEDR); |
|
138 |
|
|
139 |
|
|
140 |
for(unsigned int i=0;i<60000;i++) |
|
120 | 141 |
{ |
121 | 142 |
delay_ms(1); |
122 | 143 |
if(! (PINB & _BV(DETECT_12V))) |
123 | 144 |
{ |
124 |
PORTB = _BV(LED2);
|
|
145 |
PORTB |= _BV(LEDR);
|
|
125 | 146 |
data[1]=I2C_MSG_CONTACT_ERROR; |
126 | 147 |
i2c_putpacket(0x01, data, 2); |
127 | 148 |
|
128 |
if((++count)>=500)
|
|
149 |
if((++count)>=200)
|
|
129 | 150 |
break; |
130 | 151 |
} |
131 | 152 |
else |
... | ... | |
137 | 158 |
i2c_putpacket(0x01, data, 2); |
138 | 159 |
} |
139 | 160 |
|
140 |
} |
|
161 |
} |
Also available in: Unified diff