基于单片机的时钟调整系统Word文档下载推荐.docx
- 文档编号:18579429
- 上传时间:2022-12-28
- 格式:DOCX
- 页数:18
- 大小:197.25KB
基于单片机的时钟调整系统Word文档下载推荐.docx
《基于单片机的时钟调整系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《基于单片机的时钟调整系统Word文档下载推荐.docx(18页珍藏版)》请在冰豆网上搜索。
4、显示子程序
显示由MAX7219驱动的六位显示器和点阵LED显示器共同完成,首先对其进行初始化,然后用单片机控制显示器显示。
MAX7219驱动器显示流程图
图2显示子程序
5、定时器T0中断服务程序
定时溢出中断周期设为50MS,中断进入后先进行定时中断初值校正,当中断累加到20次时,对秒计数单元进行加1操作。
时钟最大计时值为23时59分59秒。
在计数单元中,采用十进制BCD码计数,满十进位。
流程图如图3所示
在程序中采用12MHZ晶振频率,精度为1MS,定时初值为50MS,用循环程序进行20次循环可到1S。
当1S到时调用加1程序并判断秒、分是否为60,当秒为60时,秒清零,分加1;
当分为60时,分清零。
当时满24时,星期加1,时清零,星期由1至7循环。
终端结束时,计时单元数据移入对应显示单元。
三、按键设置
本时钟设置P1.0,P1.1,P1.2接3个按钮开关,用于调时。
其中P1.0用于选择调时模式(对星期,小时,分钟,秒的选择),P1.1完成对所选的项目进行增一的操作,P1.2完成对所选项目进行减一的操作。
四、程序
KEY1BITP1.0
KEY2BITP1.1
KEY3BITP1.2
CLKBITP1.3
LOADBITP1.4
DINBITP1.5
SECONDDATA30H
MINUTEDATA31H
HOURDATA32H
DAYDATA33H
ORG0000H
AJMPMAIN
ORG000BH
AJMPTIMER0
MAIN:
MOVSP,#60H
MOVTMOD,#01H
MOVTH0,#0B1H
MOVTL0,#0E0H
SETBET0
SETBEA
MOVR2,#50
SETBTR0
MOVSECOND,#00H
MOVMINUTE,#00H
MOVHOUR,#00H
MOVDAY,#00H
MOVA,HOUR
ANLA,#0F0H
SWAPA
MOV79H,A
ANLA,#0FH
MOV7AH,A
MOVA,MINUTE
MOV7BH,A
MOVA,MINUTE
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OND,#00H
ADDA,#01
S2:
CJNEA,#24H,NEXT
S3:
MOVHOUR,#00H
MOVA,DAY
ADDA,#01H
MOVDAY,A
CJNEA,#07H,NEXT
MOVDAY,#00H
NEXT:
POPPSW
POPACC
RETI
DTAB:
DB00H,08H,08H,08H,08H,08H,08H,00H
DB00H,04H,24H,24H,24H,24H,04H,00H
DB00H,02H,52H,52H,52H,52H,02H,00H
DB00H,0FFH,91H,0F1H,81H,0F1H,91H,0FFH
DB91H,91H,91H,0FFH,91H,91H,9FH,01H
DB20H,22H,24H,0A8H,60H,28H,24H,22H
DB00H,00H,0FFH,91H,91H,0FFH,00H,00H
END
五、运用Proteus进行仿真
1、正常状态下的时钟显示
6、按一次KEY1对时进行调整
3、按两次KEY1对分进行调整
4、按三次KEY1对秒进行调整
5、按四次KEY1进入关机
6、按五次KEY1返回正常显示模式
操作模式
KEY1次数
1
2
3
4
5
调整模式
调秒
调分
调时
调星期
正常显示
设计说明及建议:
本设计特点在于同时采用由MAX7219驱动六位LED显示器和点阵LED显示器,利用前者的设计程序简便性和后者的显示的多样性以达到理想效果。
参考文献:
【1】赵嘉蔚,张家栋,霍凯,肖燕彩.单片机原理及接口技术【M】.清华大学出版社2010
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 单片机 时钟 调整 系统