Hi folks,
I've scratched my head over this one for most of the day and after paring my original program down to the minimal number of lines, I'm still stuck. First, the code:
This is essentially an LED flasher where I can control the duration and delay of the flashes but substituting different numbers in the "if count1=" lines. Hopefully it's pretty easy to follow. Initially, ignore the "if count1=7 ... endif" lines.Code:@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF count1 var word init: count1 = 0 check1: if count1 = 0 then high 0 -------------- if count1 = 7 then high 1 pause 20 low 1 endif ------------- IF count1 = 20 then low 0 if count1 = 100 then count1=0 else count1 = count1 + 1 endif pause 20 ' 20 ms increments goto check1
When I run this on my 16F628, I expect to see my LED flash at a constant rapid rate. When count1=0, the LED goes on. When count1=20 the LED goes off. When count1=100 we start all over again.
What actually happens is that as soon as I power up the PIC, I get one flash, a short delay, then the rapid flashes I expect. It's this rogue flash at the beginning that I can't figure out.
Now about the HIGH 1/LOW 1 lines. I added these in to flash a "debugging" LED when count1 reached certain values. What I found was that, for the first cycle only, count1 was being reset when it reached 6! If I leave the code as shown (IF count1=7), the LED at 0 does it's initial wierd flash before running smoothly. If I change it to (IF count1=6), then I get a flash from BOTH LEDs during the first rogue flash.
Can anyone offer any explanation to this? After the first errant flash everything runs fine. I just don't get it.
Thanks for your time,
Jeff
Bookmarks