数字电子时钟设计报告Word格式文档下载.docx
《数字电子时钟设计报告Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《数字电子时钟设计报告Word格式文档下载.docx(32页珍藏版)》请在冰豆网上搜索。
![数字电子时钟设计报告Word格式文档下载.docx](https://file1.bdocx.com/fileroot1/2022-12/7/389ef2d9-7511-40de-a728-7f5f79c6c0b6/389ef2d9-7511-40de-a728-7f5f79c6c0b61.gif)
数码管
DI2
SR430563K
6
微动开关
K1-16
6*6*5
16
7
连接器
P1
HX8
8
P2
3.96
9
三极管
Q1-7
9012
10
电阻
R1-8、R17
510Ω
11
R9-16
12
IC座
IC40
13
IC
U1
AT89S51
14
晶振
Y1
6M
15
电路板
TEST.PCB
实验原理图:
四系统软件设计
1.数字时钟流程图:
2.数字时钟源程序
SUDAT00EQU40H;
加(减数)
SUDAT01EQU41H
SUDAT02EQU42H
SUDAT03EQU43H
SUDAT10EQU44H;
加(被减数)
SUDAT11EQU45H
SUDAT12EQU46H
SUDAT13EQU47H
DISPDAT0EQU29H;
显示数据区
DISPDAT1EQU2AH
DISPDAT2EQU2BH
DISPDAT3EQU2CH
DISPDAT4EQU2DH
DISPDAT5EQU2EH
DISPDAT6EQU2FH
DISPLONGEQU31H;
显示长度
DISPCONEQU32H;
显示计位
KEYDATEQU30H;
键码
HOURHEQU34H;
时间数据
HOURLEQU35H
MINHEQU36H
MINLEQU37H
EDMODEQU39H;
流水灯模式
SUCONEQU3AH;
输入计数
SUBITEQU20H.1;
减标示
DPEQU20H.2;
秒显标示
KEYBITEQU20H.3;
有键码标示
SUEQU20H.4;
计算标示
TIMEEQU20H.5;
时间标示TIMESETEQU20H.6;
时间设置标示
ORG0000H
AJMPSTART
ORG0003H
RETI
ORG000BH
AJMPTIME0
ORG0013H
ORG001BH
LJMPTIME1
ORG0023H
RETI
ORG0050H
START:
MOVA,#00H
MOVR0,#20H
MOVR1,#30H
LOOP0:
MOV@R0,A
INCR0
DJNZR1,LOOP0
MOVSP,#50H
MOVDISPLONG,#07
SETBRS0
SETBRS1
MOVR0,#DISPDAT0
MOVR2,#200
MOVR3,#120
MOVR4,#00
MOVR5,#00
MOVR6,#0FEH
MOVR7,DISPLONG
CLRRS0
MOVR2,#50
MOVR3,#30
CLRRS1
MOVLEDMOD,#02
MOVDISPCON,#07
MOVKEYDAT,#0FFH
SETBTIME
MOVTL0,#0AH;
1E定时2.5MS
MOVTH0,#0F7H
MOVIE,#8AH;
开T0,T1
MOVTMOD,#11H;
定时方式1
SETBTR0
MOVTL1,#00H;
定时10MS
MOVTH1,#0DCH
SETBTR1
MAIN:
ACALLKEY
JNBKEYBIT,MAIN1
ACALLDOKEY
MAIN1:
JBTIME,MAIN2
JBTIMESET,MAIN2
JBSU,MAIN3
MAIN2:
MOVR0,#HOURH
MOVR1,#DISPDAT0
MOVR2,#04H
MAINLOOP:
MOVA,@R0;
时间转七段码送显示数据区
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVC,DP
MOVACC.7,C
MOV@R1,A
INCR1
DJNZR2,MAINLOOP
SJMPMAIN
MAIN3:
MOVR0,#SUDAT00;
计算数转段码送显区
SJMPMAINLOOP
TAB:
DB40H,79H,24H,30H,19H
DB12H,02H,78H,00H,10H
DB7FH,7FH,7FH,7FH,7FH,7FH;
0A-0FF全黑
;
显示子程序
R0显示数址,R6位选值,R7显示计数,DISPL0NG显示数长度
DISPDATA0显示数据区首址
DISPLAY:
MOVP2,#0FFH
MOVP0,@R0
MOVP2,R6
DJNZR7,DISPLAY1
SJMPDISPOUT
DISPLAY1:
MOVA,R6
RLA
MOVR6,A
DISPOUT:
RET
键盘扫描程序
;
KEYDAT存放键码,双键按下只认前键
KEYBIT有键标示
KEY:
MOVP1,#0F0H
MOVA,P1
ORLA,#0FH
XRLA,#0FFH
JZKEYOUT0
MOVA,#60H
LCALLDELAY
MOVP1,#0FEH;
KEYDAT存放键码
JNBP1.4,KEY1
JNBP1.5,KEY2
JNBP1.6,KEY3
JNBP1.7,KEY4
MOVP1,#0FDH
JNBP1.4,KEY5
JNBP1.5,KEY6
JNBP1.6,KEY7
JNBP1.7,KEY8
MOVP1,#0FBH
JNBP1.4,KEY9
JNBP1.5,KEY10
JNBP1.6,KEY11
JNBP1.7,KEY12
MOVP1,#0F7H
JNBP1.4,KEY13
JNBP1.5,KEY14
JNBP1.6,KEY15
JNBP1.7,KEY16
CLRKEYBIT
KEYOUT0:
AJMPKEYOUT1
KEY1:
MOVKEYDAT,#0AH
SJMPKEYOUT
KEY2:
MOVKEYDAT,#09H
KEY3:
MOVKEYDAT,#08H
KEY4:
MOVKEYDAT,#07H
KEY5:
MOVKEYDAT,#0BH
KEY6:
MOVKEYDAT,#06H
KEY7:
MOVKEYDAT,#05H
KEY8:
MOVKEYDAT,#04H
KEY9:
MOVKEYDAT,#0CH
KEY10:
MOVKEYDAT,#03H
KEY11:
MOVKEYDAT,#02H
KEY12:
MOVKEYDAT,#01H
KEY13:
MOVKEYDAT,#0DH
KEY14:
MOVKEYDAT,#0EH
KEY15:
MOVKEYDAT,#00H
KEY16:
MOVKEYDAT,#0FH
KEYOUT:
SETBKEYBIT
JNZKEYOUT
MOVA,#100H
KEYOUT1:
键盘处理,
SU计算标志,TIME时间标志,TIMSET时间设置标志
SUCON计算输入位数,TSETCON时间设置位数
DISPCON显示位数
SUDAT00-03加数(减数),SUDAT10-13加数(被减数)
LEDMOD流水灯模式,TSETCON时间设置位数,DISPCON显示位数
ADDBIT加法标示,SUBBIT减法标示
DOKEY:
MOVA,KEYDAT
CLRC
SUBBA,#10H;
大于16为错码
JNCDONEXT
SUBBA,#0AH;
大于10为功能键,小于10为数字键
JCNEXT
MOVB,#03
MULAB
MOVDPTR,#DOFKEY;
功能键处理
JMP@A+DPTR
DOFKEY:
LJMPDOFKEY1
LJMPDOFKEY2
LJMPDOFKEY3
LJMPDOFKEY4
LJMPDOFKEY5
LJMPDOFKEY6
NOP
DONEXT:
LJMPDOKEYOUT
NEXT:
LJMPDOSKEY
DOFKEY1:
计算功能
LCALLTIMDB
JNBTIMESET,DOFKEY11
PUSHPSW
POPPSW
DOFKEY11:
SETBSU;
SU计算标志
CLRTIME;
TIME时间标志
CLRTIMESET;
TIMSET时间设置标志
MOVSUCON,#04H;
SUCON计算输入位数
SETBDP
CLRSUBIT
MOVSUDAT00,#00H
MOVSUDAT01,#00H
MOVSUDAT02,#00H
MOVSUDAT03,#00H
MOVSUDAT10,#00H
MOVSUDAT11,#00H
MOVSUDAT12,#00H
MOVSUDAT13,#00H
DOFKEY2:
计时功能
JNBTIMESET,DOFKEY21
DOFKEY21:
CLRSU
CLRTIMESET
MOVSUCON,#00H
DOFKEY3:
时间设置功能
SETBTIMESET
CLRTIME
DOFKEY4:
流水灯功能
MOVA,LEDMOD
SUBBA,#01H
JNCDOFKEY40
MOVLEDMOD,#03
MOVDISPLONG,#04H
DOFKEY40:
MOVLEDMOD,A
MOVDISPLONG,#07H;
DISPLONG显示位数
CJNEA,#02H,DOFKEY41
MOVDISPDAT4,#00H
MOVDISPDAT5,#00H
MOVDISPDAT6,#00H
DOFKEY41:
MOVDISPDAT4,#24H
MOVDISPDAT5,#92H
MOVDISPDAT6,#49H
DOFKEY5:
加号处理
MOVR4,SUDAT00
MOVR5,SUDAT01
MOVR6,SUDAT02
MOVR7,SUDAT03
MOVR0,SUDAT10
MOVR1,SUDAT11
MOVR2,SUDAT12
MOVR3,SUDAT13
LCALLBADD
MOVSUCON,#04H
DOFKEY6:
减号处理
SETBSUBIT
DOSKEY:
数字键处理
JBSU,DOSKEY1
JBTIMESET,DOSKEY2;
时间设定
DOSKEY1:
MOVA,SUCON
CJNEA,#04H,DOSKEY10
DOSKEY10:
JZDOKEYOUT
MOVSUDAT00,SUDAT01
MOVSUDAT01,SUDAT02
MOVSUDAT02,SUDAT03
MOVSUDAT03,KEYDAT
DECSUCON
DOSKEY2:
MOVA,SUCON;
设定时间
ADDA,SUCON
MOVDPTR,#DOSKEY20
DOSKEY20:
SJMPDOSKEY21
SJMPDOSKEY22
SJMPDOSKEY23
SJMPDOSKEY24
DOSKEY21:
MOVA,KEYDAT;
设定小时高位
SUBBA,#03
JNCDOKEYOUT
MOVHOURH,KEYDAT
SJMPDOSKEY25
DOSKEY22:
MOVA,HOURH;
设定小时低位
CJNEA,#02,NE1
SUBBA,#4
NE1:
MOVHOURL,KEYDAT
DOSKEY23:
设分高位
SUBBA,#6
MOVMINH,KEYDAT
DOSKEY24:
MOVMINL,KEYDAT;
设分低位
DOSKEY25:
LCALLSU10T08
INCSUCON
JCDOKEYOUT
DOKEYOUT:
MOVKEYDAT,#0FFH;
0FFH为无键码指示
TIME0;
用第三组寄存器,MINL分钟低位,MINH分钟高位
HOURL小时低位,HOURH小时高位
R4分钟数<
60,R5小时数<
24,R2为2.5MS计数,R3为0.5S计数
DP秒闪标示
TIME0:
T0计时
PUSHACC
MOVF0,C
ACALLDISPLAY;
0.25MS显示一位
DJNZR2,TIMEOUT
MOVR2,#200;
200*0.25MS=0.5S
JBSU,TIME00
CPLDP
TIME00:
DJNZR3,TIMEOUT
MOVR3,#120;
120*0.5S=60S
INCR4;
R4计分钟值,满60向R5进位
MOVA,R4
SUBBA,#60
JCTIME01
INCR5;
R5计小时值
TIME01:
MOVA,R4;
将R5值化为十进制数
MOVB,#10
DIVAB
MOVMINH,A
MOVMINL,B
MOVA,R5
SUBBA,#24
JCTIME02
TIME02:
MOVHOURH,A
MOVHOURL,B
TIMEOUT:
MOVC,PSW.1
POPACC
TIME1:
T1计时,用于跑马灯和控制时间设置闪烁
PUSHACC;
R2计数时间闪烁频率
MOVF0,C;
r3计数跑马灯频率
PUSHPSW;
R4保存时间闪动初值
CLRRS0;
第二组寄存器
JNBTIMESET,TI10
DJNZR2,TI10
ADDA,R0
MOVR0,A
MOVA,@R0
CJNEA,#0AH,TI11
SJMPTI10
TI11:
MOVR4,A
MOV@R0,#0AH
TI10:
CJNEA,#02H,TI12
DJNZR3,TI1OUT
MOVR3,#15
ACALLLED
SJMPTI1OUT
TI12:
MOVR3,#60
TI1OUT:
DELAY;
DELAY:
延时程序,时间常数在ACC
DELAY1:
DJNZACC,$
DJNZACC,DELAY
流水灯子程序
LEDMOD模式,流水灯数据在DISPDAT4-6
LED:
ADDA,LEDMOD
MOVDPTR,#LED0
LED0:
SJMPMODL1
SJMPMODL2
SJMPMODL3
MODL1:
MOVC,DISPDAT6.7;
右移动
MOVA,DISPDAT4
RLCA
MOVDISPDAT4,A
MOVA,DISPDAT5
MOVDISPDAT5,A
MOVA,DISPDAT6
MOVDISPDAT6,A
MODL2:
MOVC,DISPDAT4.0;
左移动
RRCA
MODL3:
MOVC,DISPDAT4.7;
灯从左全亮后又到全灭
CPLC
十进制加法子程序
入口R0-3,R4-7,出口R4-7
SUADD:
MOVA,R3
ADDA,R7
DAA
MOVC,ACC.4
ANLA,#0FH
MOVR7,A
MOVA,R2
ADDCA,R6
MOVA,R1
ADDCA,R5
DA