设计一个秒表,需要考虑以下因素:
1、因为视觉暂留的因素,一般而言到0.1秒的精度就可以了。
2、需要有按键控制启动、停止、清零这些功能。
KEYVAL EQU 30H
DAT EQU 33H
SCANLED EQU 39H
CLK EQU 77H
SEC EQU 78H
SEC1 EQU 79H
SEC2 EQU 7AH
DOT BIT 00H
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP EXTINT0
ORG 000BH
LJMP T0ISR ;50ms定时
ORG 001BH
LJMP T1ISR ;扫描显示
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#11H
MOV TH0,#03CH
MOV TL0,#0B0H
MOV TH1,#0ECH
MOV TL1,#078H
MOV KEYVAL,#2
MOV 33H,#10H
MOV 34H,#10H
MOV 35H,#10H
MOV 36H,#10H
MOV CLK,#0
SETB IT0
SETB EX0
CLR TR0
CLR ET0
MOV R2,#0
SETB TR1
SETB ET1
SETB EA
LOOP:
MOV A,KEYVAL
LOOP1:
JNZ LOOP2 ;启动
SETB TR0
SETB ET0
SJMP LOOP
LOOP2:
DEC A
JNZ LOOP3 ;暂停
CLR TR0
CLR ET0
SJMP LOOP
LOOP3:
DEC A
JNZ LOOP ;清零
MOV 36H,#0
MOV 35H,#0
MOV 34H,#0
MOV 33H,#0
SJMP LOOP
EXTINT0:
PUSH ACC
INC KEYVAL
MOV A,KEYVAL
CJNE A,#3,EXT00
EXT00:
JC EXT01
MOV KEYVAL,#0
EXT01:
POP ACC
RETI
T0ISR:
PUSH ACC
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
INC CLK
MOV A,CLK
CJNE A,#2,T0ISRE
MOV CLK,#0
INC 36H
MOV A,36H
CJNE A,#10,T0ISRE
MOV 36H,#0
INC 35H
MOV A,35H
CJNE A,#10,T0ISRE
MOV 35H,#0
INC 34H
MOV A,34H
CJNE A,#6,T0ISRE
MOV 34H,#0
INC 33H
MOV A,33H
CJNE A,#10,T0ISRE
MOV 33H,#0
T0ISRE:
POP ACC
RETI
T1ISR:
PUSH ACC
CLR TR1
MOV TH1,#0ECH
MOV TL1,#78H
SETB TR1
MOV DPTR,#LEDTAB
T100:
MOV R0,#DAT
MOV A,SCANLED
ADD A,R0
MOV R0,A
MOV A,SCANLED
JNZ T101
MOV P2,#01H
SETB DOT
SJMP T1DIS
T101:
DEC A
JNZ T102
MOV P2,#02H
CLR DOT
SJMP T1DIS
T102:
DEC A
JNZ T103
MOV P2,#04H
SETB DOT
SJMP T1DIS
T103:
MOV P2,#08H
CLR DOT
T1DIS:
MOV A,@R0
MOVC A,@A+DPTR
JNB DOT,T1DIS1
ORL A,#01H
T1DIS1:
CPL A
MOV P0,A
INC SCANLED
MOV A,SCANLED
CJNE A,#4,T1END
MOV SCANLED,#0
T1END:
POP ACC
RETI
LEDTAB: DB 0FCH ;"0" 00H
DB 60H ;"1" 01H
DB 0DAH ;"2" 02H
DB 0F2H ;"3" 03H
DB 66H ;"4" 04H
DB 0B6H ;"5" 05H
DB 0BEH ;"6" 06H
DB 0E0H ;"7" 07H
DB 0FEH ;"8" 08H
DB 0F6H ;"9" 09H
DB 0EEH ;"A" 0AH
DB 3EH ;"B" 0BH
DB 9CH ;"C" 0CH
DB 7AH ;"D" 0DH
DB 9EH ;"E" 0EH
DB 8EH ;"F" 0FH
DB 00H ;" " 10H
END
C51 http://zhidao.baidu.com/question/42921479.html?fr=qrl&cid=192&index=1
http://zhidao.baidu.com/question/29519178.html?fr=qrl&cid=192&index=2
1.基于单片机的设计
2.计时精度:百分之一秒
2.5键操作完成 清除 启动 停止 设置初值 程序退出的功能
采用LED显示时、分、秒、百分之一.PROTEL图最好也有
用89C51,外接晶振,复位电路,二个数码管,二个按键,做一个电子秒表,具体要求为用按键起停电子表,可用按键设计倒计时时间(如10S,20S,60S),并启动倒计时功能。能用按键选择以上两功能之一。
三、程序代码:
A_BIT EQU 20H
B_BIT EQU 21H
TEMP EQU 22H
MOV P3,#0FFH
MOV P0,#0FFH
CLR F0
CLR F1
MOV DPTR,#NUMTAB
MOV P3,#0FFH
MOV P0,#0FFH
START:JB P3.6,START1
ACALL DELAY10
JB P3.6,START
JNB P3.6,$
LJMP GN1
START1: JB P3.7,START
ACALL DELAY10
JB P3.7,START1
JNB P3.7,$
LJMP GN2
GN1:
S1:MOV A,#0
MOV TEMP,A
GOON1: MOV R2,#2
JS1: MOV R3,#250
TIME1: MOV A,TEMP
MOV B,#10
DIV AB
MOV B_BIT,A
MOV A_BIT,B
LCALL DPLOP1
C1: JB P3.6,B1
ACALL DELAY10
JB P3.6,C1
JNB P3.6,$
CPL F0
ZT1: ; MOV P3,#0FFH
JB P3.6,$
ACALL DELAY10
JB P3.6,ZT1
JNB P3.6,$
LCALL DPLOP1
B1: JB P3.7,LOOP1
ACALL DELAY10
JB P3.7,B1
JNB P3.7,$
AJMP OVER
LOOP1: DJNZ R3,TIME1
DJNZ R2,JS1
INC TEMP
MOV A,TEMP
CLR C
SUBB A,#60
JNZ GOON1
ACALL OVER
RET
GN2: MOV A,#14H
MOV TEMP,A
MOV P3,#0FFH
MOV P0,#14H
GOON2: MOV R2,#2
JS2: MOV R3,#250
TIME2: MOV A,TEMP
MOV B,#10
DIV AB
MOV B_BIT,A
MOV A_BIT,B
MOV DPTR,#NUMTAB
DPLOP2: MOV A,A_BIT
MOVC A,@A+DPTR
MOV P0,A
CLR P2.5
ACALL DELY1
SETB P2.5
MOV A,B_BIT
MOVC A,@A+DPTR
MOV P0,A
CLR P2.6
ACALL DELY1
SETB P2.6
C2: JB P3.6,B2
ACALL DELAY10
JB P3.6,C2
JNB P3.6,$
ZT2: MOV P3,#0FFH
JB P3.6,$
ACALL DELAY10
JB P3.6,ZT2
JNB P3.6,$
B2: JB P3.7,LOOP2
ACALL DELAY10
JB P3.7,B1
JNB P3.7,$
AJMP OVER
LOOP2: DJNZ R3,TIME2
DJNZ R2,JS2
DEC TEMP
MOV A,TEMP
JNZ GOON2
ACALL OVER
RET
OVER: AJMP START
DELY1: MOV R4,#2
D1:MOV R5,#248
DJNZ R5,$
DJNZ R4,D1
RET
DELAY10: MOV R4,#20
D2:MOV R5,#248
DJNZ R5,$
DJNZ R4,D2
RET
NUMTAB: DB 40H,79H,24H,30H,19H,12H,02H,78H,00H,10H
DPLOP1: MOV A,A_BIT
MOVC A,@A+DPTR
MOV P0,A
CLR P2.5
ACALL DELY1
SETB P2.5
MOV A,B_BIT
MOVC A,@A+DPTR
MOV P0,A
CLR P2.6
ACALL DELY1
SETB P2.6
RET
END
教材中都有啊,用定时器做,根据晶振大小选择初值,先做一个1s的定时子程序,然后设置几个软件计数器,60就进位,第二个计数器60再进位,思路就是这