89C51单片机红绿灯程序是什么?

2025-01-31 09:13:01
推荐回答(1个)
回答1:

注p0口为东西红灯
; p1口为东西黄灯
;p2口为东西绿灯
;p3南北红灯
;p4南北黄灯
;p5南北绿灯

;绿灯停留3s;黄灯闪烁5次,每次0.2s,红的停留4s
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:MOV DPTR,#B1
MOV R2,#4
MOV A,#0H
F3:MOV R1,A
MOVC A,@A+DPTR
JNB ACC.4,SS1 ;判断东西方向黄灯是否亮,若亮则转移到黄灯闪烁程序
JNB ACC.1,SS2 ;判断南北方向黄灯是否亮,若亮则转移到黄灯闪烁程序
MOV P1,A
LCALL DY1S
SS:MOV A,R1
INC A
DJNZ R2,F3
SJMP MAIN

SS1:MOV R0,#10
XH1:CPL ACC.4
MOV P1,A
LCALL DYS
DJNZ R0,XH1
SJMP SS
SS2:MOV R0,#10
XH2:CPL ACC.1
MOV P1,A
LCALL DYS
DJNZ R0,XH2
SJMP SS

DY1S:MOV R5,#30
DLP0:MOV R6,#100
DLP1:MOV R7,#250 ;F=6MHZ
DLP2:DJNZ R7,DLP2 ;2X250X2uS=1ms
DJNZ R6,DLP1 ;1x100=0.1S
DJNZ R5,DLP0 ;0.1X30=3s
RET

DYS:MOV R6,#200
DLP3:MOV R7,#250 ;F=6MHZ
DLP4:DJNZ R7,DLP4 ;2X250X1uS=500us=1ms
DJNZ R6,DLP3 ;1x200=0.2S
RET
B1: DB 11011110B,11101110B,11110011B,11110101B
END