| 1 |
list p=18F2455 |
| 2 |
include p18f2455.inc |
| 3 |
radix decimal |
| 4 |
;Program Configuration Register 1H |
| 5 |
; __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H |
| 6 |
;Program Configuration Register 2L |
| 7 |
; __CONFIG _CONFIG2L, _BOR_OFF_2L & _PWRT_ON_2L |
| 8 |
;Program Configuration Register 2H |
| 9 |
; __CONFIG _CONFIG2H, _WDT_OFF_2H |
| 10 |
cblock 0x20 |
| 11 |
counth,countl ;for timer0 interrupt counter |
| 12 |
msecsh,msecsl |
| 13 |
seconds |
| 14 |
tmps,tmp10 |
| 15 |
wsave |
| 16 |
ssave |
| 17 |
endc |
| 18 |
;onecycle equ 256-10000/128 ;time for 1msec |
| 19 |
onecycle equ 0x78 |
| 20 |
org 0 |
| 21 |
goto main |
| 22 |
org 8 |
| 23 |
goto highpint |
| 24 |
org 18 |
| 25 |
retfie |
| 26 |
highpint: |
| 27 |
movwf wsave ;save WREG |
| 28 |
swapf STATUS,w ;save STATUS |
| 29 |
movwf ssave |
| 30 |
movlw 0xff |
| 31 |
movlw 0xec ;rrr |
| 32 |
movwf TMR0H |
| 33 |
movlw onecycle |
| 34 |
movwf TMR0L ;re-initialize the timer for next time |
| 35 |
decf msecsl,f |
| 36 |
bnz skip0 |
| 37 |
movf msecsh,w |
| 38 |
btfsc STATUS,Z |
| 39 |
goto resetms |
| 40 |
decf msecsh,f ;rrr changed w to f |
| 41 |
goto skip0 |
| 42 |
resetms: |
| 43 |
movlw 1000&255 |
| 44 |
movwf msecsl |
| 45 |
movlw 1000>>8 |
| 46 |
movwf msecsh |
| 47 |
incf seconds,f |
| 48 |
skip0: |
| 49 |
bcf INTCON,T0IF ;re-enable interrupt |
| 50 |
swapf ssave,w |
| 51 |
movwf STATUS |
| 52 |
swapf wsave,f |
| 53 |
swapf wsave,w |
| 54 |
retfie |
| 55 |
; |
| 56 |
main: |
| 57 |
movlw 0x80 ;tmr0on=1,t08bit=0,t0cs=0,t0se=-,psa=0,t0ps2=0,t0ps1=0,t0ps0=0 |
| 58 |
;so timer0 will run at chip instruction frequency as a 16bit timer |
| 59 |
movwf T0CON |
| 60 |
movlw 0xff |
| 61 |
movlw 0xec ; rrr` |
| 62 |
movwf TMR0H |
| 63 |
movlw onecycle |
| 64 |
movwf TMR0L ;initialize the timer for 1 msec |
| 65 |
movlw 1000&255 |
| 66 |
movwf msecsl |
| 67 |
movlw 1000>>8 |
| 68 |
movwf msecsh |
| 69 |
clrf seconds |
| 70 |
bcf INTCON,T0IF ;clear interrupt flag |
| 71 |
bsf INTCON,T0IE ;enable interrupt |
| 72 |
bsf INTCON,GIE ;enable interrupts |
| 73 |
; |
| 74 |
mainloop: |
| 75 |
goto mainloop |
| 76 |
end |