Page 1 of 1

Invisible Problem

PostPosted: Wed Aug 06, 2014 12:49 am
by SLTom992
I backed up my working program a couple of days ago and ended up overwriting it with an older backup.

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);
                }
            }
        }
    }
}

Re: Invisible Problem

PostPosted: Wed Aug 06, 2014 1:32 am
by ric
What are the values defined for LED_OFF and LED_ON?
It would be best to show the definitions for your arrays also.

Re: Invisible Problem

PostPosted: Wed Aug 06, 2014 2:46 pm
by drh
Are the pins driving the LEDS configured as outputs?