Rev 271 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 271 | Rev 273 | ||
---|---|---|---|
Line 60... | Line 60... | ||
60 | #include "uart1.h" |
60 | #include "uart1.h" |
61 | #include "fat16.h" |
61 | #include "fat16.h" |
62 | #include "led.h" |
62 | #include "led.h" |
63 | #include "menu.h" |
63 | #include "menu.h" |
64 | #include "printf_P.h" |
64 | #include "printf_P.h" |
- | 65 | #include "analog.h" |
|
- | 66 | ||
- | 67 | #ifdef USE_FOLLOWME |
|
- | 68 | int16_t UBat = 120; |
|
- | 69 | #endif |
|
Line 65... | Line 70... | ||
65 | 70 | ||
66 | int main (void) |
71 | int main (void) |
67 | { |
72 | { |
68 | // disable interrupts global |
73 | // disable interrupts global |
Line 73... | Line 78... | ||
73 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
78 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
74 | WDTCSR = 0; |
79 | WDTCSR = 0; |
Line 75... | Line 80... | ||
75 | 80 | ||
76 | // initalize modules |
81 | // initalize modules |
77 | LED_Init(); |
- | |
78 | 82 | LED_Init(); |
|
79 | LEDRED_ON; |
83 | LEDRED_ON; |
80 | TIMER0_Init(); |
84 | TIMER0_Init(); |
81 | USART0_Init(); |
85 | USART0_Init(); |
- | 86 | USART1_Init(); |
|
82 | USART1_Init(); |
87 | ADC_Init(); |
83 | // enable interrupts global |
88 | // enable interrupts global |
84 | sei(); |
89 | sei(); |
85 | LEDRED_OFF; |
90 | LEDRED_OFF; |
86 | #ifdef USE_FOLLOWME |
91 | #ifdef USE_FOLLOWME |
Line 119... | Line 124... | ||
119 | 124 | ||
120 | while (1) |
125 | while (1) |
121 | { |
126 | { |
122 | USART0_ProcessRxData(); |
127 | USART0_ProcessRxData(); |
- | 128 | USART0_TransmitTxData(); |
|
- | 129 | // restart ADConversion if ready |
|
- | 130 | if(ADReady) |
|
- | 131 | { |
|
- | 132 | DebugOut.Analog[0] = Adc0; |
|
- | 133 | DebugOut.Analog[1] = Adc1; |
|
- | 134 | DebugOut.Analog[2] = Adc2; |
|
- | 135 | DebugOut.Analog[3] = Adc3; |
|
- | 136 | DebugOut.Analog[4] = Adc4; |
|
- | 137 | DebugOut.Analog[5] = Adc5; |
|
- | 138 | DebugOut.Analog[6] = Adc6; |
|
- | 139 | DebugOut.Analog[7] = Adc7; |
|
- | 140 | ||
- | 141 | #ifdef USE_FOLLOWME |
|
- | 142 | // AVcc = 5V --> 5V = 1024 counts |
|
- | 143 | // the voltage at the voltage divider reference point is 0.8V less that the UBat |
|
- | 144 | // because of the silicon diode inbetween. |
|
- | 145 | // voltage divider R2=10K, R3=1K |
|
- | 146 | // UAdc4 = R3/(R3+R2)*(UBat-0.8V) = 1k/(1k+10k)*(UBat-0.8V) = (UBat-0.8V)/11 |
|
- | 147 | UBat = (3 * UBat + (69 * Adc4) / 128 + 8) / 4; |
|
- | 148 | DebugOut.Analog[8] = UBat; |
|
- | 149 | #endif |
|
- | 150 | ADReady = 0; |
|
- | 151 | ADC_Enable(); |
|
123 | USART0_TransmitTxData(); |
152 | } |
124 | } |
153 | } |
125 | return (1); |
154 | return (1); |