数字钟单片机课程设计.docx
- 文档编号:6881227
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:32
- 大小:1.71MB
数字钟单片机课程设计.docx
《数字钟单片机课程设计.docx》由会员分享,可在线阅读,更多相关《数字钟单片机课程设计.docx(32页珍藏版)》请在冰豆网上搜索。
数字钟单片机课程设计
物电学院单片机课程设计报告
数字钟
姓名:
孙李涛
学号:
101103060
指导教师:
李艾华
成绩:
日 期:
2012.6.14
理工类样张(上边25mm,下边距25mm,左边距20mm,右边距20mm)
基于汇编语言的数字钟设计
摘要:
该数字钟利用AT89C51来设计数字钟,数字钟包括三功能,行列键盘校时、秒表、时钟。
校时时时钟和秒表均不工作,秒表工作时,时钟不显示但是继续走,到显示的时候能够准确的显示。
时钟工作时,秒表不工作。
关键词:
AT89C51、4*4独立行列式键盘、汇编、读键、键处理、数字钟、秒表
各功能单独实现
秒表
1、思路:
秒表跑秒的时候,时钟还在工作,所以秒表的存储器跟时钟的存储器不一样,虽然这里没有时分秒之说,但是为了与时钟的思路差不多所以就相当于时分秒了,时、分、秒分别放在“43h”、“44h”、“45h”,拆分后放在时的十位放在“75h”,时的个位放在“74h”;拆分后分的十位放在“73h”,分的个位放在“72h”;拆分后秒的十位放在“71h”,秒的个位放在“70h”。
将时的十位“75h”通过查询的方式查找到相应BCD七段码放在“85h”,将时的个位“74h”通过查询的方式查找到相应BCD七段码放在“84h”,将分的十位“73h”通过查询的方式查找到相应BCD七段码放在“83h”,将分的个位“72h”通过查询的方式查找到相应BCD七段码放在“82h”,将秒的十位“71h”通过查询的方式查找到相应BCD七段码放在“81h”,将秒的个位“70h”通过查询的方式查找到相应BCD七段码放在“80h”。
2、实现秒表的程序
org0000h
ljmpstart
org001bh
ljmpit1p
org1000h
start:
movtmod,#20h
mov62h,#40
mov43h,#0
mov44h,#0
mov45h,#0
setbet1
setbea
movth1,#6
movtl1,#6
setbtr1
abc2:
setbp3.4
jbp3.4,hold
jbp3.5,def2
mov43h,#0
mov44h,#0
mov45h,#0
setbea
def2:
lcallchaifen2
lcallzhuanhuan2
lcalldisp2
ljmpabc2
hold:
clrea
lcallchaifen2
lcallzhuanhuan2
lcalldisp2
ljmpabc2
it1p:
djnz62h,return
mov62h,#40
mova,#01h
adda,45h
daa
mov45h,a
cjnea,#100h,return
mov45h,#00h
mova,#01h
adda,44h
daa
mov44h,a
cjnea,#60h,return
mov44h,#00h
mova,#01h
adda,43h
daa
mov43h,a
cjnea,#60h,return
mov43h,#00h
return:
reti
chaifen2:
movr2,#3
movr0,#43h
movr1,#75h
loop4:
mova,@r0
anla,#0f0h
swapa
mov@r1,a
decr1
mova,@r0
anla,#0fh
mov@r1,a
decr1
incr0
djnzr2,loop4
ret
zhuanhuan2:
movr0,#70h
movr1,#80h
movr2,#6
dp102:
movdptr,#segtab
mova,@r0
movca,@a+dptr
mov@r1,a
incr1
incr0
djnzr2,dp102
ret
disp2:
movr0,#80h
movr7,#6
MOVR3,#0feh
loop22:
mova,#0ffh
movP1,a
mova,@r0
movp0,a
mova,r3
movp1,a
lcalldelay
rla
movr3,a
incr0
djnzr7,loop22
ret
delay:
movr4,#20
loop3:
movr5,#25
djnzr4,loop3
ret
segtab:
DB3FH,06H,5BH,4FH,66H,6DH
DB7DH,07H,7FH,6FH,77H,7CH
DB58H,5EH,7BH,71H,00H,40H
End
3、程序流程图
秒表主程序流程图秒表中断服务子程序it1p
4、仿真图
数字钟
1、思路:
时、分、秒分别放在“40h”、“41h”、“42h”,拆分后放在时的十位放在“35h”,时的个位放在“34h”;拆分后分的十位放在“33h”,分的个位放在“32h”;拆分后秒的十位放在“31h”,秒的个位放在“30h”。
将时的十位“35h”通过查询的方式查找到相应BCD七段码放在“55h”,将时的个位“34h”通过查询的方式查找到相应BCD七段码放在“54h”,将分的十位“33h”通过查询的方式查找到相应BCD七段码放在“53h”,将分的个位“32h”通过查询的方式查找到相应BCD七段码放在“52h”,将秒的十位“31h”通过查询的方式查找到相应BCD七段码放在“51h”,将秒的个位“30h”通过查询的方式查找到相应BCD七段码放在“50h”。
2、实现数字钟的程序
org0000h
ljmpstart
org000bh
ljmpit0p
org1000h
start:
movtmod,#02h
mov60h,#40
mov61h,#100
mov40h,#0
mov41h,#0
mov42h,#0
setbet0
setbea
movth0,#6
movtl0,#6
setbtr0
abc1:
lcallchaifen1
lcallzhuanhuan1
lcalldisp1
ljmpabc1
it0p:
pushacc
djnz61h,return
mov61h,#100
djnz60h,return
mov60h,#40
mova,#01h
adda,42h
daa
mov42h,a
cjnea,#60h,return
mov42h,#00h
mova,#01h
adda,41h
daa
mov41h,a
cjnea,#60h,return
mov41h,#00h
mova,#01h
adda,40h
daa
mov40h,a
cjnea,#24h,return
mov40h,#00h
return:
popacc
reti
chaifen1:
movr2,#3
movr0,#40h
movr1,#35h
loop41:
mova,@r0
anla,#0f0h
swapa
mov@r1,a
decr1
mova,@r0
anla,#0fh
mov@r1,a
decr1
incr0
djnzr2,loop41
ret
zhuanhuan1:
movr0,#30h
movr1,#50h
movr2,#6
dp101:
movdptr,#segtab
mova,@r0
movca,@a+dptr
mov@r1,a
incr1
incr0
djnzr2,dp101
ret
disp1:
movr0,#50h
movr7,#6
MOVR3,#0feh
loop21:
mova,#0ffh
movP1,a
mova,@r0
movp0,a
mova,r3
movp1,a
lcalldelay
rla
movr3,a
incr0
djnzr7,loop21
ret
delay:
movr4,#20
loop3:
movr5,#25
djnzr4,loop3
ret
segtab:
DB3FH,06H,5BH,4FH,66H,6DH
DB7DH,07H,7FH,6FH,77H,7CH
DB58H,5EH,7BH,71H,00H,40H
end
3程序流程图
时钟主程序流程图中断服务程序的流程
4、仿真图
行列式键盘校时
1、思路
一般情况下,校时是用来对数字钟的校对,所以行列式键盘校时用到的存储单元跟数字钟中的存储单元一样。
即要校对的数据:
时的十位放在“35h”,时的个位放在“34h”;分的十位放在“33h”,分的个位放在“32h”;秒的十位放在“31h”,秒的个位放在“30h”。
将时的十位“35h”通过查询的方式查找到相应BCD七段码放在“55h”,将时的个位“34h”通过查询的方式查找到相应BCD七段码放在“54h”,将分的十位“33h”通过查询的方式查找到相应BCD七段码放在“53h”,将分的个位“32h”通过查询的方式查找到相应BCD七段码放在“52h”,将秒的十位“31h”通过查询的方式查找到相应BCD七段码放在“51h”,将秒的个位“30h”通过查询的方式查找到相应BCD七段码放在“50h”。
2、实现校时的程序
3、程序流程图
DBUFEQU30H
TEMPEQU50H
ORG0000H
LJMPSTART
ORG0030h
START:
clrF0
mov40h,#0
mov41h,#0
mov42h,#0
ghi3:
lcallkey1
JNBF0,abc3
CLRF0
lcallshiftd
abc3:
lcallzhenghe
lcallzhuanhuan3
lcalldisp3
ljmpghi3
zhenghe:
movr2,#3
movr0,#40h
movr1,#35h
loop43:
mova,@r1
movb,#10h
mulab
mov21h,a
decr1
mova,@r1
adda,21h
mov@r0,a
decr1
incr0
djnzr2,loop43
ret
zhuanhuan3:
movr0,#30h
movr1,#50h
movr2,#6
dp103:
movdptr,#segtab
mova,@r0
movca,@a+dptr
mov@r1,a
incr1
incr0
djnzr2,dp103
ret
disp3:
movr0,#50h
movr7,#6
MOVR3,#0feh
loop23:
mova,#0ffh
movP1,a
mova,@r0
movp0,a
mova,r3
movp1,a
lcalldelay
rla
movr3,a
incr0
djnzr7,loop23
ret
SEGTAB:
DB3FH,06H,5BH,4FH,66H,6DH
DB7DH,07H,7FH,6FH,77H,7CH
DB58H,5EH,7BH,71H,00H,40H
shiftd:
movdbuf+5,dbuf+4
movdbuf+4,dbuf+3
movdbuf+3,dbuf+2
movdbuf+2,dbuf+1
movdbuf+1,dbuf
movdbuf,20H
ret
delay:
movr4,#100
loop3:
movr5,#100
djnzr4,loop3
ret
KEY1:
MOVP2,#0FH
MOVA,P2
ORLA,#0F0H
CPLA
JZEKEY
LCALLdisp3
LCALLdisp3
LCALLdisp3;
SKEY:
MOVA,#00
MOVR0,A
MOVR2,A
MOVR3,#0efH
SKEY2:
MOVA,R3
MOVP2,A
MOVA,P2
MOVR1,A
ORLA,#0F0H
CPLA
S123:
JNZSKEY3
INCR0
MOVA,R3
RlA
MOVR3,A
MOVA,R0
CJNEA,#04H,SKEY2
EKEY:
RET
SKEY3:
MOVA,R1
JNBACC.0,SKEY5
JNBACC.1,SKEY6
JNBACC.2,SKEY7
JNBACC.3,SKEY8
AJMPEKEY
SKEY5:
MOVA,#00H
MOVR2,A
AJMPDKEY
SKEY6:
MOVA,#01H
MOVR2,A
AJMPDKEY
SKEY7:
MOVA,#02H
MOVR2,A
AJMPDKEY
SKEY8:
MOVA,#03H
MOVR2,A
AJMPDKEY
DKEY:
MOVA,R0
MOVB,#04H
MULAB
ADDA,R2
SETBF0
MOV20H,A
EKEYD:
MOVP2,#0FH
MOVA,P2
ORLA,#0F0H
CPLA
JZEKEY
AJMPEKEYD
END
3、流程图
校时主程序shiftd子程序
行列式键盘校时子程序键值译码子程序
zhenghe子程序图
转换子程序流程图拆分子程序流程图显示子程序流程图
4、仿真图
综合实现时钟秒表校时
1、思路:
使用T1、T2中断来完成数字钟和秒表的计数,利用主程序来进行扫描显示,主程序中利用查询来控制校时、秒表和时钟,用到了p3.0、p3.1、p3.4、p3.5。
P3.0闭合,时钟和秒表工作,断开为校时。
p3.1断开,仅显示时钟,并断开秒表计数中断,p3.1闭合,显示秒表,但不关断数字钟。
P3.4、p3.5开控制秒表,同时为闭合时,秒表清零,先关断p3.5,秒表开始工作,从零开始计时,再关断p3.4秒表停止计时,但是显示会停留在那里,当p3.5与p3.4关断后就会又清零。
2、程序:
DBUFEQU30H
TEMPEQU50H
org0000h
ljmpstart
org000bh
ljmpit0p
org001bh
ljmpit1p
org0030h
start:
movtmod,#22h
mov60h,#40
mov61h,#100
mov62h,#40
mov43h,#0
mov44h,#0
mov45h,#0
setbet0
setbea
movth0,#6
movtl0,#6
setbtr0
setbet1
movth1,#6
movtl1,#6
setbtr1
xunhuan:
movp3,#0ffh
jbp3.0,jiaoshi
jbp3.1,shuzizhong
setbet1
lcallabc2
lcallxunhuan
jiaoshi:
lcallghi3
shuzizhong:
setbet0
clret1
ljmpabc1
abc1:
lcallchaifen1
lcallzhuanhuan1
lcalldisp1
ljmpxunhuan
abc2:
jbp3.4,hold
jbp3.5,def2
mov43h,#0
mov44h,#0
mov45h,#0
setbea
def2:
lcallchaifen2
lcallzhuanhuan2
lcalldisp2
jnbp3.1,abc2
ljmpxunhuan
hold:
clrea
lcallchaifen2
lcallzhuanhuan2
lcalldisp2
jnbp3.1,abc2
ljmpxunhuan
ghi3:
clret0
lcallkey1
JNBF0,abc3
CLRF0
lcallshiftd
abc3:
lcallzhenghe
lcallzhuanhuan3
lcalldisp3
jnbp3.0,xunhuan
ljmpghi3
zhenghe:
movr2,#3
movr0,#40h
movr1,#35h
loop43:
mova,@r1
movb,#10h
mulab
mov21h,a
decr1
mova,@r1
adda,21h
daa
mov@r0,a
decr1
incr0
djnzr2,loop43
ret
it0p:
pushacc
djnz61h,return
mov61h,#100
djnz60h,return
mov60h,#40
mova,#01h
adda,42h
daa
mov42h,a
cjnea,#60h,return
mov42h,#00h
mova,#01h
adda,41h
daa
mov41h,a
cjnea,#60h,return
mov41h,#00h
mova,#01h
adda,40h
daa
mov40h,a
cjnea,#24h,return
mov40h,#00h
return:
popacc
reti
it1p:
pushacc
djnz62h,return
mov62h,#40
mova,#01h
adda,45h
daa
mov45h,a
cjnea,#100h,return
mov45h,#00h
mova,#01h
adda,44h
daa
mov44h,a
cjnea,#60h,return
mov44h,#00h
mova,#01h
adda,43h
daa
mov43h,a
cjnea,#60h,return
mov43h,#00h
popacc
reti
chaifen1:
movr2,#3
movr0,#40h
movr1,#35h
loop41:
mova,@r0
anla,#0f0h
swapa
mov@r1,a
decr1
mova,@r0
anla,#0fh
mov@r1,a
decr1
incr0
djnzr2,loop41
ret
chaifen2:
movr2,#3
movr0,#43h
movr1,#75h
loop42:
mova,@r0
anla,#0f0h
swapa
mov@r1,a
decr1
mova,@r0
anla,#0fh
mov@r1,a
decr1
incr0
djnzr2,loop42
ret
zhuanhuan1:
movr0,#30h
movr1,#50h
movr2,#6
dp101:
movdptr,#segtab
mova,@r0
movca,@a+dptr
mov@r1,a
incr1
incr0
djnzr2,dp101
ret
zhuanhuan2:
movr0,#70h
movr1,#80h
movr2,#6
dp102:
movdptr,#segtab
mova,@r0
movca,@a+dptr
mov@r1,a
incr1
incr0
djnzr2,dp102
ret
zhuanhuan3:
movr0,#30h
movr1,#50h
movr2,#6
dp103:
movdptr,#segtab
mova,@r0
movca,@a+dptr
mov@r1,a
incr1
incr0
djnzr2,dp103
ret
disp1:
movr0,#50h
movr7,#6
MOVR3,#0feh
loop21:
mova,#0ffh
movP1,a
mova,@r0
movp0,a
mova,r3
movp1,a
lcalldelay
rla
movr3,a
incr0
djnzr7,loop21
ret
disp2:
movr0,#80h
movr7,#6
MOVR3,#0feh
loop22:
mova,#0ffh
movP1,a
mova,@r0
movp0,a
mova,r3
movp1,a
lcalldelay
rla
movr3,a
incr0
djnzr7,loop22
ret
disp3:
movr0,#50h
movr7,#6
MOVR3,#0feh
loop23:
mova,#0ffh
m
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字 单片机 课程设计