SLTom992 wrote:I'm not sure I understand you. I have the proper battery voltage measured. In the one case it lights the green LED and with those two instructions revered it lights the red LED instead.
This description of the
outcome is not consistent with your description of the sequence of instructions that would produce this outcome. If the battery voltage is above 8.8 volts, then the code should execute the following instructions:
- Code: Select all
led_mode[1] = OFF; // Red LED
led_mode[2] = LED_ON; // Grn LED
If you are claiming that the result is a red light, then I assume you are claiming the following instructions are executed:
- Code: Select all
led_mode[1] = LED_ON; // Red LED
led_mode[2] = OFF; // Grn LED
But none of your descriptions of single-stepping said that these were the instructions that were executed. That is why I assumed you were perhaps mistaken about which instructions were executed and deduced the "compiler error" strictly from observing which LED was turned on in the end. Despite being asked repeatedly to clarify which instructions you say are being executed, you have so far refused to clarify your hopelessly vague description.
I also asked you, and you failed to answer me, how the setting of led_mode[1] and led_mode[2] result in making the red or green LEDs go on or off. The syntax looks a lot like an array in memory, not like direct access to an I/O port. If you are claiming the
compiler messed up because the red LED is on, you must consider the possibility that
you messed up in making the setting of this array in memory affect and I/O port that is presumably controlling the LEDs.
If you want to make sense of debugging, you must either:
1. Turn off all optimizations. Or..
2. Debug at the machine language level, not the C-code level, because optimizations can make that very confusing.
Since this code is very simple, my guess is that this code is executing fine, but you are doing something wrong with the array led_mode[] elsewhere in the code to make the red LED come one.