func main() global counter as integer global sec as integer global min as integer global hour as integer dim x clear 'Set the timer hour = 5 min = 50 setTMR0reg() 'Go set up the hardware registers for Timer 0 decmask %10000011 loop: print hour,":",min,":",sec pause 500 goto loop endfunc func setTMR0reg() 'Setup timer 0 T0CON = 3 'Set the timer0 prescale to 1:16 T0CON.bit(3) = 0 'Make sure you use prescale T0CON.bit(7) = 1 'Turn timer on 'IRQ stuff INTCON.bit(5) = 1 'Enable Timer 0 IRQ INTCON.bit(7) = 1 'Enable global interupts endfunc 'Can be placed outside functions '--------------------------------------------------- 'IRQ handler for INT0 IRQ '--------------------------------------------------- startirqasm TMR0 movlb .2 ;We need this to access global variables ;========================================== incf G_counterl,f ;If counter < 10 then just exit movlw .10 subwf G_counterl,w btfss STATUS,Z goto exithandler clrf G_counterl ;========================================= incf G_secl,f ;If sec < 60 just exit movlw .60 subwf G_secl,w btfss STATUS,Z goto exithandler clrf G_secl ;========================================= incf G_minl,f ;If min < 60 just exit movlw .60 subwf G_minl,w btfss STATUS,Z goto exithandler clrf G_minl ;========================================= infsnz G_hourl,f incf G_hourh,f exithandler ;Use this to tweek time movlw .1 ;Major adjustmets bigger for faster movwf TMR0H movlw .0 ;Minor adjustment bigger for faster movwf TMR0L endirqasm