交通灯 汇编 仿真 CPU过载 求解答
程序是 SECOND1 EQU 30H ;SECOND2 EQU 31H ;
DBUF EQU 40H ;
TEMP EQU 44H ;
LED_G2 BIT P2.2 ;
LED_Y2 BIT P2.3 ;
LED_R2 BIT P2.4 ;
LED_G1 BIT P2.5 ;
LED_Y1 BIT P2.6 ;
LED_R1 BIT P2.7 ;
DIN BIT P2.1 ;
CLK BIT P2.0 ;
ORG 0000H
LJMP START
ORG 0100H
START:
MOV A,#00H ;
MOV P2,A
MOV A,#0FFH
MOV P0,A
MOV P1,A
LCALL DISPLAY2
MOV TMOD,#01H ;
MOV TH0,#3CH ;
MOV TL0,#0B0H
SETB TR0;
CLR EA
LOOP: MOV R2,#20;
MOV R3,#20;
MOV SECOND1,#25;
MOV SECOND2,#25;
LCALL DISPLAY
LCALL STATE1;
WAIT1:JNB TF0,WAIT1;
CLR TF0
MOV TH0,#3CH;
MOV TL0,#0B0H
SETB TR0 ;
DJNZ R2,WAIT1;
MOV R2,#20;
DEC SECOND1;
DEC SECOND2;
LCALL DISPLAY
DJNZ R3,WAIT1;
MOV R2,#5;
MOV R3,#3;
MOV R4,#4;
MOV SECOND1,#5;
MOV SECOND2,#5;
LCALL DISPLAY
WAIT2: LCALL STATE2;
JNB TF0,WAIT2;
CLR TF0
MOV TH0,#3CH;
MOV TL0,#0B0H
DJNZ R4,WAIT2;
CPL LED_G1;
MOV R4,#4;
DJNZ R2,WAIT2;
MOV R2,#5;
DEC SECOND1;
DEC SECOND2;
LCALL DISPLAY
DJNZ R3,WAIT2;
MOV R2,#20;
MOV R3,#2;
MOV SECOND1,#2;
LCALL DISPLAY;
WAIT3: LCALL STATE3;
JNB TF0,WAIT3;
CLR TF0
MOV TH0,#3CH;
MOV TL0,#0B0H
DJNZ R2,WAIT3;
MOV R2,#20;
DEC SECOND1;
DEC SECOND2;
LCALL DISPLAY
DJNZ R3,WAIT3;
MOV R2,#20;
MOV R3,#20;
MOV SECOND1,#25;
MOV SECOND2,#25;
LCALL DISPLAY
WAIT4: LCALL STATE4;
JNB TF0,WAIT4;
CLR TF0
MOV TH0,#3CH;
MOV TL0,#0B0H
DJNZ R2,WAIT4;
MOV R2,#20;
DEC SECOND1;
DEC SECOND2;
LCALL DISPLAY
DJNZ R3,WAIT4;
MOV R2,#5;
MOV R4,#4;
MOV SECOND1,#5;
MOV SECOND2,#5;
LCALL DISPLAY;
WAIT5: LCALL STATE5;
JNB TF0,WAIT5;
CLR TF0
MOV TH0,#3CH;
MOV TL0,#0B0H
DJNZ R4,WAIT5;
CPL LED_G2;
MOV R4,#4;
DJNZ R2,WAIT5;
MOV R2,#5;
DEC SECOND1;
DEC SECOND2;
LCALL DISPLAY
DJNZ R3,WAIT5;
MOV R2,#20;
MOV R3,#2;
MOV SECOND1,#2;
MOV SECOND2,#2;
LCALL DISPLAY;
WAIT6: LCALL STATE6;
JNB TF0,WAIT6;
CLR TF0
MOV TH0,#3CH;
MOV TL0,#0B0H
DJNZ R2,WAIT6;
MOV R2,#20;
DEC SECOND1;
DEC SECOND2;
LCALL DISPLAY
DJNZ R3,WAIT6;
LJMP LOOP;
STATE1: ;
SETB LED_G1 ;
CLR LED_Y1
CLR LED_R1
CLR LED_G2
CLR LED_Y2
SETB LED_R2 ;
RET
STATE2: ;
CLR LED_Y1
CLR LED_R1
CLR LED_G2
CLR LED_Y2
SETB LED_R2 ;
RET
STATE3: ;
CLR LED_G1
CLR LED_Y1
CLR LED_G2
CLR LED_Y2
SETB LED_R2 ;
SETB LED_Y1 ;
RET
STATE4: ;
CLR LED_G1
CLR LED_Y1
SETB LED_R1 ;
SETB LED_G2 ;
CLR LED_Y2
CLR LED_R2
RET
STATE5: ;
CLR LED_G1
CLR LED_Y1
SETB LED_R1 ;
CLR LED_Y2
CLR LED_R2
RET
STATE6: ;
CLR LED_G1
CLR LED_Y1
SETB LED_R1 ;
CLR LED_G2
CLR LED_R2
SETB LED_Y2 ;
RET
DISPLAY: ;
MOV A,SECOND1;
MOV B,#10;
DIV AB
MOV DBUF+2,A
MOV A,B
MOV DBUF+3,A
MOV A,SECOND2;
MOV B,#10;
DIV AB
MOV DBUF,A
MOV A,B
MOV DBUF+1,A
MOV R0,#DBUF
MOV R1,#TEMP
MOV R7,#4
DP10: MOV DPTR ,#LEDMAP
MOV A,@R0
MOVC A,@A+DPTR
MOV @R1,A
INC R0
INC R1
DJNZ R7,DP10
MOV R0,#TEMP
MOV R1,#4
DP12: MOV R7,#8
MOV A,@R0
DP13: RLC A
MOV DIN,C
CLR CLK
SETB CLK
DJNZ R7,DP13
INC R0
DJNZ R1,DP12
RET
LEDMAP:DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH;
DISPLAY2:
MOV R7, #8
OUTDATA:
RRC A
MOV P3.0,C
CLR P3.2
SETB P3.2
NOP
NOP
DJNZ R7,OUTDATA
SETB P3.1;
CLR P3.1
RET
END
在仿真的时候第一个状态能出现 这个时候CPU占用半分之50左右 当绿灯闪3秒后 黄灯2接着两秒 但是这个时候就会卡在着 数码管不变了 就显示02 黄灯一直亮着 CPU过载了 谁能帮忙分析一下呢