微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 4位数码管电子时钟(冒号为秒闪烁)

4位数码管电子时钟(冒号为秒闪烁)

时间:11-29 来源:互联网 点击:

org 0000h

ajmp main

org 000bh

ljmp inti0

org 0030h

main: mov ie,#82h

mov tmod,#01h

mov th0,#4ch

mov tl0,#00h

mov 31h,#00

mov 32h,#00

mov 33h,#00

mov sp,#60h

setb tr0

loop:lcall display

lcall keyer

ajmp loop

display: mov a,31h ;秒显示

mov b,#10

div ab

mov 20h,a

mov 21h,b

disp1: mov a,20h ;秒十位显示

mov dptr,#table

movc a,@a+dptr

mov p0,a

clr p2.0

lcall del1ms

setb p2.0

disp2: mov a,21h ;秒个位显示

mov dptr,#table

movc a,@a+dptr

mov p0,a

clr p2.1

lcall del1ms

setb p2.1

disp3: mov a,32h ;分显示

mov b,#10

div ab

mov 22h,a

mov 23h,b

disp4: mov a,22h ;分十位显示

mov dptr,#table

movc a,@a+dptr

mov p0,a

clr p2.6

lcall del1ms

setb p2.6

disp5: mov a,23h ;分个位显示

mov dptr,#table

movc a,@a+dptr

mov p0,a

clr p2.7

lcall del1ms

setb p2.7

disp6: mov a,33h ;时显示

mov b,#10

div ab

mov 24h,a

mov 25h,b

disp7: mov a,24h ;时十位显示

mov dptr,#table

movc a,@a+dptr

mov p0,a

clr p2.4

lcall del1ms

setb p2.4

disp8: mov a,25h ;时个位显示

mov dptr,#table

movc a,@a+dptr

mov p0,a

clr p2.5

lcall del1ms

setb p2.5

ret

inti0:push acc

push psw

clr ea

mov th0,4ch

mov tl0,#00h

inc 3ah

mov a,3ah

cjne a,#40,out

mov 3ah,#00

cpl p2.2

inc 31h ;秒加1

mov a,31h

cjne a,#60,out

mov 31h,#00

inc 32h ;分加1

mov a,32h

cjne a,#60,out

mov 32h,#00

inc 33h ;时加1

mov a,33h

cjne a,#24,out

mov 33h,#00

out:setb ea

pop psw

pop acc

reti

table: db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h

del1ms: mov r7,#10

del1:mov r6,#50

del2:djnz r6,del2

djnz r7,del1

ret

del20ms:mov r5,#40

del3:mov r4,#250

del4:djnz r4,del4

djnz r5,del3

ret

keyer:jnb p3.2,key1 ;分加1按钮

jnb p3.3,key2 ;时加1按钮

sjmp keyout

key1:lcall del20ms

jb p3.2,keyout

jnb p3.2,$

inc 32h ;分加1

mov a,32h

cjne a,#60,keyout

mov 32h,#00

sjmp keyout

key2:lcall del20ms

jb p3.3,keyout

jnb p3.3,$

inc 33h ;时加1

mov a,33h

cjne a,#24,keyout

mov 33h,#00

sjmp keyout

keyout:ret

end

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top