2camjohn
Member
I have been trying to get timer0 to work on my pic16f628. I have read the datasheets and various websites on the subject. I think I must be overlooking something that is very simple.
Here is what I have done:
At the start of the program:
OPTION_REG.PS0 = 1
OPTION_REG.PS1 = 1
OPTION_REG.PS2 = 0
(Option reg bits 0 - 2 = 110 - sets prescalar to 4th option)
INTCON.INTE = 1
INTCON.T0IE = 1
(intcon bits INTE and T0IE to 1 - enable RB0 and timer0 interrupts)
INTCON.GIE = 1
(enable interrupts - all)
during the interrupt sequence I have
If INTCON.INTF = 1 Then
(if interrupt is generated by RB0)
*some code here, dependant on timer*
else
(else it must have been the timer)
*timer code here*
end if
INTCON.INTF = 0
INTCON.T0IF = 0
(enable timer and RB0 interrupts)
resume
The config i am using is:
IntRC osscilator
Power up timer Enabled
Watchdog timer Disabled
The problem is the RB0 interrupt code works, but the timer0 code never activates. Can anyone tell from my pseudocode what I have missed?
Ive been tearing my hair out trying to work it out.
Thanks in advance for your time
John
Here is what I have done:
At the start of the program:
OPTION_REG.PS0 = 1
OPTION_REG.PS1 = 1
OPTION_REG.PS2 = 0
(Option reg bits 0 - 2 = 110 - sets prescalar to 4th option)
INTCON.INTE = 1
INTCON.T0IE = 1
(intcon bits INTE and T0IE to 1 - enable RB0 and timer0 interrupts)
INTCON.GIE = 1
(enable interrupts - all)
during the interrupt sequence I have
If INTCON.INTF = 1 Then
(if interrupt is generated by RB0)
*some code here, dependant on timer*
else
(else it must have been the timer)
*timer code here*
end if
INTCON.INTF = 0
INTCON.T0IF = 0
(enable timer and RB0 interrupts)
resume
The config i am using is:
IntRC osscilator
Power up timer Enabled
Watchdog timer Disabled
The problem is the RB0 interrupt code works, but the timer0 code never activates. Can anyone tell from my pseudocode what I have missed?
Ive been tearing my hair out trying to work it out.
Thanks in advance for your time
John