Page 2 of 2

Re: Compiler Error?

PostPosted: Thu Aug 14, 2014 11:25 pm
by ric
ahhh, just a moment. You said "will step down six lines and then hop to line 13 (the last line). "

Can you explain exactly where it jumped to.
I thought you meant the last functional line, which is " led_mode[1] = LED_ON; // Red LED", but that is line#15.
Line#13 is the second "else"

Re: Compiler Error?

PostPosted: Fri Aug 15, 2014 8:04 pm
by tunelabguy
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.

Re: Compiler Error?

PostPosted: Fri Aug 15, 2014 8:19 pm
by jtemples
Another slightly odd thing about this code is that it refers to indices 1 and 2 of an array; is it really an array of three elements?

Re: Compiler Error?

PostPosted: Mon Aug 18, 2014 6:17 pm
by SLTom992
The array led_on[] is used because the LEDs are blinked at different rates to mean different things though you can think of them merely as LAT's.

It appears that the original problem was not caused by the code optimizer but from the way I was using the ADRESH and ADRESL registers and testing them separately instead of combining them into a single INT as is shown in the code displayed. How THAT could have caused the problem I don't know but it makes no difference now in which order I place the final instructions in the subroutine.

If I have the time I'll dig though my back-ups and see if I can find the original code for your perusal.