单片机万年历.docx
- 文档编号:9326735
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:42
- 大小:161.42KB
单片机万年历.docx
《单片机万年历.docx》由会员分享,可在线阅读,更多相关《单片机万年历.docx(42页珍藏版)》请在冰豆网上搜索。
单片机万年历
一、设计要求
1.具有年、月、日、星期、时、分、秒等功能;
2.时间与阴、阳历能够自动关联;
3.具备年、月、日、星期、时、分、秒校准功能
二、电路设计框图
MCS51单片机
三、程序流程框图
图-A主程序流程图
图-B计算阳历程序流程图
图-C时间调整程序流程图
图-D阴历程序流程图
四、电路模块说明
1.时钟电路
时钟系统是单片机的心脏,在本次设计中,包括中央处理器在内的所有单片机都是时钟系统所提供的节拍工作的。
时钟电路由外接谐振器的时钟振荡器、时钟发生器及关断控制信号等组成。
时钟振荡器是单片机的时钟源,时钟发生器对振荡器的输出信号进行二分频。
利用单片机内部的定时功能来实现时钟的走时,通过编程实现每50毫秒产生一次中断,中断20次后,秒单元加1,秒单元加到60时,跳回到零再继续加,同时分单元加1。
以次类推,从而实现秒、分、小时、年的走时。
2.复位电路
复位是指在规定的条件下,单片机自动将CPU以及与程序运行相关的主要功能部件、I/O口等设置为确定初始状态的过程。
如果电路参数不符合规定的条件或干扰导致单片机不能正确的复位,系统将无法进行正常的工作。
3.按键电路
每个键单独占有一根I/O接口线,每个I/O口的工作状态互不影响,此类键盘采用端口直接扫描方式。
但是当按键较多时占用单片机的I/O数目较多。
4.显示电路
这种工作方式是分时轮流选通数码管的公共端,使得各个数码管轮流导通。
当所有数码管依次显示一遍后,软件控制循环,使每位显示器分时点亮。
这种方式不但能提高数码管的发光效率,并且由于各个数码管的字段线是并联使用的,因而大大简化了硬件线路。
各个数码管虽然是分时轮流通电,但由于发光数码管具有余辉特性及人眼具有视觉暂留作用,所以适当选取循环扫描频率时,看上去所有数码管是同时点亮的,察觉不出有闪烁现象。
5.电源电路
220V交流电通过电源变压器变换成交流12V低压,再经过桥式整流电路和滤波电容2200uf的整流和滤波。
五、程序清单
CONFIG12EQU7FH
TEMPHEQU21H
TEMPLEQU20H
REG2EQU22H
REG3EQU23H
REG4EQU24H
DATEQUP0.7
SCLKEQUP3.2
IOEQUP3.3
RSTEQUP3.4
yearDATA66H
monthDATA65H
weekDATA64H
dayDATA63H
hourDATA62H
mintueDATA61H
secondDATA60H
ORG0000H
LJMPSTART
ORG001BH
LJMPINTT1
START:
;初值
LCALLZJ
SETBEA
MOVSCON,#00H;串行输出,方式0
MOVTMOD,#10H;计数器1,方式1
MOVTL1,#00H
MOVTH1,#00H
MOV32H,#8EH
MOV31H,#00H;允许写1302
LCALLWRITE
MOV32H,#90H
MOV31H,#0A6H;1302充电,充电电流1.1MA
LCALLWRITE
;主程序~~~~~~~~~~~~~~~~~~~~~
MAIN1:
MOV32H,#8DH;读出年
LCALLREAD
MOVyear,31H
MOV32H,#8BH;读出星期
LCALLREAD
MOVweek,31H
MOV32H,#89H;读出月
LCALLREAD
MOVmonth,31H
MOV32H,#87H;读出日
LCALLREAD
MOVday,31H
MOV32H,#85H;读出小时
LCALLREAD
MOVhour,31H
MOV32H,#83H;读出分钟
LCALLREAD
MOVmintue,31H
MOV32H,#81H;读出秒
LCALLREAD
MOVsecond,31H
;~~~~~~~~~~~~分离缓存~~~~~~~~
MOVR0,year;年分离,送显示缓存
LCALLDIVIDE
MOV7BH,R1
MOV4BH,R1
MOV7CH,R2
MOV4CH,R2
MOV78H,week
MOV48H,week
MOVR0,month;月分离,送显示缓存
LCALLDIVIDE
MOV79H,R1
MOV49H,R1
MOV7AH,R2
MOV4AH,R2
MOVR0,day;日分离,送显示缓存
LCALLDIVIDE
MOV76H,R1
MOV46H,R1
MOV77H,R2
MOV47H,R2
MOVR0,hour;小时分离,送显示缓存
LCALLDIVIDE
MOV74H,R1
MOV44H,R1
MOV75H,R2
MOV45H,R2
MOVR0,mintue;分钟分离,送显示缓存
LCALLDIVIDE
MOV72H,R1
MOV42H,R1
MOV73H,R2
MOV43H,R2
MOVR0,second;秒分离,送显示缓存
LCALLDIVIDE
MOV70H,R1
MOV40H,R1
MOV71H,R2
MOV41H,R2
CLREA
LCALLTOUTOU
SETBEA
LCALLDISPLAY
LCALLGENGXIAN;更新农历程序
JNBP0.1,SETG111
JNBF0,SSS
setbP0.4;非闰月,则p0.4清零,指示灯亮
LJMPMAIN1
SETG111:
LJMPSETG
SSS:
clrP0.4;闰月,则p0.4置位,指示灯不亮
LJMPMAIN1
;~~~~~~~~~~~~~~温度
TOUTOU:
LCALLCHUSHI
LCALLRDTEMP
MOVA,TEMPL
ANLA,#11110000B
MOVTEMPL,A
MOVA,TEMPH
ANLA,#00000111B
ORLA,TEMPL
SWAPA
MOV25H,A
MOVA,25H
MOVB,#64H
DIVAB
MOVA,B
MOVB,#0AH
DIVAB
SWAPA
ORLA,B
MOV10H,A
RET
CHUSHI:
LCALLRESET
MOVA,#0CCH
LCALLWRITE111
MOVA,#4EH
LCALLWRITE111
MOVA,#CONFIG12
LCALLWRITE111
RET
RDTEMP:
LCALLRESET
MOVA,#0CCH
LCALLWRITE111
MOVA,#44H
LCALLWRITE111
LCALLDL1MS
LCALLRESET
MOVA,#0CCH
LCALLWRITE111
MOVA,#0BEH
LCALLWRITE111
LCALLERAD111
MOVTEMPL,A
LCALLERAD111
MOVTEMPH,A
RET
RESET:
LA:
SETBDAT
MOV52H,#200
LB:
CLRDAT
DJNZ52H,LB
SETBDAT
MOV52H,#30
LC:
DJNZ52H,LC
CLRC
ORLC,DAT
JCLB
MOV58H,#80
LD:
ORLC,DAT
JCLP
DJNZ58H,LD
SJMPLA
LP:
MOV52H,#250
LF:
DJNZ52H,LF
RET
WRITE111:
MOV53H,#8
W51HA:
SETBDAT
MOV54H,#8
RRCA
CLRDAT
W52HA:
DJNZ54H,W52HA
MOVDAT,C
MOV54H,#30
W53HA:
DJNZ54H,W53HA
DJNZ53H,W51HA
SETBDAT
RET
ERAD111:
CLREA
MOV58H,#8
RD1A:
CLRDAT
MOV54H,#6
NOP
SETBDAT
RD2A:
DJNZ54H,RD2A
MOVC,DAT
RRCA
MOV55H,#30
RD3A:
DJNZ55H,RD3A
DJNZ58H,RD1A
SETBDAT
RET
;公历设置程序~~~~~~~~~~~~~~~~~~~~~
SETG:
SETBTR1
SETBET1
MOV32H,#8EH
MOV31H,#00H;允许写1302
LCALLWRITE
MOV32H,#80H
MOV31H,#80H;1302停止振荡
LCALLWRITE
GWAIT:
;~~~~~~~~~~~~~~~~~~
LCALLDISPLAY
JNBP0.1,GWAIT
SETG1:
LCALLDISPLAY
JNBP0.1,SETG2
JNBP0.2,GADDYEAR
JNBP0.3,JIANYEAR
AJMPSETG1
GADDYEAR:
MOVR7,66H;年加一
LCALLADD1
MOV66H,A
CJNEA,#51H,GADDYEAR1
MOV66H,#00H
AJMPGADDYEAR1
JIANYEAR:
MOVR7,66H;年减一
LCALLJIAN1
MOV66H,A
CJNEA,#00H,GADDYEAR1
MOV66H,#51H
GADDYEAR1:
MOV32H,#8CH;年值送人1302
MOV31H,66H
LCALLWRITE
MOVR0,66H
LCALLDIVIDE;年分离送显示缓存
MOV4BH,R1
MOV7BH,R1
MOV4CH,R2
MOV7CH,R2
WAITT1:
;~~~~~~~~~~~~~~~~
LCALLDISPLAY
JNBP0.2,WAITT1
JNBP0.3,WAITT1
AJMPSETG1
SETG2:
SETB0AH;调月时闪标志
GWAIT2:
LCALLDISPLAY
JNBP0.1,GWAIT2
SETG3:
LCALLDISPLAY
JNBP0.1,SETG4
JNBP0.2,GADDMONTH
JNBP0.3,JIANMONTH
AJMPSETG3
GADDMONTH:
MOVR7,65H;月加一
LCALLADD1
MOV65H,A
CJNEA,#13H,GADDMONTH1
MOV65H,#01H
AJMPGADDMONTH1
JIANMONTH:
MOVR7,65H;月减一
LCALLJIAN1
MOV65H,A
CJNEA,#00H,GADDMONTH1
MOV65H,#12H
GADDMONTH1:
MOV32H,#88H;月值送人1302
MOV31H,65H
LCALLWRITE
MOVR0,65H
LCALLDIVIDE;月分离,送显示缓存
MOV79H,R1
MOV49H,R1
MOV7AH,R2
MOV4AH,R2
WAITT2:
;~~~~~~~~~~~~~~~~~~~~
LCALLDISPLAY
JNBP0.2,WAITT2
JNBP0.3,WAITT2
AJMPSETG3
SETG4:
SETB0BH;调日时闪标志
GWAIT4:
LCALLDISPLAY
JNBP0.1,GWAIT4
SETG5:
LCALLDISPLAY
JNBP0.1,SETG6
JNBP0.2,GADDDAY
JNBP0.3,JIANDAY
AJMPSETG5
GADDDAY:
MOVR7,63H;日加一
LCALLADD1
MOV63H,A
CJNEA,#32H,GADDDAY1
MOV63H,#01H
JIANDAY:
MOVR7,63H;日减一
LCALLJIAN1
MOV63H,A
CJNEA,#00H,GADDDAY1
MOV63H,#31H
GADDDAY1:
MOV32H,#86H;日值送人1302
MOV31H,63H
LCALLWRITE
MOVR0,63H
LCALLDIVIDE;日分离,送显示缓存
MOV76H,R1
MOV46H,R1
MOV77H,R2
MOV47H,R2
WAITT3:
;~~~~~~~~~~~~~~~~~
LCALLDISPLAY
JNBP0.2,WAITT3
JNBP0.3,WAITT3
AJMPSETG5
SETG6:
SETB0CH;调星期时闪标志
GWAIT6:
LCALLDISPLAY
JNBP0.1,GWAIT6
SETG7:
LCALLDISPLAY
JNBP0.1,SETG8
JNBP0.2,GADDWEEK
JNBP0.3,JIANWEEK
AJMPSETG7
GADDWEEK:
MOVR7,64H;星期加一
LCALLADD1
MOV64H,A
CJNEA,#07H,GADDWEEK1
MOV64H,#00H
AJMPGADDWEEK1
JIANWEEK:
MOVR7,64H;星期减一
LCALLJIAN1
MOV64H,A
CJNEA,#00H,GADDWEEK1
MOV64H,#06H
GADDWEEK1:
MOV32H,#8AH
MOV31H,64H;星期值送人1302
LCALLWRITE
MOVR0,64H
LCALLDIVIDE;星期值分离送显示缓存
MOV48H,R1
MOV78H,R1
WAITT4:
;~~~~~~~~~~~~~~~~~~~~
LCALLDISPLAY
JNBP0.2,WAITT4
JNBP0.3,WAITT4
AJMPSETG7
SETG8:
SETB0DH;调小时时闪标志
GWAIT8:
LCALLDISPLAY
JNBP0.1,GWAIT8
SETG9:
LCALLDISPLAY
JNBP0.1,SETG10
JNBP0.2,GADDHOUR
JNBP0.3,JIANHOUR
AJMPSETG9
GADDHOUR:
MOVR7,62H;小时加一
LCALLADD1
MOV62H,A
CJNEA,#24H,GADDHOUR1
MOV62H,#00H
AJMPGADDHOUR1
JIANHOUR:
MOVR7,62H;小时减一
LCALLJIAN1
MOV62H,A
CJNEA,#00H,GADDHOUR1
MOV62H,#23H
GADDHOUR1:
MOV32H,#84H;小时值送人1302
MOV31H,62H
LCALLWRITE
MOVR0,62H
LCALLDIVIDE;小时值分离送显示缓存
MOV74H,R1
MOV44H,R1
MOV75H,R2
MOV45H,R2
WAITT5:
;~~~~~~~~~~~~~~~~~~~~~~~~~
LCALLDISPLAY
JNBP0.2,WAITT5
JNBP0.3,WAITT5
AJMPSETG9
SETG10:
SETB0EH;调分时候闪标志
GWAIT10:
LCALLDISPLAY
JNBP0.1,GWAIT10
SETG11:
LCALLDISPLAY
JNBP0.1,SETGOUT
JNBP0.2,GADDMINTUE
JNBP0.3,JIANMINTUE
AJMPSETG11
GADDMINTUE:
MOVR7,61H;分钟加一
LCALLADD1
MOV61H,A
CJNEA,#60H,GADDMINTUE1
MOV61H,#00H
AJMPGADDMINTUE1
JIANMINTUE:
MOVR7,61H;分钟减一
LCALLJIAN1
MOV61H,A
CJNEA,#00H,GADDMINTUE1
MOV61H,#59H
GADDMINTUE1:
MOV32H,#82H;分钟值送人1302
MOV31H,61H
LCALLWRITE
MOVR0,61H
LCALLDIVIDE;分钟值分离送显示缓存
MOV72H,R1
MOV42H,R1
MOV73H,R2
MOV43H,R2
WAITT6:
LCALLDISPLAY
JNBP0.2,WAITT6
JNBP0.3,WAITT6
AJMPSETG11
SETGOUT:
LCALLDISPLAY
JNBP0.1,SETGOUT
LCALLGENGXIAN
MOV32H,#80H
MOV31H,#00H;1302晶振开始振荡
LCALLWRITE
MOV32H,#8EH
MOV31H,#80H;禁止写入1302
LCALLWRITE
CLR08H
CLR09H
CLR0AH
CLR0BH
CLR0CH
CLR0DH
CLR0EH
CLR0FH
CLRET1;关闪中断
CLRTR1
LJMPMAIN1
;;闪动调时程序~~~~~~~~~~~~~~~~
INTT1:
PUSHACC
PUSHPSW
GFLASH:
CPL0FH
JB0FH,GFLASH1
MOV7CH,4CH;全部显示
MOV7BH,4BH
MOV7AH,4AH
MOV79H,49H
MOV78H,48H
MOV77H,47H
MOV76H,46H
MOV75H,45H
MOV74H,44H
MOV73H,43H
MOV72H,42H
MOV71H,41H
MOV70H,40H
GFLASHOUT:
POPPSW
POPACC
RETI
GFLASH1:
JB0AH,GFLASH2;调年闪
MOV7CH,#0FH
MOV7BH,#0FH
AJMPGFLASHOUT
GFLASH2:
JB0BH,GFLASH3;调月闪
MOV7AH,#0FH
MOV79H,#0FH
AJMPGFLASHOUT
GFLASH3:
JB0CH,GFLASH4;调日闪
MOV77H,#0FH
MOV76H,#0FH
AJMPGFLASHOUT
GFLASH4:
JB0DH,GFLASH5;调星期闪
MOV78H,#0FH
AJMPGFLASHOUT
GFLASH5:
JB0EH,GFLASH6;调小时闪
MOV75H,#0FH
MOV74H,#0FH
AJMPGFLASHOUT
GFLASH6:
MOV73H,#0FH;调分钟闪
MOV72H,#0FH
AJMPGFLASHOUT
;加一程序~~~~~~~~~~~~~~~~~~~~~~~~~
ADD1:
MOVA,R7
ADDA,#1
DAA
RET
;减一程序~~~~~~~~~~~~~~~~~~~~~~~~~
JIAN1:
MOVA,R7
DECA
CJNEA,#4FH,KK1
MOVA,#49H
KK1:
CJNEA,#3FH,KK2
MOVA,#39H
KK2:
CJNEA,#2FH,KK3
MOVA,#29H
KK3:
CJNEA,#1FH,KK4
MOVA,#19H
KK4:
CJNEA,#0FH,KK5
MOVA,#09H
KK5:
RET
;分离程序~~~~~~~~~~~~~~~~~~~~~~~~~
DIVIDE:
MOVA,R0
ANLA,#0FH
MOVR1,A
MOVA,R0
SWAPA
ANLA,#0FH
MOVR2,A
RET
;写1302程序~~~~~~~~~~~~~~~~~~~~~~~~~~
WRITE:
CLRSCLK
NOP
SETBRST
NOP
MOVA,32H
MOVR4,#8
WRITE1:
RRCA;送地址给1302
NOP
NOP
CLRSCLK
NOP
NOP
NOP
MOVIO,C
NOP
NOP
NOP
SETBSCLK
NOP
NOP
DJNZR4,WRITE1
CLRSCLK
NOP
MOVA,31H
MOVR4,#8
WRITE2:
RRCA
NOP;送数据给1302
CLRSCLK
NOP
NOP
MOVIO,C
NOP
NOP
NOP
SETBSCLK
NOP
NOP
DJNZR4,WRITE2
CLRRST
RET
;读1302程序~~~~~~~~~~~~~~~~~~~~~~~~~
READ:
CLRSCLK
NOP
NOP
SETBRST
NOP
MOVA,32H
MOVR4,#8
READ1:
RRCA;送地址给1302
NOP
MOVIO,C
NOP
NOP
NOP
SETBSCLK
NOP
NOP
NOP
CLRSCLK
NOP
NOP
DJNZR4,READ1
MOVR4,#8
READ2:
CLRSCLK
NOP
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 万年历