;**********************************************************************
; Filename: timer.asm *
; Date: 2001/1/12 *
; 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
start_stop EQU 0x16 ;start/stop ram
;start_stop,0 timer start/stop flg
;start_stop,1 buzzer flg
key_data EQU 0x17 ;key data ram
;key_data,2 start/stop key
;key_data,3 up1 key
;key_data,4 up10 key
;key_data,5 up1,up10 key
key_input EQU 0x18 ;key input ram
;key_input,2 start/stop key
;key_input,3 up1 key
;key_input,4 up10 key
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
;--------------------------------
btfss start_stop,0 ;start/stop check
goto next_int
call zero_check
btfsc start_stop,1 ;buzzer check
goto next_int
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 ;port initial set
movwf PORTA
movlw 0f0h
movwf PORTB
call timer0_set
movlw 00h ;start/stop <= stop
;buzzer flg off
movwf start_stop
movlw 0ffh ;key data,key input clear
movwf key_data
movwf key_input
movlw cnt_setdata
movwf count_data
call sec_clear
call min_clear
main_loop
;-------------------------------------- key scan 1
movlw 0ffh ;key input clear
movwf key_input
btfss PORTA,2 ;start/stop key check
bcf key_input,2 ;start/stop key input ari
btfss PORTA,3 ;up1 key check
bcf key_input,3 ;up1 key input ari
btfss PORTA,4 ;up10 key check
bcf key_input,4 ;up10 key input ari
;--------------------------------------- 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
;------------------------------------- key scan 2
stsp_check
btfss PORTA,2 ;start/stop key check
goto stsp_next
bsf key_data,2 ;start/stop key off
goto up1_check
stsp_next
btfsc key_input,2 ;start/stop key input check
goto up1_check
btfss key_data,2 ;start/stop key on check
goto up1_check
bcf key_data,2 ;start/stop key on
btfss start_stop,0 ;start/stop check
goto stsp_next_2
bcf start_stop,0 ;start/stop <=stop
nop
bcf start_stop,1 ;buzzer flg off
goto up1_check
stsp_next_2
bsf start_stop,0 ;start/stop <=start
;-------------------------------------
up1_check
btfss PORTA,3 ;up1 key check
goto up1_next
bsf key_data,3 ;up1 key off
goto up10_check
up1_next
btfsc key_input,3 ;up1 key input check
goto up10_check
btfss key_data,3 ;up1 key on check
goto up10_check
bcf key_data,3 ;up1 key on
btfsc start_stop,0 ;start/stop check
goto up10_check
call sec_clear ;min1_data up
incf min1_data,1
movlw 0ah
subwf min1_data,0
btfss STATUS,0
goto up10_check
movlw 00h
movwf min1_data
;--------------------------------------
up10_check
btfss PORTA,4 ;up10 key check
goto up10_next
bsf key_data,4 ;up10 key off
goto up110_check
up10_next
btfsc key_input,4 ;up10 key input check
goto up110_check
btfss key_data,4 ;up10 key on check
goto up110_check
bcf key_data,4 ;up10 key on
btfsc start_stop,0 ;start/stop check
goto up110_check
call sec_clear ;min10_data up
incf min10_data,1
movlw 0ah
subwf min10_data,0
btfss STATUS,0
goto up110_check
movlw 00h
movwf min10_data
;---------------------------------------
up110_check
btfsc key_data,3 ;up1 key on check
goto up110_next
btfsc key_data,4 ;up10 key on check
goto up110_next
btfss key_data,5 ;up1up10 key on check
goto next_key
bcf key_data,5 ;up1up10 key on
btfsc start_stop,0 ;start/stop check
goto next_key
call min_clear
goto next_key
up110_next
bsf key_data,5 ;up1up10 key off
;---------------------------------------
next_key
;---------------------------------------
buzzer
btfss start_stop,1 ;buzzer flg check
goto buzzer_2
bsf PORTA,0 ;buzzer on
goto buzzer_3
buzzer_2
bcf PORTA,0
buzzer_3
;---------------------------------------
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
;------------------------------------------------------------------------------
sec_clear
movlw 00h
movwf sec1_data
movwf sec10_data
return
;------------------------------------------------------------------------------
min_clear
movlw 00h
movwf min1_data
movwf min10_data
return
;------------------------------------------------------------------------------
zero_check
movf sec1_data,1
btfss STATUS,2 ;Z check
return
movf sec10_data,1
btfss STATUS,2 ;Z check
return
movf min1_data,1
btfss STATUS,2 ;Z check
return
movf min10_data,1
btfss STATUS,2 ;Z check
return
btfss start_stop,0 ;start/stop check
return
bsf start_stop,1 ;buzzer flg on
return
;-----------------------------------------------------------------------------
END ; directive 'end of program'
|