Aaaaah yes it worked. I had this thought that since as the name "Timer Interrupt Flag" itself suggests, it looked like as if I needed to activate the interrupt settings too, but as a friend told me, "You're not doing any interrupt programming, it's only polling".
Note I moved setup code to before the while loop and remed out the interrupt code.
I have a question: Why is it a problem to reset TMR2IF first, then turn on the timer, since TMR2IF should certainly flag up when the TMR2 reaches the value of PR2?
In short, why this snippet:
C:
while (1){
TMR2ON_bit=1; //turn on the timer
if (TMR2IF_bit==1){ //poll for the flag bit to go high
PORTD=~PORTD;
TMR2IF_bit=0; //reset the flag bit
TMR2ON_bit=0; //stop the timer
}
}
aaahh... now I see. I thought the loop would go back to the part where the TMR2ON is set, but it's not part of the "if", but only part of the "while" loop. My bad.
Sorry, my bad, I didn't realise that you were turning it back on again in the while loop. The code will go back to where the timer is turned back on and so I have no idea why that wouldn't work.