如图 我想用单片机汇编语言来编写中断程序,要求是 LED灯初始化是灭的,当按下按钮灯亮一秒灭一秒,

2024-12-02 03:02:51
推荐回答(3个)
回答1:

;晶振12M
LED BIT P1.0
KEY1 BIT P2.0
KEY2 BIT P2.4
ORG 0000H
LJMP START
ORG 000BH
LJMP Timer0Interrupt

START:
MOV SP,#60H
MOV R2,#20
SETB LED
SETB KEY1
CLR KEY2
CLR TR0
LCALL InitTimer0

LOOP:;add your code here!
JNB KEY1,$
DELAY10MS
JB KEY1,$
CPL TR0
JNB TR0,D1
CLR LED
MOV TH0,#3CH;50MS
MOV TL0,#0B0H
LJMP LOOP
D1:
SETB LED
LJMP LOOP

InitTimer0:
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
SETB EA
SETB ET0 RET

Timer0Interrupt:
PUSH DPH
PUSH DPL
PUSH ACC
MOV TH0,#3CH
MOV TL0,#0B0H
;========================
;add your code here!
DJNZ R2,FH
MOV R2,#20
CPL LED
FH:
;========================
POP ACC
POP DPL
POP DPH
RETI
DELAY10MS: ;误差 0us
MOV R7,#01H
DL1:
MOV R6,#26H
DL0:
MOV R5,#82H
DJNZ R5,$
DJNZ R6,DL0
DJNZ R7,DL1
RET
END

回答2:

TCOUNT EQU 30H
ORG 0000H
LJMP START
ORG 000BH
LJMP T0INT
ORG 0050H
START:
CLR EA
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
MOV 30H,#0
SETB ET0
CLR 00H
SETB P1.0
LOOP:
JNB 00H,NOLED
SETB TR0
SJMP KEY
NOLED:
CLR TR0
SETB P1.0 ;灯灭
KEY:
MOV A,#01H
MOV P2,A
LCALL DELAY
MOV A,P2
ANL A,#10H
JNB ACC.4,LOOP ;有键按下
CPL 00H
SJMP LOOP
DELAY:
MOV R0,#250
DJNZ R0,$
RET
T0INT:
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
INC TCOUNT
MOV A,TCOUNT
CJNE A,#20,T0INTE ;1秒亮灭
CPL P1.0
MOV TCOUNT,#0
T0INTE:
RETI
END

回答3:

中断是什么 中断?定时中断?灯亮灭的间隔是多少?一般按键没你这样接的,一端接IO口,另一端接地。