扩展LED数码管,独立式键盘;利用片内定时器功能,完成电子计时时钟的硬件和软件设计。要电路图和汇编程序。
1.通过按键完成起始时间设置和计时启动。
2.显示精度:1s
3.6位数码管显示,“时,分,秒”
扩展LED数码管,独立式键盘;利用片内定时器功能,完成电子计时时钟的硬件和软件设计。要电路图和汇编程序。
1.通过按键完成起始时间设置和计时启动。
2.显示精度:1s
3.6位数码管显示,“时,分,秒”
S1 EQU P1.2
S2 EQU P1.3
S3 EQU P1.4
S4 EQU P1.5
DISPBUF EQU 30H
HOUR EQU 34H
MIN EQU 35H
SEC EQU 36H
COUNT EQU 37H
ORG 0000H
LJMP START
ORG 000BH
LJMP T0INT
START:CLR P1.1
MOV DISPBUF,#0C0H ;4个数码管显示“00.00”字形数据
MOV DISPBUF+1,#40H
MOV DISPBUF+2,#0C0H
MOV DISPBUF+3,#0C0H
MOV HOUR,#0 ;给时,分,秒及50MS计数单元附初值0
MOV MIN,#0
MOV SEC,#0
MOV COUNT,#0
MOV SP,#60H
MOV TMOD,#01H ;初始化T0工作于定时,方式1,软启动
MOV TH0,#3CH
MOV TL0,#0B0H
MOV IE,#10000010B
SETB TR0
MOV A,#0FFH
MOV P0,A
LOOP:LCALL CONV ;调用数码管显示数据转换子程序CONV
LCALL DISPSCAN ;调用数码管动态显示子程序
JNB S1,KEY1
SJMP LOOP
KEY1:LCALL DELAY
JNB S1,KEY2
SJMP LOOP
KEY2:LCALL SETTIME ;扫描S1键,如S1按下则调用时间调节子程序
SJMP LOOP
CONV:MOV A,HOUR
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV DISPBUF,A
MOV A,B
MOV DPTR,#TABLE1
MOVC A,@A+DPTR
MOV DISPBUF+1,A
MOV A,MIN
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV DISPBUF+2,A
MOV A,B
MOVC A,@A+DPTR
MOV DISPBUF+3,A
RET
DISPSCAN:MOV R0,#DISPBUF
MOV R2,#4
MOV A,#0FEH
SC:PUSH A
MOV A,@R0
MOV P0,A
POP A
MOV P2,A
LCALL DELAY1
RL A
INC R0
DJNZ R2,SC
RET
SETTIME:CLR TR0 ;T0暂停工作
MOV SEC,#0 ;秒计数单元清0
L0:LCALL DISPSCAN
JB S2,L1 ;S2键按下则小时计数单元加1
JNB S2,$
INC HOUR
MOV A,HOUR
CJNE A,#24,L11
MOV HOUR,#0
L11:LCALL CONV
LCALL DISPSCAN
SJMP L0
L1:JB S3,L2 ;S3键按下则分计数单元加1
JNB S3,$
INC MIN
MOV A,MIN
CJNE A,#60,L21
MOV MIN,#0
L21:LCALL CONV
LCALL DISPSCAN
SJMP L0
L2:JB S4,L0 ;S4键按下则退出时间调整状态
JNB S4,$
SETB TR0
RET
T0INT:PUSH A
MOV TH0,#3CH
MOV TL0,#0B0H
INC COUNT
MOV A,COUNT
CJNE A,#20,TT1
MOV COUNT,#0
CPL P3.0
INC SEC
MOV A,SEC
CJNE A,#60,TT1 ;秒计数单元为60,则分计数单元加1,同时秒计数单元清0
MOV SEC,#0
INC MIN
MOV A,MIN
CJNE A,#60,TT1
MOV MIN,#0
INC HOUR
MOV A,HOUR
CJNE A,#24,TT1 ;小时计数单元为24,则将其清0
MOV SEC,#0
MOV MIN,#0
MOV HOUR,#0
TT1:POP A
RETI
DELAY: ;10ms延时子程序
RET
DELAY1: ;1ms延时子程序
RET
TABLE:DB 11100111B,10000100B,11010011B,11010110B,10110100B;0,1,2,3,4
DB 01110110B,01110111B,11000100B,11110111B,11110110B;5,6,7,8,9
TABLE1:DB 11101111B,10001100B,11011011B,11011110B,10111100B;0.,1.,2.,3.,4.
DB 01111110B,01111111B,11001100B,11111111B,11111110B;5.,6.,7.,8.,9.
END
怎么提了2个相同问题?这个很容易弄的,就是麻烦点:
(1. 开机时,显示12:00:00的时间开始计时;
(2. P0.0/AD0控制“秒”的调整,每按一次加1秒;
(3. P0.1/AD1控制“分”的调整,每按一次加1分;
(4. P0.2/AD2控制“时”的调整,每按一次加1个小时;
汇编源程序
SECOND EQU 30H
MINITE EQU 31H
HOUR EQU 32H
HOURK BIT P0.0
MINITEK BIT P0.1
SECONDK BIT P0.2
DISPBUF EQU 40H
DISPBIT EQU 48H
T2SCNTA EQU 49H
T2SCNTB EQU 4AH
TEMP EQU 4BH
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START: MOV SECOND,#00H
MOV MINITE,#00H
MOV HOUR,#12
MOV DISPBIT,#00H
MOV T2SCNTA,#00H
MOV T2SCNTB,#00H
MOV TEMP,#0FEH
LCALL DISP
MOV TMOD,#01H
MOV TH0,#(65536-2000) / 256
MOV TL0,#(65536-2000) MOD 256
SETB TR0
SETB ET0
SETB EA
WT: JB SECONDK,NK1
LCALL DELY10MS
JB SECONDK,NK1
INC SECOND
MOV A,SECOND
CJNE A,#60,NS60
MOV SECOND,#00H
NS60: LCALL DISP
JNB SECONDK,$
NK1: JB MINITEK,NK2
LCALL DELY10MS
JB MINITEK,NK2
INC MINITE
MOV A,MINITE
CJNE A,#60,NM60
MOV MINITE,#00H
NM60: LCALL DISP
JNB MINITEK,$
NK2: JB HOURK,NK3
LCALL DELY10MS
JB HOURK,NK3
INC HOUR
MOV A,HOUR
CJNE A,#24,NH24
MOV HOUR,#00H
NH24: LCALL DISP
JNB HOURK,$
NK3: LJMP WT
DELY10MS:
MOV R6,#10
D1: MOV R7,#248
DJNZ R7,$
DJNZ R6,D1
RET
DISP:
MOV A,#DISPBUF
ADD A,#8
DEC A
MOV R1,A
MOV A,HOUR
MOV B,#10
DIV AB
MOV @R1,A
DEC R1
MOV A,B
MOV @R1,A
DEC R1
MOV A,#10
MOV@R1,A
DEC R1
MOV A,MINITE
MOV B,#10
DIV AB
MOV @R1,A
DEC R1
MOV A,B
MOV @R1,A
DEC R1
MOV A,#10
MOV@R1,A
DEC R1
MOV A,SECOND
MOV B,#10
DIV AB
MOV @R1,A
DEC R1
MOV A,B
MOV @R1,A
DEC R1
RET
INT_T0:
MOV TH0,#(65536-2000) / 256
MOV TL0,#(65536-2000) MOD 256
MOV A,#DISPBUF
ADD A,DISPBIT
MOV R0,A
MOV A,@R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P1,A
MOV A,DISPBIT
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P3,A
INC DISPBIT
MOV A,DISPBIT
CJNE A,#08H,KNA
MOV DISPBIT,#00H
KNA: INC T2SCNTA
MOV A,T2SCNTA
CJNE A,#100,DONE
MOV T2SCNTA,#00H
INC T2SCNTB
MOV A,T2SCNTB
CJNE A,#05H,DONE
MOV T2SCNTB,#00H
INC SECOND
MOV A,SECOND
CJNE A,#60,NEXT
MOV SECOND,#00H
INC MINITE
MOV A,MINITE
CJNE A,#60,NEXT
MOV MINITE,#00H
INC HOUR
MOV A,HOUR
CJNE A,#24,NEXT
MOV HOUR,#00H
NEXT: LCALL DISP
DONE: RETI
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H
TAB: DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
END