下面是我写的一个关于定时器的程序,然后我想给程序添加一个功能,功能是“当K2调节
tiME0或TIME1时,对应的数码管显示以一秒为周期闪烁” 我尝试用T0中断来实现,但是
proteus仿真失败,所以请教一下大家,要是你们的话,会怎么修改这个程序来实现我上诉所说的功能!!!
K1 EQU P3.2
K2 EQU P3.3
TIME0 EQU 24H
TIME1 EQU 25H
SECOND EQU 28H
FLAG EQU 20H.1
FLAG1 EQU 20H.2
FLAG2 EQU 29H
ORG 0000H
AJMP MAIN
ORG 001BH
LJMP INT_T1
;******主程序******
ORG 0030H
MAIN: MOV SP,#60H
MOV TMOD,#10H
MOV TL1,#0E0H
MOV TH1,#0B1H
MOV TIME0,#00H
MOV TIME1,#01H
MOV SECOND,#00H
MOV FLAG2,#00H
MOV R1,#19H
SETB FLAG
SETB FLAG1
SETB TR1
SETB ET1
SETB EA
;******LED数码管显示子程序******
LEDDISPLAY:MOV DPTR,#TAB
SETB P3.1
LCALL DELAY
CLR P3.1
MOV A,TIME0
MOVC A,@A+DPTR
JB FLAG,L0
ANL A,#7FH
L0: MOV P1,A
SETB P3.0
LCALL DELAY
CLR P3.0
MOV A,TIME1
MOVC A,@A+DPTR
MOV P1,A
LCALL KEYJUDGE
LJMP LEDDISPLAY
;******T1中断程序******
INT_T1:MOV TL1,#0E0H
MOV TH1,#0B1H
DJNZ R1,TTT1
CPL FLAG
MOV R1,#19H
JNB FLAG,TTT1
LCALL TIMER
TTT1: RETI
;******倒计数子程序******
TIMER: INC SECOND
MOV A,SECOND
CJNE A,#01H,TT0
MOV SECOND,#00H
MOV A,TIME1
CJNE A,#00H,TT1
MOV A,TIME0
CJNE A,#00H,TT2
CLR TR1
CLR P3.4
LJMP TT0
TT1: MOV A,TIME0
CJNE A,#00H,TT2
DEC TIME1
MOV TIME0,#09H
LJMP TT0
TT2: DEC TIME0
TT0: RET
;******按键判断子程序******
KEYJUDGE:JB K1,AK1
LCALL DELAY
LCALL DELAY
JNB K1,$
INC FLAG2
MOV B,#03H
MOV A,FLAG2
DIV AB
MOV A,B
CJNE A,#01H,AN2
CLR ET1
CLR TR1
LJMP AK2
AN2: CJNE A,#02H,AN3
CLR ET1
CLR TR1
LJMP AK2
AN3: CJNE A,#00H,AN4
SETB TR1
SETB ET1
LJMP AK2
AN4: CLR ET1
CLR TR1
LJMP AK2
AK1: JB K2,AK2
LCALL DELAY
LCALL DELAY
MOV B,#03H
MOV A,FLAG2
DIV AB
MOV A,B
CJNE A,#01H,SETT1
LCALL SET_TIME0
LJMP AK2
SETT1: CJNE A,#02H,AK2
LCALL SET_TIME1
AK2: RET
;******定时时间个位设定子程序******
SET_TIME0:JNB K2,$
PUSH PSW
PUSH ACC
INC TIME0
MOV A,TIME0
CJNE A,#0AH,SET01
MOV TIME0,#00H
SET01: POP ACC
POP PSW
RET
;******定时时间十位设定子程序******
SET_TIME1:JNB K2,$
PUSH PSW
PUSH ACC
INC TIME1
MOV A,TIME1
CJNE A,#0AH,SET11
MOV TIME1,#00H
SET11: POP ACC
POP PSW
RET
;******延时子程序******
DELAY: MOV R7,#100
DJNZ R7,$
RET
;******数码管字形表******
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH
END
一周热门 更多>