基于AT89S52单片机的数字电子钟程序.docx
- 文档编号:2386351
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:16
- 大小:17.13KB
基于AT89S52单片机的数字电子钟程序.docx
《基于AT89S52单片机的数字电子钟程序.docx》由会员分享,可在线阅读,更多相关《基于AT89S52单片机的数字电子钟程序.docx(16页珍藏版)》请在冰豆网上搜索。
基于AT89S52单片机的数字电子钟程序
基于AT89S52单片机的数字电子钟程序可以实现控制家用电器,如热水器等HOUREQU030H;小时缓存
MINUTEEQU031H;分钟缓存
SECONDEQU032H;秒缓存
D1HOUREQU033H;定时1小时缓存
D1MINUTEEQU034H;定时1分钟缓存
D2HOUREQU035H;定时2小时缓存
D2MINUTEEQU036H;定时2分钟缓存
AJBZEQU037H;按键次数标志
COUNT1EQU038H;总计数到4000:
拆分成40*100总计数1COUNT2EQU039H;总计数到4000:
拆分成40*100总计数2SPLEQU020H;闪烁判断的依据
TSPLEQU021H;定时计数器闪烁时间信号标志
SET_BTNEQU022H;标志位
DSBZEQU023H;定时开关标志
ORG0000H;程序入口地址
AJMPMAIN;跳转到主程序执行
ORG001BH;定时计数器1中断入口地址
AJMPIT_1;跳转到低定时计数器1中断服务程序
ORG040H;主程序入口地址
MAIN:
MOVSPL,#00H;闪烁标志清零
MOVDPTR,#TABLE;码段首地址存放到数据指针
MOVHOUR,#00H;小时缓存清零
MOVMINUTE,#00H;分缓存清零
MOVSECOND,#00H;秒缓存清零
MOVD1HOUR,#00H;定时1小时缓存清零
MOVD1MINUTE,#00H;定时1分钟缓存清零
MOVD2HOUR,#00H;定时2小时缓存清零
MOVD2MINUTE,#00H;定时2分钟缓存清零
MOVAJBZ,#00H;按键次数缓存清零
MOVCOUNT1,#00H;总计数1清零
MOVCOUNT2,#00H;总计数2清零
MOVDSBZ,#00H;定时开关标志清零
CLRP3.1
MOVTMOD,#20H;设置计数方式
MOVTH1,#06H;定时计数器T1高八位初值
MOVTL1,#06H;定时计数器低八位初值
MOVIE,#10001000B;设置允许中断,并且打开两个定时器
SETBTR1;打开定时计数器T1
LOOP:
JNBP0.0,JUST_TIME
JBSET_BTN.0,JUST_TIME;标志位为1跳转
JNBP0.1,SUBB_TIME;减操作
JBSET_BTN.1,SUBB_TIME
JNBP0.2,ADD_TIME;加操作
JBSET_BTN.2,ADD_TIME
JBP0.3,TIME
CLRP3.1
TIME1:
JBSPL.2,DS1XS;定时1显示
JBSPL.3,DS1XS
JBSPL.4,DS1XS
JBSPL.5,DS2XS;检测定时2是否显示
JBSPL.6,DS2XS
JBSPL.7,DS2XS
ACALLHOUR_SHOW;小时显示ACALLMINUTE_SHOW;分钟显示
ACALLSECOND_SHOW;秒显示
ACALLDS1BJ
ACALLDS2BJ
AJMPLOOP
DS1XS:
ACALLD1HOUR_SHOW;定时1显示ACALLD1MINUTE_SHOW
ACALLD1SECOND_SHOW
AJMPLOOP
DS2XS:
ACALLD2HOUR_SHOW;定时2显示ACALLD2MINUTE_SHOW
ACALLD2SECOND_SHOW
AJMPLOOP
JUST_TIME:
JBSET_BTN.0,WAIT_UP;为1跳
ACALLDELAY2;防抖
JBP0.0,TIME;P0.0为1跳转
SETBSET_BTN.0
MOVR1,AJBZ
CJNER1,#08H,INC1
MOVAJBZ,#00H
MOVSPL,#00H
LJMPTIME
WAIT_UP:
JNBP0.0,TIME
CLRSET_BTN.0
LJMPTIME
SUBB_TIME:
LJMPSUBB_TIME1
TIME:
LJMPTIME1
ADD_TIME:
LJMPADD_TIME1
INC1:
INCAJBZ
MOVR1,AJBZ
CJNER1,#01H,JSFZ;计时分钟
SETBSPL.0
LJMPTIME
JSFZ:
CJNER1,#02H,DS1X
CLRSPL.0
SETBSPL.1
LJMPTIME
DS1X:
CJNER1,#03H,DS1FZ
CLRSPL.1
SETBSPL.2
LJMPTIME
DS1FZ:
CJNER1,#04H,DS1KG
CLRSPL.2
SETBSPL.3
LJMPTIME
DS1KG:
CJNER1,#05H,DS2X
CLRSPL.3
SETBSPL.4
LJMPTIME
DS2X:
CJNER1,#06H,DS2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W_HRER
ACALLWAIT2_DL1
RET
HOUR_SHOW_HRER:
;小时显示SETBP2.6
CLRA
MOVA,HOUR
MOVB,#0AH
DIVAB;小时十位在A中,个位在B中
MOVCA,@A+DPTR
MOVP1,#00H;P1口控制显示数据,此时显示小时十位数据MOVP1,A
CLRP2.7;P2口控制位置(低电平有效;共阴显示
;延时
ACALLDELAY1
SETBP2.7;熄灭小时
MOVP1,#00H
MOVA,B;B中存放的小时各位数据放入A
MOVCA,@A+DPTR
MOVP1,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 AT89S52 单片机 数字 电子钟 程序