下列程序,已经经过实验,可以满足题目要求。
KEY1 EQU P3.0
KEY2 EQU P3.1
LED1 EQU P3.2
LED2 EQU P3.3
Flag1 EQU 20H.0
Flag2 EQU 20H.1
L_F1 EQU 20H.2
L_F2 EQU 20H.3
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0_INT
ORG 0030H
MAIN:
MOV TH0, #04H
SETB TR0
MOV IE, #82H
MOV R2, #50
SJMP $
T0_INT:
MOV TH0, #04H
MOV C, Flag1
MOV LED1, C
DJNZ R2, K0
MOV R2, #50
JNB Flag2, K0
CPL LED2
K0:
;-------------------
K11:
JB KEY1, K12
SETB L_F1
SJMP K21
K12:
JB L_F1, K13
SJMP K21
K13:
CLR L_F1
CPL Flag1
;-------------------
K21:
JB KEY2, K22
SETB L_F2
SJMP K31
K22:
JB L_F2, K23
SJMP K31
K23:
CLR L_F2
CPL Flag2
;-------------------
K31:
RETI
END
KEY1 EQU P3.0
KEY2 EQU P3.1
LED1 EQU P3.2
LED2 EQU P3.3
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#01H
MOV TH0,#HIGH (65536-50000)
MOV TL0,#LOW (65536-50000)
SETB ET0
SETB EA
SETB LED1
SETB LED2
LOOP:
JB KEY1,LOOP1
LCALL DELAY
JB KEY1,LOOP1
JNB KEY1,$
CPL LED1
SJMP LOOP
LOOP1:
JB KEY2,LOOP
LCALL DELAY
JB KEY2,LOOP
JNB KEY2,$
CPL 00H
JB 00H,LOOP2
CLR TR0
SETB LED2
LJMP LOOP
LOOP2:
SETB TR0
LJMP LOOP
DELAY:
MOV R2,#20
DELAY1:
MOV R3,#250
DJNZ R3,$
DJNZ R2,DELAY1
RET
T0ISR:
CLR TR0
MOV TH0,#HIGH (65536-50000)
MOV TL0,#LOW (65536-50000)
SETB TR0
CPL LED2
RETI
END
#
定义UCHAR无符号的字符
的UCHAR时间,数量;
SBIT键= P3 ^ 0;
SBIT LED = P3 ^ 1;
>位标志;
的无效t0isr()中断1
{
倍+ +;
(次> = 6)
{
倍= 0
标志= 1;
}
}
()
{
TMOD = 0X01;
ET0 = 1;
倍= 0;
数= 0;
(1)
{
(KEY == 0)
{
延迟(10);
(键== 0)
{
TH0 =(65536-50000)/ 256;
TL0 =(65536-50000) 256%;
TR0 = 1;
(键);
(KEY == 0)
{
延迟(10);
((的关键== 0)&&(标志== 0))LED =?LED;
}
}
}
TR0 = 0;标志= 0; />}
}
如用C语言,我可以帮你!汇编我也不会!