|
include "p16f877A.inc"
;************************************************
__CONFIG B'011000001100010';
pcl equ 02h
status equ 3h
z equ 2h
intcon equ 0bh
porta equ 5h
trisa equ 85h
portd equ 8h
trisd equ 88h
count equ 29h
count1 equ 2ah
rp0 equ 5h
tmr1l equ 0eh
tmr1h equ 0fh
pir1 equ 0ch
pie1 equ 8ch
t1con equ 10h
tmr1lb equ 0xdc
tmr1hb equ 0x0b
second equ 30h
second1 equ 31h
minute equ 32h
minute1 equ 33h
hour equ 34h
hour1 equ 35h
org 0000h
nop
goto main
org 0004h
;***********TMR1延时子程序0。25S*************
bcf pir1,0
bcf t1con,0
movlw tmr1lb
movwf tmr1l
movlw tmr1hb
movwf tmr1h
bsf t1con,0
;open interrput
incf count1,1
movlw 0x02
subwf count1,0
btfsc status,z
goto sec1
goto exit
;two times
hou clrf hour1
goto Display
hou2 incf hour,1
movf count,0
subwf hour,0
btfsc status,z
goto hou
goto exit
hou1 clrf minute
incf hour1,1
movf count,0
subwf hour1,0
btfsc status,z
goto hou2
goto exit
;hour hand
min2 clrf minute1
incf minute,1
movf count,0
subwf minute,0
btfsc status,z
goto hou1
goto exit
min1 clrf second
incf minute1,1
movf count,0
subwf minute1,0
btfsc status,z
goto min2
goto exit
;minute hand
sec2 clrf second1
incf second,1
movf count,0
subwf second,0
btfsc status,z
goto min1
goto exit
sec1 clrf count1
incf second1,1
movf count,0
subwf second1,0
btfsc status,z
goto sec2
exit retfie
;**************主程序***************
main bsf status,rp0
movlw 0x00
movwf trisa
movwf trisd
bsf pie1,0
bcf status,rp0
movlw 0x0
movwf second1
movwf second
movwf minute1
movwf minute
movwf hour1
movwf hour
movwf count1
movlw 0x0a
movwf count
movlw 0x34
movwf t1con
movlw 0xc0
movwf intcon
movlw tmr1lb
movwf tmr1l
movlw tmr1hb
movwf tmr1h
bsf t1con,0
;*********Display*****************
Display movf hour,0
call numb
movwf portd
movlw 0x20
movwf porta
call delay
;顶位数显示
movf hour1,0
call numb
movwf portd
movlw 0x10
movwf porta
call delay
;万位数显示
movf minute,0
call numb
movwf portd
movlw 0x08
movwf porta
call delay
;千位数显示
movf minute1,0
call numb
movwf portd
movlw 0x04
movwf porta
call delay
;百位数显示
movf second,0
call numb
movwf portd
movlw 0x02
movwf porta
call delay
;十位数显示
movf second1,0
call numb
movwf portd
movlw 0x01
movwf porta
call delay
;个位数显示
goto Display
;*********************************************
;秒针+1
;-------------------------廷时子程序----------------------------
delay ;子程序名,也是子程序入口地址
movlw 0x04 ;将外层循环参数值FFH经过W
movwf 20h ;送入用作外循环变量的20H单元
lp0 movlw 0xff ;将第二层循环参数值FFH经过W
movwf 21h ;送入用作内循环变量的21H单元
lp1 movlw 0x08 ;将内层循环参数值FFH经过W
decfsz 21h,1 ;变量21H内容递减,若为0跳跃
goto lp1 ;跳跃到LP1处
decfsz 20h,1 ;变量20H内容递减,若为0跳跃
goto lp0 ;跳跃到LP0处
retlw 0 ;返回主程序
;**********读取显示信息的查表子程序*******
numb addwf pcl,1
retlw 0x3f
retlw 0x06
retlw 0x5b
retlw 0x4f
retlw 0x66
retlw 0x6d
retlw 0x7d
retlw 0x07
retlw 0x7f
retlw 0x6f
end ;源程序结束
此内容由EEWORLD论坛网友windirection原创,如需转载或用于商业用途需征得作者同意并注明出处
|
|