请问C51单片机电子时钟的设计程序怎么样编写啊?

题目一、单片机电子时钟的设计(参考P158例6-4)要求:利用8个LED数码管显示时、分、秒(显示形式为:23-45-28),按Key1键时钟停止走动,首先进入调分状态,... 题目一 、 单片机电子时钟的设计(参考P158例6-4)
要求:利用8个LED数码管显示时、分、秒(显示形式为:23 - 45 - 28),按Key1键时钟停止走动,首先进入调分状态,继续按Key1键进入调时状态,按Key2键进行加1操作,按Key3键进行减1操作,最后按Key1键退出调整状态,时钟开始运行。
展开
 我来答
西区金毛豹
2008-01-10 · TA获得超过131个赞
知道答主
回答量:49
采纳率:0%
帮助的人:0
展开全部
BUFF_KEY EQU 21H ;键盘键
BUFF_LED1 EQU 22H ;数码管显示缓存
BUFF_LED2 EQU 23H
BUFF_LED3 EQU 24H
BUFF_LED4 EQU 25H
BUFF_LED5 EQU 26H
BUFF_LED6 EQU 27H
BUFF_LED_LP EQU 28H ;T0键盘显示扫描缓存
HOR EQU 30H ;小时值缓存
MIN EQU 31H ;分钟值缓存
SEC EQU 32H ;秒值缓存
F_BEEP BIT 01H
LED_PORT EQU P0
DIG_PORT EQU P2
KEY_PORT EQU P2
SW1 BIT P2.7
SW2 BIT P2.6
SW3 BIT P2.5
SW4 BIT P2.4
SW5 BIT P2.3
SW6 BIT P2.2
BEEP BIT P2.0
KEY BIT P3.3
org 000h
JMP main
ORG 00BH
JMP T0_INT
ORG 100H
MAIN: MOV SP ,#40H
MOV PSW,#00H
MOV R0,#7FH ;初始化RAM区,
CLR_RAM:MOV A,#00H
MOV @R0,A
DJNZ R0,CLR_RAM
MOV P1,0FFH ;INIT
MOV P2,0FFH
MOV P0,0FFH
MOV P3,0FFH
MOV TMOD,#21h
MOV TH0,#240 ;T0=4MS
MOV TL0,#96
SETB TR0
SETB ET0
SETB EA

WAIT_KEY:JB KEY,$ ;等候按键!
JNB SW1,SW1_OK
JNB SW2,SW2_OK
JNB SW3,SW3_OK
JNB SW4,SW4_OK
JNB SW5,SW5_OKA
JNB SW6,SW6_OKA
JMP WAIT_KEY
SW5_OKA: JMP SW5_OK
SW6_OKA: JMP SW6_OK
SW1_OK: MOV A,HOR
CJNE A,#24,SW1_OVER
MOV HOR,#00H
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY
SW1_OVER:INC HOR ;时加1
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY

SW2_OK: MOV A,HOR
CJNE A,#00,SW2_OVER
MOV HOR,#23
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY
SW2_OVER:DEC HOR ;时减1
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
JMP WAIT_KEY

SW3_OK: MOV A,MIN
CJNE A,#59,SW3_OVER
MOV MIN,#00H
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY
SW3_OVER:INC MIN ;分加1
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY

SW4_OK: MOV A,MIN
CJNE A,#00,SW4_OVER
MOV MIN,#59
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY
SW4_OVER:DEC MIN ;分减1
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY

SW5_OK: MOV A,SEC
CJNE A,#59,SW5_OVER
MOV SEC,#00H
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY
SW5_OVER:INC SEC ;秒加1
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY

SW6_OK: MOV A,SEC
CJNE A,#00,SW6_OVER
MOV HOR,#59
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY
SW6_OVER:DEC SEC ;时减1
SETB F_BEEP
CLR BEEP
LCALL DEL
SETB BEEP
CLR F_BEEP
JMP WAIT_KEY

DEL: MOV R5,#02 ;为演示方便,人为插入的延时
DEL01: MOV R6,#200
DEL02: MOV R7,#200
DJNZ R7,$
DJNZ R6,DEL02
DJNZ R5,DEL01
RET

BIN_BCD: MOV B,#10
DIV AB
RET

;------------- T0 INTRRUPT 数码管扫描定时中断---------------------------
T0_INT: PUSH ACC
PUSH PSW
MOV TH0,#240 ;T0=4MS
MOV TL0,#96
INC BUFF_LED_LP
MOV A,BUFF_LED_LP
CJNE A,#250,CONT_SCAN ;250*4MS=1S
MOV BUFF_LED_LP,#00H
INC SEC
MOV A,SEC
CJNE A,#60,CONT_SCAN
MOV SEC,#00H
INC MIN
MOV A,MIN
CJNE A,#60,CONT_SCAN
MOV MIN,#00H
INC HOR
MOV A,HOR
CJNE A,#24,CONT_SCAN
MOV HOR,#00H
clr beep
clr p1.0
lcall del
setb beep
setb p1.0
CONT_SCAN:MOV A,SEC
LCALL BIN_BCD
MOV BUFF_LED6,B
MOV BUFF_LED5,A
MOV A,MIN
LCALL BIN_BCD
MOV BUFF_LED4,B
MOV BUFF_LED3,A
MOV A,HOR
LCALL BIN_BCD
MOV BUFF_LED2,B
MOV BUFF_LED1,A
MOV A,BUFF_LED_LP
MOV B,#06
DIV AB
MOV A,B
RL A
MOV DPTR,#TAB_SCAN
JMP @A+DPTR
TAB_SCAN: AJMP SCAN_L1
AJMP SCAN_L2
AJMP SCAN_L3
AJMP SCAN_L4
AJMP SCAN_L5
AJMP SCAN_L6
SCAN_L1: MOV DIG_PORT,#01111111B
MOV A,BUFF_LED1
JMP END_SCAN
SCAN_L2: MOV DIG_PORT,#10111111B
MOV A,BUFF_LED2
JMP END_SCAN
SCAN_L3: MOV DIG_PORT,#11011111B
MOV A,BUFF_LED3
JMP END_SCAN
SCAN_L4: MOV DIG_PORT,#11101111B
MOV A,BUFF_LED4
JMP END_SCAN
SCAN_L5: MOV DIG_PORT,#11110111B
MOV A,BUFF_LED5
JMP END_SCAN
SCAN_L6: MOV DIG_PORT,#11111011B
MOV A,BUFF_LED6
END_SCAN: MOV DPTR,#TAB_LED
MOVC A,@A+DPTR
MOV LED_PORT,A
JNB F_BEEP,EXIT_T0
CLR BEEP
EXIT_T0: POP PSW
POP ACC
RETI

TAB_LED: DB 0C0H,0F9H,0A4H,0B0H,99H,92H ;数码管显示字型表
DB 82H,0F8H,80H,90H,88H,83H,0A7H
DB 0A1H,86H,8EH

END
潇湘电子工程师
2008-01-08 · TA获得超过3703个赞
知道大有可为答主
回答量:4170
采纳率:0%
帮助的人:2334万
展开全部
我的博客上有一个比较好的,是我2004年带课程设计时写的,你可以去看看.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
於夜漆雕骞骞
2019-09-07 · TA获得超过3765个赞
知道大有可为答主
回答量:3121
采纳率:34%
帮助的人:429万
展开全部
BUFF_KEY
EQU
21H
;键盘键
BUFF_LED1
EQU
22H
;数码管显示缓存
BUFF_LED2
EQU
23H
BUFF_LED3
EQU
24H
BUFF_LED4
EQU
25H
BUFF_LED5
EQU
26H
BUFF_LED6
EQU
27H
BUFF_LED_LP
EQU
28H
;T0键盘显示扫描缓存
HOR
EQU
30H
;小时值缓存
MIN
EQU
31H
;分钟值缓存
SEC
EQU
32H
;秒值缓存
F_BEEP
BIT
01H
LED_PORT
EQU
P0
DIG_PORT
EQU
P2
KEY_PORT
EQU
P2
SW1
BIT
P2.7
SW2
BIT
P2.6
SW3
BIT
P2.5
SW4
BIT
P2.4
SW5
BIT
P2.3
SW6
BIT
P2.2
BEEP
BIT
P2.0
KEY
BIT
P3.3
org
000h
JMP
main
ORG
00BH
JMP
T0_INT
ORG
100H
MAIN:
MOV
SP
,#40H
MOV
PSW,#00H
MOV
R0,#7FH
;初始化RAM区,
CLR_RAM:MOV
A,#00H
MOV
@R0,A
DJNZ
R0,CLR_RAM
MOV
P1,0FFH
;INIT
MOV
P2,0FFH
MOV
P0,0FFH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CJNE
A,#59,SW5_OVER
MOV
SEC,#00H
SETB
F_BEEP
CLR
BEEP
LCALL
DEL
SETB
BEEP
CLR
F_BEEP
JMP
WAIT_KEY
SW5_OVER:INC
SEC
;秒加1
SETB
F_BEEP
CLR
BEEP
LCALL
DEL
SETB
BEEP
CLR
F_BEEP
JMP
WAIT_KEY
SW6_OK:
MOV
A,SEC
CJNE
A,#00,SW6_OVER
MOV
HOR,#59
SETB
F_BEEP
CLR
BEEP
LCALL
DEL
SETB
BEEP
CLR
F_BEEP
JMP
WAIT_KEY
SW6_OVER:DEC
SEC
;时减1
SETB
F_BEEP
CLR
BEEP
LCALL
DEL
SETB
BEEP
CLR
F_BEEP
JMP
WAIT_KEY
DEL:
MOV
R5,#02
;为演示方便,人为插入的延时
DEL01:
MOV
R6,#200
DEL02:
MOV
R7,#200
DJNZ
R7,$
DJNZ
R6,DEL02
DJNZ
R5,DEL01
RET
BIN_BCD:
MOV
B,#10
DIV
AB
RET
;-------------
T0
INTRRUPT
数码管扫描定时中断---------------------------
T0_INT:
PUSH
ACC
PUSH
PSW
MOV
TH0,#240
;T0=4MS
MOV
TL0,#96
INC
BUFF_LED_LP
MOV
A,BUFF_LED_LP
CJNE
A,#250,CONT_SCAN
;250*4MS=1S
MOV
BUFF_LED_LP,#00H
INC
SEC
MOV
A,SEC
CJNE
A,#60,CONT_SCAN
MOV
SEC,#00H
INC
MIN
MOV
A,MIN
CJNE
A,#60,CONT_SCAN
MOV
MIN,#00H
INC
HOR
MOV
A,HOR
CJNE
A,#24,CONT_SCAN
MOV
HOR,#00H
clr
beep
clr
p1.0
lcall
del
setb
beep
setb
p1.0
CONT_SCAN:MOV
A,SEC
LCALL
BIN_BCD
MOV
BUFF_LED6,B
MOV
BUFF_LED5,A
MOV
A,MIN
LCALL
BIN_BCD
MOV
BUFF_LED4,B
MOV
BUFF_LED3,A
MOV
A,HOR
LCALL
BIN_BCD
MOV
BUFF_LED2,B
MOV
BUFF_LED1,A
MOV
A,BUFF_LED_LP
MOV
B,#06
DIV
AB
MOV
A,B
RL
A
MOV
DPTR,#TAB_SCAN
JMP
@A+DPTR
TAB_SCAN:
AJMP
SCAN_L1
AJMP
SCAN_L2
AJMP
SCAN_L3
AJMP
SCAN_L4
AJMP
SCAN_L5
AJMP
SCAN_L6
SCAN_L1:
MOV
DIG_PORT,#01111111B
MOV
A,BUFF_LED1
JMP
END_SCAN
SCAN_L2:
MOV
DIG_PORT,#10111111B
MOV
A,BUFF_LED2
JMP
END_SCAN
SCAN_L3:
MOV
DIG_PORT,#11011111B
MOV
A,BUFF_LED3
JMP
END_SCAN
SCAN_L4:
MOV
DIG_PORT,#11101111B
MOV
A,BUFF_LED4
JMP
END_SCAN
SCAN_L5:
MOV
DIG_PORT,#11110111B
MOV
A,BUFF_LED5
JMP
END_SCAN
SCAN_L6:
MOV
DIG_PORT,#11111011B
MOV
A,BUFF_LED6
END_SCAN:
MOV
DPTR,#TAB_LED
MOVC
A,@A+DPTR
MOV
LED_PORT,A
JNB
F_BEEP,EXIT_T0
CLR
BEEP
EXIT_T0:
POP
PSW
POP
ACC
RETI
TAB_LED:
DB
0C0H,0F9H,0A4H,0B0H,99H,92H
;数码管显示字型表
DB
82H,0F8H,80H,90H,88H,83H,0A7H
DB
0A1H,86H,8EH
END
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式