So I've spent the last couple of day redoing all of my code and finally it's working except for one function. This is an LED light blinking function. The LED's can be blinked at different rates to means different things and they can also be blinked very rapidly so that we conserve power.
The function operates the first LED properly. And external function sets the mode for each LED and that operates properly. The time counter counts down each counter correctly. But it only enters the "if" statements to turn the LEDs on or off for the initial "0" LED.
I am testing it by running it in Debug mode on an ICD3 and stopping it in various locations and observing the variables. It all appears to me to be properly programmed but it isn't working.
This has to be something staring me in the face but I can't see it.
- Code: Select all
void blink_light() {
char i, k; // Normal counter variable
// mode indicates that LED is running, and whether it is
// in the on mode or off mode (0 = not running, 1 = on 2 = off)
// time is the amount of "on" or "off" time
// "led_on" or "led_off" contain the reloads for time.
for (i = 0; i < 5; i++) {
k = 0x02;
if (led_mode[i] > 0 && led_time[i] > 0) { // if active count down
led_time[i]--;
if ((led_time[i] == 0) && (led_mode[i] > 0)) { // if timeout, action
if (led_mode[i] == LED_OFF) {
led_time[i] = led_on[i]; // insert next time
led_mode[i] = LED_ON;
LATB |= (k << i); // LED off
}
else {
led_time[i] = led_off[i];
led_mode[i] = LED_OFF;
LATB &= ~(k << i);
}
}
}
}
}