;**********************************************************************
; Filename: timer.asm *
; Date: 2001/1/6 *
; File Version: *
;**********************************************************************
list p=16F84 ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
;***** VARIABLE DEFINITIONS
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving
count_data EQU 0x10 ;1sec keisoku count ram
sec1_data EQU 0x11 ;1sec LED data ram
sec10_data EQU 0x12 ;10sec LED data ram
min1_data EQU 0x13 ;1min LED data ram
min10_data EQU 0x14 ;10min LED data ram
wait_data EQU 0x15 ;wait data ram
tm0_setdata EQU 63h ;255-156=99=63H 156*128=19.968msec
cnt_setdata EQU 32h ;19.968*50=0.9984sec
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
;---------------------------------
bcf INTCON,T0IF
movlw tm0_setdata
movwf TMR0
decfsz count_data,1
goto next_int
time_up movlw cnt_setdata
movwf count_data
movlw 01h
subwf sec1_data,1
btfsc STATUS,0
goto next_int
movlw 09h
movwf sec1_data
movlw 01h
subwf sec10_data,1
btfsc STATUS,0
goto next_int
movlw 05h
movwf sec10_data
movlw 01h
subwf min1_data,1
btfsc STATUS,0
goto next_int
movlw 09h
movwf min1_data
movlw 01h
subwf min10_data,1
btfsc STATUS,0
goto next_int
movlw 09h
movwf min10_data
next_int
nop
;----------------------------------
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
call port_set
movlw 00h
movwf PORTA
movlw 0f0h
movwf PORTB
call timer0_set
movlw cnt_setdata
movwf count_data
movlw 00h
movwf sec1_data
movwf sec10_data
movlw 09h ;test data
movwf min1_data
movwf min10_data
main_loop
;----------------------- led7_disp
movf sec1_data,0
iorlw 0f0h
movwf PORTB
bcf PORTB,4
call wait_1
bsf PORTB,4
movf sec10_data,0
iorlw 0f0h
movwf PORTB
bcf PORTB,5
call wait_1
bsf PORTB,5
movf min1_data,0
iorlw 0f0h
movwf PORTB
bcf PORTB,6
call wait_1
bsf PORTB,6
movf min10_data,0
iorlw 0f0h
movwf PORTB
bcf PORTB,7
call wait_1
bsf PORTB,7
;-----------------------
goto main_loop
wait_1
movlw 0ffh
movwf wait_data
wait_2
decfsz wait_data,1
goto wait_2
return
port_set
;RA0,RA1(OUT)
;RA2,RA3,RA4(IN)
;RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7(OUT)
bsf STATUS,RP0
clrf TRISA
bsf TRISA,3
nop
bsf TRISA,4
nop
bsf TRISA,2
clrf TRISB
bcf STATUS,RP0
return
timer0_set
bsf STATUS,RP0
movlw 086h ;(1)PORTB NOT PULLUP
;(0)INTEDG
;(0)TOCS
;(0)TOSE
;(0)PSA
;(110)1/128
movwf OPTION_REG
bcf STATUS,RP0
movlw tm0_setdata
movwf TMR0
bsf INTCON,T0IE
bsf INTCON,GIE
return
END ; directive 'end of program'
|