📄 timer.asm
字号:
; TIMER.ASM
; *********
; [ milindhp@tifrvax.tifr.res.in ]
;Set Processor configuration word as = 0000 0000 1010 b.
; a] -MCLR tied to VDD (internally).
; b] Code protection off.
; c] WDT disabled.
; d] Internal RC oscillator [4 MHZ].
list p=12c508, r=dec
include "p12c508.inc"
;define ram
include "def_ram.asm"
;processor start
org 0
goto start
;define legends and table
include "tables.asm"
;subroutines
include "subs.asm"
;initialize and start
start clrf key
clrf oldkey
clrf newkey
clrf digit_inc
clrf units
clrf tens
clrf counter_4ms
clrf counter_100ms
clrf seconds
movlw 250 ;4000us tmr0 (1:16 prescaler * 250 )
movwf tmr_comp
call init_ports ;init ports & timer
main movf tmr_comp, w ;is tmr0 = tmr_comp (4 msec over?)
xorwf TMR0, w
btfss STATUS, Z ;skip if = 250
goto main
movlw 250
addwf tmr_comp, f ;update 4 msec compare register
incf counter_4ms, f
movlw 25
xorwf counter_4ms, w ;is 4ms * 25 = 100ms over ?
btfss STATUS, Z ;skip if = 100ms
goto main
clrf counter_4ms
;************** 100 MSEC OVER **********************************
incf counter_100ms, f
movlw 10
xorwf counter_100ms, w ;is 100ms * 10 = 1sec over ?
btfss STATUS, Z ;skip if 1 sec over
goto main21 ;jmp if 1 sec not over
clrf counter_100ms ;1 sec over
incf seconds, f
movlw 60
xorwf seconds, w ;is 1 minute over ?
btfss STATUS, Z ;skip if 1 min over
goto main21
;************** 1 MINUTE OVER *********************************
clrf seconds
;process relay and display
;if tens & units both = 0 then rly off and out
;else relay on & decrement display & out
movf tens, w
iorwf units, w
btfss STATUS, Z
goto main1
relay_off
goto main21
main1 relay_on
movf units, f
btfss STATUS, Z
goto main2
movlw 9
movwf units
decf tens, f
goto main21
main2 decf units, f
;************** EXECUTED EVERY 100 MSEC *************
main21 call read_keys
;** DISPLAY ROUTINE TO BE EXECUTED EVERY 500 MSEC **
;process display every 500 msec
;if unit key pressed increment unit display
;if tens key pressed increment tens display
;flash unit display's dec. pt. every second if units & tens
;not equal to zero i.e. indicate timer is active
;execute display routine in counter_100ms = 0 or 5
movf counter_100ms, w
btfsc STATUS, Z
goto main3
xorlw 5
btfss STATUS, Z
goto main
;if units_key pressed then inc units display between 0 thr. 9
;if tens_key pressed then inc tens display between 0 thr. 9
main3 btfss digit_inc, units_inc
goto main4
bcf digit_inc, units_inc
;inc units display. if units = 10 then units = 0
incf units, f
movlw 10
xorwf units, w
btfsc STATUS, Z ;skip if not equal
clrf units
main4 btfss digit_inc, tens_inc
goto main5
bcf digit_inc, tens_inc
;inc tens display. if tens = 10 then tens = 0
incf tens, f
movlw 10
xorwf tens, w
btfsc STATUS, Z ;skip if not equal
clrf tens
;convert decimal in units & tens to decoded segment data
;for led display in scrtch1 & 2 for transmission
main5 movf tens, w
call get_seg
movwf scrtch1
movf units, w
call get_seg
movwf scrtch2
;flash (toggle) decimal point every 500ms if timer active
;i.e. if timer not equal to zero i.e. relay on, then flash
;decimal point else, do not to indicate relay off
movf tens, w
iorwf units, w
btfsc STATUS, Z ;skip to flash dp
goto main6 ;jmp if 0 to no flash
movf counter_100ms, f
btfss STATUS, Z ;toggle-on dec pt if counter_100ms = 0
goto main6 ;else jmp out to toggle-off
;flash dp of units display
movlw dec_pt
andwf scrtch2, f
;transmit data from scrtch1 thr scrtch1 to display circuit (msb first).
main6 movlw 16 ;no of bit to tx
movwf scrtch0
main61 rlf scrtch2, f ;check msb
rlf scrtch1, f
btfsc STATUS, C ;data hi if cy=1 else lo
goto main62
data_lo
goto main63
main62 data_hi
main63 nop ;delay
nop
clk_hi ;toggle clk to push data
nop
nop
clk_lo
nop
nop
decfsz scrtch0, f ;next bit
goto main61
strobe_hi ;strobe data nop
nop
strobe_lo
data_lo ;leave data lo
goto main
end
; ************* EOF MAIN.ASM ********************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -