The code reads the on-board 10 bit ADC which monitors the battery power.
If the final two lines are in the reverse order of what they presently are - that is: if they are the same as the others - the code (with good battery voltage) will step down six lines and then hop to line 13 (the last line). This means that with good voltage the light will be a red "low voltage".
If I reverse the order of the bottom two lines the code operates normally and works fine.
This appears to be some sort of optimization but this is the free version which I understood to not have any optimizations in it.
- Code: Select all
if (ad_flag == TRUE && ADCON0bits.GODONE == DONE) {
int_ADC_rd = ADRESH;
int_ADC_rd = int_ADC_rd << 8;
int_ADC_rd |= ADRESL;
if (int_ADC_rd >= 0x30E) { // More than 8.8 Volts turn Green
led_mode[1] = OFF; // Red LED
led_mode[2] = LED_ON; // Grn LED
}
else if (int_ADC_rd <= 0x2E6) { // Less than 8.4 turn Red
led_mode[1] = LED_ON; // Red LED
led_mode[2] = OFF; // Grn LED
}
else { // In between turn Orange
led_mode[2] = LED_ON; // Grn LED
led_mode[1] = LED_ON; // Red LED
}