here is the code so far, will this work? do i need to set the offset only once or every cycle? and will this be accurate or do i need to adjust for instruction cycle times?
#chip 12F683, 18
#config MCLRE=off, WDT=off
on interrupt Timer1Overflow call IncCounter
InitTimer1 ExtOsc, PS1_8
dim full as byte
dim min as byte
dim sec as byte
dim hr as byte
full = 0
wait 2 s
ClearTimer 1
TMR1L = 0 'Need to do this according to the PIC datasheet
TMR1H = 36
TMR1L = 13 'should be 10hz
StartTimer 1
main:
goto main
Sub IncCounter
full=full+1
if full = 10 then sec=sec+1
if sec = 60 then
min= min+1
sec=0
end if
if min= 60 then
hr=hr+1
min=0
end if
if hr=25 then hr=0
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is the code so far, will this work? do i need to set the offset only once or every cycle? and will this be accurate or do i need to adjust for instruction cycle times?
#chip 12F683, 18
#config MCLRE=off, WDT=off
on interrupt Timer1Overflow call IncCounter
InitTimer1 ExtOsc, PS1_8
dim full as byte
dim min as byte
dim sec as byte
dim hr as byte
full = 0
wait 2 s
ClearTimer 1
TMR1L = 0 'Need to do this according to the PIC datasheet
TMR1H = 36
TMR1L = 13 'should be 10hz
StartTimer 1
main:
goto main
Sub IncCounter
full=full+1
if full = 10 then sec=sec+1
if sec = 60 then
min= min+1
sec=0
end if
if min= 60 then
hr=hr+1
min=0
end if
if hr=25 then hr=0
end sub
Hi ,
Yes you must reload TMR1H and TMR1L with their value in your sub IncCounter or else clock will be false
and instead of
"if full=10 then sec=sec+1"
you may write
if full=10 then
sec=sec+1
full=0
end if
otherwise full will increase to 255 then will stop ! Its value will never be =10
regards
GC