第1个回答 2011-01-07
谁知道你实验箱的电路板是怎样的啊??这个难啊!!
我有一个单片机的,是51芯片。你参考看看!!
ORG 0000H ;程序入口地址
AJMP START
ORG 000BH ;定时器0中断入口地址
LJMP INT_0
ORG 001BH ;定时器1中断入口地址
LJMP INT_1
ORG 0100H
START:LCALL QING ;初始化
QING: ;初始化
MOV 30H,#0 ;时十位寄存器清零
MOV 31H,#0 ;时个位寄存器清零
MOV 32H,#0 ;分十位寄存器清零
MOV 33H,#0 ;分个位寄存器清零
MOV 34H,#0 ;秒十位寄存器清零
MOV 35H,#0 ;秒个位寄存器清零
MOV 36H,#0 ;秒
MOV 37H,#0 ;分
MOV 38H,#0 ;时
MOV 39H,#20
MOV 40H,#0
MOV 41H,#0
MOV TMOD,#11H
MOV TH0,#3CH
MOV TL0,#0B0H ;赋初值,定时50ms
MOV TH1,#09EH
MOV TL1,#0D0H
SETB TR0 ;开启定时器0
SETB TR1
SETB EA ;开中断总开关
SETB ET0 ;定时器0中断允许位
SETB ET1
SETB PT0
CLR PT1
MAIN:MOV P3,#0FFH ;开启按键
JNB P3.3,KEY ;扫描按键
AJMP MAIN
KEY:JNB P3.3,KEY ;控制时钟
MOV 41H,#1
CLR TR0 ;关“T0“中断
LJMP KEY1
DISPLAY: ;数码管
MOV DPTR,#TABLE
MOV P2,#80H
MOV A,35H ; 显示秒个位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#40H
MOV A,34H ;显示秒十位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#20H
MOV A,33H ; 显示分个位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#10H
MOV A,32H ; 显示分十位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#20H
MOV P0,#7FH ;显示小数点
ACALL DELAY
JNB P3.2,LOOP ;转为” 时分“显示
LJMP EXIT
LOOP:JNB P3.2,LOOP
MOV 40H,#1
AJMP EXIT
DELAY:
MOV R3,#50 ;延时约为50MS
D0:
MOV R2,#50
DJNZ R2,$
DJNZ R3,D0
RET
DISPLAY_1:
MOV P2,#80H
MOV A,33H ; 显示分个位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#40H
MOV A,32H ; 显示分十位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#20H
MOV A,31H ;显示时个位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#10H
MOV A,30H ; 显示时十位
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
MOV P2,#20H
MOV P0,#7FH ;显示小数点
ACALL DELAY
JNB P3.2,LOOP1 ;转为”分秒“显示
LJMP EXIT
LOOP1:JNB P3.2,LOOP1
MOV 40H,#0
LJMP EXIT
K3:JNB P3.4,K3
KEY3:JNB P3.5,K2_0 ;调整”时“
JNB P3.3,SHI_0
AJMP KEY3
SHI_0:JNB P3.3,SHI_0
SHI:JNB P3.4,JIA_SHI ;”时“
JNB P3.5,JIAN_SHI
JNB P3.3,KEY0
AJMP SHI
JIA_SHI:JNB P3.4,JIA_SHI ; 加时
INC 36H
MOV R0,36H
CJNE @R0,#24,SHI
MOV 36H,#0
AJMP SHI
JIAN_SHI:JNB P3.5,JIAN_SHI ; 减时
DEC 36H
MOV R0,36H
CJNE @R0,#-1,SHI
MOV 36H,#23
AJMP SHI
KEY0: JNB P3.3,KEY0 ;转为时钟
MOV 41H,#0
MOV TH0,#3CH
MOV TL0,#0B4H
SETB TR0 ;开”T0” 中断
AJMP MAIN
K2: JNB P3.4,K2
K2_0: JNB P3.5,K2_0
KEY2: JNB P3.4,K3 ;调整”分“
JNB P3.5,K1
JNB P3.3,F_0
AJMP KEY2
K1: JNB P3.5,K1
KEY1: ;调整”秒“
JNB P3.4,K2
JNB P3.3,S_0
AJMP KEY1
S_0: JNB P3.3,S_0
S: JNB P3.3,KEY0 ; ”秒“
JNB P3.4,JIA_S
JNB P3.5,JIAN_S
AJMP S
JIA_S:JNB P3.4,JIA_S ;加秒
INC 38H
MOV R0,38H
CJNE @R0,#61,S
MOV 38H,#0
AJMP S
JIAN_S:JNB P3.5,JIAN_S ;减秒
DEC 38H
MOV R0,38H
CJNE @R0,#-1,S
MOV 38H,#59
AJMP S
F_0:JNB P3.3,F_0
F: JNB P3.4,JIA_F ; ”分“
JNB P3.5,JIAN_F
JNB P3.3,KEY0
AJMP F
JIA_F:JNB P3.4,JIA_F ;加 ”分“
INC 37H
MOV R0,37H
CJNE @R0,#60,F
MOV 37H,#0
AJMP F
JIAN_F:JNB P3.5,JIAN_F ;减 ”分“
DEC 37H
MOV R0,37H
CJNE @R0,#-1,F
MOV 37H,#59
AJMP F
INT_0: ;中断0初始化
MOV TH0,#4BH
MOV TL0,#0EAH
DJNZ 39H,EXIT
MOV 39H,#20
MOV A,41H ; 41H控制是否计时
CJNE A,#1,INT_01
INT_01:
INC 38H
MOV A,38H
CJNE A,#60,EXIT
MOV 38H,#0
INC 37H
MOV A,37H
CJNE A,#60,EXIT
MOV 37H,#0
INC 36H
MOV A,36H
CJNE A,#24,EXIT
MOV 36H,#0
INT_1:
MOV TH1,#9EH ;定时1中断
MOV TL1,#0D0H
INT_13: ;数据转换 “时”“分”“秒”
MOV A,36H
MOV B,#10
DIV AB
MOV 30H,A
MOV 31H,B
MOV A,37H
MOV B,#10
DIV AB
MOV 32H,A
MOV 33H,B
MOV A,38H
MOV B,#10
DIV AB
MOV 34H,A
MOV 35H,B
ACALL X1
EXIT:
RETI
X1: MOV A,40H ;分秒转换
CJNE A,#1,X2
LJMP DISPLAY_1
X2: LJMP DISPLAY
RET
TABLE: ;数据调用
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H ;字形显示编码
END本回答被网友采纳