void interrupt()
{
if (INTCON.TMR0IF ==1) // timer 0 interrupt flag
{
GPIO = ~GPIO; // Toggle PORTB bit0 LED
INTCON.TMR0IF = 0; // clear the flag
INTCON.TMR0IE = 1; // reenable the interrupt
TMR0 = 204; // reset the timer preset count
}
}
// code starts here...
void main()
{
// setup portb to show the interrupts by blibking LEDs
TRISIO = 0; // PORT is all output...to show the interrupts
GPIO = 0; // start with all outputs low
ANSEL = 0;
//Timer0 Registers Prescaler= 1 - TMR0 Preset = 204 - Freq = 38461.54 Hz - Period = 0.000026 seconds
OPTION_REG.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
OPTION_REG.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
OPTION_REG.PSA = 1; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
OPTION_REG.PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Rate Select bits
OPTION_REG.PS1 = 0;
OPTION_REG.PS0 = 0;
TMR0 = 238; // preset for timer register
// Interrupt Registers
INTCON = 0; // clear the interrpt control register
INTCON.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
INTCON.TMR0IF = 0; // bit2 clear timer 0 interrupt flag
INTCON.GIE = 1; // bit7 global interrupt enable
while(1) //endless loop
{
}
}