initializing timer0 in pic 16f84

Status
Not open for further replies.

malak_pal2004

New Member
hay ,
i want my timer to have a 500ms interrupt on overflow interval
fosc is typically 4 MHz so fosc/4=1MHz
desired scale is 500000
max scale by timer 256*256
if we say 4* 125=500 then i need 125 interrupts? each after 4 seconds? 32 prescaling?
if so i will intialize thetimer0 to 131 , but if i want to count backward should it be 125 or 124?

this is my hardware timer code

bcf STATUS,RP1
bsf STATUS,RP0
movlw B'11010100
movwf OPTION
bcf STATUS,RP0
movlw D'131'
movwf TMRO
bcf INTCON,T0IF
bsf INTCON,T0IE
bsf INTCON,GIE
return
and my software timer

five00Ms

movlw 124
movwf BLNKCNT

wait500

btfss BLNKCNT,7
goto wait500
return

my question why 124 not 125?


plz HELP!
 
make your xtal or resonator 4.194304 Mhz

set prescaler for 256 and assign it to tmr0
set tmr0 reload value at 255
set a register to count to 8 inside your interrupt service routine
 
Or dump the 16F84, use it's modern replacement the 16F628 - and use timer2, a far more sensible timer.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…