要求P1.0~P1.4控制4个按键,P0.0-P0.4控制四个灯,P3.2口接一个按键用外部中断0控制所有灯灭,定时器中断让四个灯分别延时1s,2s,3s,4s闪亮,单片机晶振12MZH
。要用汇编语言!!
下面是我自己写的程序 最好能在我的基础上改
ORG 0000H
SJMP MAIN
ORG 000BH
SJMP CTC0
ORG 0003H
LJMP OUT
ORG 0030H
MAIN:
MOV SP,#60H
MOV TMOD,#01H
MOV TL0,#03CH ;定时器初值50ms
MOV TH0,#0B0H
SETB TR0
SETB EX0
SETB ET0
SETB EA
ACALL SEND ;寄存器初值
M1: JNB P1.0,L5
JNB P1.1,L6
JNB P1.2,L7
JNB P1.3,L8
L5: MOV R0,#00H
SJMP L1
L6: MOV R1,#00H
SJMP L2
L7: MOV R2,#00H
SJMP L3
L8: MOV R3,#00H
SJMP L4
L1: MOV R7,#14H ;定时1s
DJNZ R7,
L2: MOV R7,#28H ;定时2s
DJNZ R7,
L3: MOV R7,#3CH ;定时3s
DJNZ R7,
L4: MOV R7,#50H ;定时4s
DJNZ R7,
SEND:
MOV P0,#0FFH
MOV R0,#0FFH
MOV R1,#0FFH
MOV R2,#0FFH
MOV R3,#0FFH
RET
CTC0:
MOV TL0,#03CH
MOV TH0,#0B0H
CJNE R0,#00H,K1
CJNE R1,#00H,K2
CJNE R2,#00H,K3
CJNE R3,#00H,K4
K1: CPL P0.0
LJMP M1
K2: CPL P0.1
SJMP M1
K3: CPL P0.3
LJMP M1
K4: CPL P0.4
LJMP M1
RETI
OUT:
ACALL SEND
RETI