...在亮灯期间按下键灯立即灭)用定时器及中断实现
发布网友
发布时间:2024-06-03 06:46
我来回答
共2个回答
热心网友
时间:2024-06-10 03:09
LED EQU P3.3
KEY EQU P3.7
ORG 0000H
LJMP START
ORG 000BH
LJMP T0_INT
ORG 0030H
;--------------------------------
START:
MOV TMOD, #01H
MOV TH0, #HIGH(65536-62500)
MOV TL0, #LOW(65536-62500)
MOV IE, #82H
;--------------------------------
LP1:
SETB LED
JB KEY, LP1
CALL DELAY
JB KEY, LP1
JNB KEY, $
;-------------------
MOV R2, #160
SETB TR0
CLR LED
LP2:
JNB TR0, LP1
JB KEY, LP2
CALL DELAY
JB KEY, LP2
JNB KEY, $
SJMP LP1
;--------------------------------
T0_INT:
MOV TH0, #HIGH(65536-62500)
MOV TL0, #LOW(65536-62500)
DJNZ R2, T0_E
CLR LED
CLR TR0
T0_E:
RETI
;--------------------------------
DELAY:
MOV R6, #20
DJNZ R7, $
DJNZ R6, $ - 2
RET
;--------------------------------
END
热心网友
时间:2024-06-10 03:11
LAMP EQU P1.0
KEY EQU P1.1
FLAG BIT 00H
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 0030H
MAIN:
MOV TMOD,#01H
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
SETB ET0
SETB EA
MOV R2,#200
CLR FLAG
LOOP:
JB KEY,LOOP
LCALL DELAY
JB KEY,LOOP
JNB KEY,$
SETB TR0
CPL FLAG
CLR LAMP
JB FLAG,LOOP
SETB LAMP
CLR TR0
SJMP LOOP
T0ISR:
CLR TR0
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
SETB TR0
DJNZ R2,T0E
MOV R2,#200
SETB FLAG
T0E:
RETI
DELAY:
MOV R3,#20
DELAY1:
MOV R4,#250
DJNZ R4,$
DJNZ R3,DELAY1
RET
END