1.在拥堵情况下,主干道绿灯亮1分钟(此时次干道红灯亮)后,主干道绿灯闪烁5次,绿灯灭,黄灯亮5秒钟后,红灯亮,同时次干道红灯灭,绿灯亮。次干道绿灯40秒后,绿灯闪烁5次,绿灯灭,黄灯亮5秒钟后,红灯亮,同时次干道红灯灭,绿灯亮 2.非拥堵时段,根据两个干道最前车辆的速度以及距离红绿灯路口的距离,判断红绿灯时间,尽量两个方向车道的车辆均能够不停车通过
根据 p0.0 来判断 是否拥堵,根据p0.1判断当前是东西绿灯还是南北绿灯,第一个要求能实现,第二个要求实现不了 不知道哪里写错了,希望大家能帮忙指出错误, LED_G1 BIT P1.0 ;东西绿灯 LED_R1 BIT P1.1 ;东西红灯 LED_Y1 BIT P1.2 ;东西黄灯 LED_G2 BIT P1.3 ;南北绿灯 LED_R2 BIT P1.4 ;南北红灯 LED_Y2 BIT P1.5 ;南北黄灯 ORG 0000H LJMP START ORG 0100H START: MOV TMOD,#01H ;置T0工作方式1 MOV TH0,#03CH ;置TO定时初始值50ms MOV TL0,#0B0H SETB TR0 ;启动定时 CLR EA MOV P0,#0FFH MOV P1,#00H JB P0.0,SHUNCHANG LJMP YONGDU SHUNCHANG: MOV R4,#80 ;东西距离 MOV R5,#8 ;速度 MOV R6,#90 ;南北距离 MOV R7,#8 ;速度 JB P0.1,NBLV SJMP DXLV DXLV: SETB LED_G1 SETB LED_R2 SJMP DX NBLV: LCALL STATE4 SJMP DX DX: MOV A,R4 MOV B,R5 DIV AB JNB PSW.2,JW1 SJMP CUN1 CUN1: MOV 20H,A SJMP NB JW1: INC A SJMP CUN1 NB: CLR PSW.2 MOV A,R6 MOV B,R7 DIV AB JNB PSW.2,JW2 SJMP CUN2 CUN2: MOV 21H,A SJMP BJ JW2: INC A SJMP CUN2 BJ: MOV A,20H CJNE A,21H,BUDENG MOV R2,#20 MOV R3,20H BAOCHI: JNB TF0,BAOCHI ;查询50ms到否 CLR TF0 MOV TH0,#3CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,BAOCHI ;判断1s到否?未到继续状态4 MOV R2,#20 DJNZ R3,BAOCHI ;状态4维持40s CPL LED_G1 CPL LED_R1 CPL LED_G2 CPL LED_R2 LJMP SHUNCHANG BUDENG: JC DXXL NBXL: MOV R2,#20 MOV R3,21H NBXL1: LCALL STATE4 JNB TF0,NBXL1 ;查询50ms到否 CLR TF0 MOV TH0,#3CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,NBXL1 ;判断1s到否?未到继续状态4 MOV R2,#20 DJNZ R3,NBXL1 LCALL STATE1 LJMP SHUNCHANG DXXL: MOV R2,#20 MOV R3,20H DXXL1: LCALL STATE1 JNB TF0,DXXL1 ;查询50ms到否 CLR TF0 MOV TH0,#3CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,DXXL1 ;判断1s到否?未到继续状态4 MOV R2,#20 DJNZ R3,DXXL1 LCALL STATE4 LJMP SHUNCHANG YONGDU: MOV R2,#20 MOV R3,#60 ;东西绿灯60s WAIT1: LCALL STATE1 ;调用状态1 JNB TF0,WAIT1 ;查询50ms到否 CLR TF0 MOV TH0,#03CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,WAIT1 ;判断1s到否?未到继续状态1 MOV R2,#20 DJNZ R3,WAIT1 ;状态1维持60s MOV R2,#5 MOV R3,#5 ;东西绿灯闪5s MOV R4,#4 ;闪烁间隔200ms WAIT2: LCALL STATE2 ;调用状态2 JNB TF0,WAIT2 ;查询50ms到否 CLR TF0 MOV TH0,#03CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R4,WAIT2 ;判断200ms到否?未到继续状态2 CPL LED_G1 MOV R4,#4 ;闪烁间隔200ms DJNZ R2,WAIT2 MOV R2,#5 DJNZ R3,WAIT2 ;状态2维持5s MOV R2,#20 MOV R3,#5 ;东西黄灯5s WAIT3: LCALL STATE3 ;调用状态3 JNB TF0,WAIT3 ;查询50ms到否 CLR TF0 MOV TH0,#3CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,WAIT3 ;判断1s到否?未到继续状态3 MOV R2,#20 DJNZ R3,WAIT3 ;状态3维持5s MOV R2,#20 MOV R3,#40 ;东西红灯40s WAIT4: LCALL STATE4 ;调用状态4 JNB TF0,WAIT4 ;查询50ms到否 CLR TF0 MOV TH0,#3CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,WAIT4 ;判断1s到否?未到继续状态4 MOV R2,#20 DJNZ R3,WAIT4 ;状态4维持40s MOV R2,#5 MOV R3,#5 ;南北绿灯闪5s MOV R4,#4 ;闪烁间隔200ms WAIT5: LCALL STATE5 ;调用状态5 JNB TF0,WAIT5 ;查询50ms到否 CLR TF0 MOV TH0,#3CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R4,WAIT5 ;判断200ms到否?未到继续状态5 CPL LED_G2 ;南北绿灯闪 MOV R4,#4 DJNZ R2,WAIT5 ;判断1s到否?未到继续状态5 MOV R2,#5 DJNZ R3,WAIT5 ;状态5维持5s MOV R2,#20 MOV R3,#5 ;黄灯5s WAIT6: LCALL STATE6 ;调用状态6 JNB TF0,WAIT6 ;查询50ms到否 CLR TF0 MOV TH0,#03CH ;恢复T0定时初始值50ms MOV TL0,#0B0H DJNZ R2,WAIT6 ;判断1s到否?未到继续状态6 MOV R2,#20 DJNZ R3,WAIT6 ;状态6维持5s LJMP YONGDU STATE1: ;状态1 SETB LED_G1 ;东西绿灯亮 CLR LED_R1 CLR LED_Y1 CLR LED_G2 SETB LED_R2 ;南北红灯亮 CLR LED_Y2 RET STATE2: ;状态2 CLR LED_R1 CLR LED_Y1 CLR LED_G2 SETB LED_R2 ;南北红灯亮 CLR LED_Y2 RET STATE3: ;状态3 CLR LED_G1 CLR LED_R1 SETB LED_Y1 ;东西黄灯亮 CLR LED_G2 SETB LED_R2 ;南北红灯亮 CLR LED_Y2 RET STATE4: ;状态4 CLR LED_G1 SETB LED_R1 ;东西红灯亮 CLR LED_Y1 SETB LED_G2 ;南北绿灯亮 CLR LED_R2 CLR LED_Y2 RET STATE5: ;状态5 CLR LED_G1 SETB LED_R1 ;东西红灯亮 CLR LED_Y1
CLR LED_R2 CLR LED_Y2 RET STATE6: ;状态6 CLR LED_G1 SETB LED_R1 ;东西红灯亮 CLR LED_Y1 CLR LED_G2 CLR LED_R2 SETB LED_Y2 ;南北黄灯亮 RET END
|