I got the question about volatile variebles and eeprom memory. (I use C and IDE)
First of all, I have a program that has to remember a variable's value even if I reset the thing (this value changes between 0 - 9 so it is an unsigned char). The details and the program is below ;
*counter is my variable that I change value via interrupt and push button *counter is my variable that microcontroller has to remember after reset *counter is my variable that can be changed by both main and interrupt
---------------------------------------------------------------- volatile unsigned char counter; ..... ..... void interrupt() { counter++; Delay_ms(150); if(counter == 10) counter=0; while(bit is zero); Delay_ms(20); ..... ..... SFRA=0xD0; } void main() { for(; { if(counter == 0) { .....program writes 7 seg the value of counter } if(counter == 1) { .....program writes 7 seg the value of counter } if(counter == 2) { .....program writes 7 seg the value of counter } if(counter == 3) { .....program writes 7 seg the value of counter } if(counter == 4) { .....program writes 7 seg the value of counter } if(counter == 5) { .....program writes 7 seg the value of counter } if(counter == 6) { .....program writes 7 seg the value of counter } if(counter == 7) { ......program writes 7 seg the value of counter } if(counter == { ........program writes 7 seg the value of counter } if(counter == 9) { ......program writes 7 seg the value of counter } } } Now, this program does not work properly it loses the value of counter. I got two choices; 1. declaring counter variable as a volatile (but I could not succeed) 2. using eeprom memory but this will increase my loop time. Please help me I am confused.
View all questions in Keil forum