shi1 equ 41h//储存时1号位
shi2 equ 42h//时2号位
fen1 equ 43h//分1
fen2 equ 44h//分2
miao1 equ 45h//秒1
miao2 equ 46h//秒2
pp equ 48h//定时器
mm equ 49h//秒
ff equ 4ah//分
ss equ 4bh//时
dula equ p2.6//段选
wela equ p2.7//位选
org 0000h
jmp main
org 000bh
jmp time0interrupt1//定时器0,
org 0030h
main:
mov shi1,#01h//初始化
mov shi2,#02h
mov fen1,#00h
mov fen2,#00h
mov miao1,#00h
mov miao2,#00h
mov pp,#00h
mov ss,#0ch
mov ff,#00h
mov mm,#00h
mov TMOD,#01h;//模式1
mov TH0,#4ch;// 由于晶振为11.0592,故所记次数应为46080,计时器每隔50000微秒发起一次中断。
mov TL0,#00h;//46080的来历,为50000*11.0592/12
setb ET0;
setb EA;
setb TR0
disp:
shijia:jnb p2.0,xiaodou1
jmp fenjia
xiaodou1:lcall DELAY5MS
anxia1:jnb p2.0,anxia1
inc ss
fenjia:jnb p2.1,xiaodou2
jmp miaojia
xiaodou2:lcall DELAY5MS
anxia2:jnb p2.1,anxia2
inc ff
miaojia:jnb p2.2,xiaodou3
jmp disp2
xiaodou3:lcall DELAY5MS
anxia3:jnb p2.2,anxia3
inc mm
disp2:
lcall display//数码管驱动
mov a,pp
cjne a,#14h,disp//判断pp是否加了20次,即1s
mov pp,#00h//加到了,清零
miao: inc mm//秒+1
mov a,mm
cjne a,#3ch,go1//判断秒是否到60
mov mm,#00h//到了,秒清零,
jmp fen//且分加一
go1: jmp disp1//没到,直接显示
fen: inc ff//分加一
mov a,ff
cjne a,#3ch,go2
mov ff,#00h
jmp shi
go2: jmp disp1
shi: inc ss
mov a,ss
cjne a,#18h,go3//是否到24
mov ss,#00h
go3: jmp disp1
disp1: mov a,ss//时给a
mov b,#0ah//10给b
div ab//除
mov shi1,a//商给shi1
mov shi2,b//余数给shi2
mov a,ff
mov b,#0ah
div ab
mov fen1,a
mov fen2,b
mov a,mm
mov b,#0ah
div ab
mov miao1,a
mov miao2,b
jmp disp
//延时1ms
delay5: ;@11.0592MHz
DELAY1MS: ;@11.0592MHz
PUSH 30H
PUSH 31H
MOV 30H,#9
MOV 31H,#150
NEXT1MS:
DJNZ 31H,NEXT1MS
DJNZ 30H,NEXT1MS
POP 31H
POP 30H
RET
DELAY5MS: ;@11.0592MHz
NOP
NOP
PUSH 30H
PUSH 31H
MOV 30H,#44
MOV 31H,#2
NEXT:
DJNZ 31H,NEXT
DJNZ 30H,NEXT
POP 31H
POP 30H
RET
display://数码管显示若显示的数字缺胳膊少腿或三头六臂:我都有
//这种现象只存在于动态扫描情况下,称为鬼影。
//原因是扫描过快导致上一个字符(视觉暂留结果)显示在当前字符上产生重
//叠
//解决办法:增长延时,减慢扫描
//还有一种情况:
//若采用同时送段码和位码,则注意送段码前数据口要清零
MOV dptr,#smg //shi1,段选
mov a,shi1
MOVC A,@A+dptr
clr dula
mov P0,#00h;
setb dula;
mov P0,a;
clr dula;
clr wela; //时1位选
mov P0,#0feh;
setb wela;
clr wela;
lcall delay5;
mov a,shi2 //shi2
MOVC A,@A+dptr
mov P0,#00h;
setb dula;
mov P0,a;
clr dula;
mov P0,#0fdh;
setb wela;
clr wela;
lcall delay5;
mov P0,#00h; //-
setb dula;
mov P0,#01000000b;
clr dula;
mov P0,#0fbh;
;mov P0,#0ffh;
setb wela;
clr wela;
lcall delay5;
mov a,fen1 //fen1
MOVC A,@A+dptr
mov P0,#00h;
setb dula;
mov P0,a;
clr dula;
mov P0,#0f7h;
setb wela;
clr wela;
lcall delay5;
mov a,fen2 //fen2
MOVC A,@A+dptr
mov P0,#00h;
setb dula;
mov P0,a;
clr dula;
mov P0,#0efh;
setb wela;
clr wela;
lcall delay5;
mov P0,#00h;; //-
setb dula;
mov P0,#01000000b
clr dula;
mov P0,#0dfh;
;mov P0,#0ffh;
setb wela;
clr wela;
lcall delay5;
mov a,miao1 //miao1
MOVC A,@A+dptr
mov P0,#00h;
setb dula;
mov P0,a;
clr dula;
mov P0,#0bfh;
setb wela;
clr wela;
lcall delay5;
mov a,miao2 //miao2
MOVC A,@A+dptr
mov P0,#00h;
setb dula;
mov P0,a;
clr dula;
mov P0,#7fh;
setb wela;
clr wela;
lcall delay5;
RET
smg://从0到f的二进制
db 00111111b//0
db 00000110b//1
db 01011011b//2
db 01001111b//3
db 01100110b//4
db 01101101b//5
db 01111101b//6
db 00000111b//7
db 01111111b//8
db 01101111b//9
db 01110111b//a//+
db 01111100b//b//-
db 00111001b//c//*
db 01011110b//d//÷
db 01111001b//e//=
db 01110001b//f//清空
ret
time0interrupt1:
mov TH0,#4ch;// 由于晶振为11.0592,故所记次数应为46080,计时器每隔50000微秒发起一次中断。
mov TL0,#00h;//46080的来历,为50000*11.0592/12
inc pp
reti
end
|