I am currently working on programming a PIC16F883 with a 3.2768 MHz oscilator. I need to make some LED blink at the right time, but that is really not relevant here.
The problem is that have set up Timer0, but it isn't working. I am going to post my code and initialization here so you can see :). By the way I am programming in MpLap IDE, in normal C with the Hi-Tech C Compiler.
Initialization:
T0CS = 0x00; //Set Timer0 to Timer-Mode
GIE = 0x01; //Enable all interrupts
PSA = 0x00; //Prescaler enable
PS0 = 0x01; //Prescaler set
PS1 = 0x00; //Prescaler set
PS2 = 0x01; //Prescaler set
The interrupt service routine itself:
void interrupt timer()
{
T0IF = 0x00; //Reset timer
millicounter++; //Add one to the helper variable
PORTA = 0x00;
if (millicounter == 25) //Check if one second has passed.
{
millicounter = 0; //Reset helper variable
seconds++; //Add one to elapsed seconds.
}
}
The problem is that it doesn't look like the timer is running. I have now simulated the program various times with different settings, the latest to make a pin open when the interrupt is being run, and then turned on again in the main. The problem was it never happend. The timer isn't running I think. Why?