View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 31, 2010 3:01 pm |
|
|
I didn't actually write the inner loop code. Someone else on the
forum wrote that as a fragment. I incorporated it into a test program
just to be my helpful old self. But I'll try to explain it.
The 'loop' variable is initialized to 100 (Set in LOOPCNT).
The first if() statement decrements the loop counter once per pass.
It will decrement to 99, then 98, etc., down to 0 (after 100 interrupts).
When it goes to 0, the if() statement will reload the loop counter with
the initial value of 100.
I think there's a bug with the 'pulse' variable. It's not initialized.
One quick fix would be to initialize it to 0 in the static declaration:
Quote: | #INT_RTCC
void tick_interrupt(void)
{
static int8 loop = LOOPCNT;
static int8 pulse = 0; |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Aug 31, 2010 4:56 pm |
|
|
PCM programmer wrote: | I think there's a bug with the 'pulse' variable. It's not initialized. | In ANSI C all static and global variables will be initialized to zero before the program starts, except when the programmer specified another value.
To avoid the confusion about the variable being initialized or not I often explicitly add the initial value. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 31, 2010 5:17 pm |
|
|
You're right, and I looked for that in the .LST file but I missed it.
It is there (with no explicit init of pulse in the code):
|
|
|
Brian
Joined: 29 Jun 2010 Posts: 10
|
|
Posted: Wed Sep 01, 2010 11:57 am |
|
|
Everything is working now and makes sense.
Thanks! |
|
|
|