I am writing my first C program. It is going very good but I have run into one problem... This is being written in Codewarrior for a Freescale MCU.
I have declared a variable in Main.c
Code:
volatile int seconds=10; //a seconds counter
Then in Main.c loop, I check the value of counter and turn on an LED if it is zero:
Code:
if (!seconds)
{
led_blue_on();
}
I have an ISR that is running and clocking at 1 seconds that decrements the variable 'seconds'. Here is the ISR code:
Code:
*/
__interrupt void isrVrtc(void)
{
/* Write your interrupt code here ... */
#include "MyEquates.h"
volatile int seconds; //have to add this to compile this file
RTCSC_RTIF=1; //reset RTC flag
if (seconds!=0){ //update seconds counter
seconds--; //reduce count
}
}
/* end of isrVrtc */
So my problem is that the variable 'seconds' is not the same in Main.c as it is in my ISR file. So 'seconds' in main never gets decremented. But I can see that 'seconds' in my ISR does decrement in another part of memory.
How can I declare my variable 'seconds' so that its value is the same in Main.c and my ISR file? I tried adding 'volatile', which I thought would solve the problem by making it global. But it did not.
Thank you!