1 / 9

实验六

实验六. 交通灯控制. 实验要求. 1 、用 单片机 的 P1 口输出控制信号,控制六个 LED 灯(红,绿,黄),模拟交通灯管理。. 实验目的. 1. 学习数据输出程序的设计方法。 2. 学习模拟交通灯控制的方法。 3. 了解软件延时方法. LED0 、 LED1 、 LED2 分别表示南北方向红、黄、绿灯. LED3 、 LED4 、 LED5 分别表示东西方向红、黄、绿灯. 实验电路及连线. 开始. 初始状态东西南北都是红灯. 状态 1 南北绿灯,东西红灯. 状态 2 南北绿灯闪转黄灯,东西红灯. 状态 3 南北红灯,东西绿灯.

alair
Download Presentation

实验六

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 实验六 交通灯控制

  2. 实验要求 1、用单片机的P1口输出控制信号,控制六个LED灯(红,绿,黄),模拟交通灯管理。

  3. 实验目的 • 1. 学习数据输出程序的设计方法。 • 2. 学习模拟交通灯控制的方法。 • 3. 了解软件延时方法

  4. LED0、LED1、LED2 分别表示南北方向红、黄、绿灯 LED3、LED4、LED5 分别表示东西方向红、黄、绿灯 实验电路及连线

  5. 开始 初始状态东西南北都是红灯 状态1南北绿灯,东西红灯 状态2南北绿灯闪转黄灯,东西红灯 状态3南北红灯,东西绿灯 状态4南北红灯,东西绿灯闪转黄灯 程序框图

  6. 程序清单 • Flash equ 0 ; LED状态 SR equ p1.0 ; 南北红灯 SY equ p1.1 ; 南北黄灯 SG equ P1.2 ; 南北绿灯 ER equ P1.3 ; 东西红灯 EY equ P1.4 ; 东西黄灯 EG equ p1.5 ; 东西绿灯 setb SR ; 南北, 东西均红灯 clr SY clr SG setb ER clr EY clr EG Loop: setb SR ; 南北红灯, 东西绿灯 clr SY clr SG clr ER

  7. 程序清单 clr EY setb EG mov a, #20 call Delay setb SR ; 南北红灯, 东西黄灯闪 clr SY clr SG clr ER clr EY clr EG clr Flash mov r7, #9 Loop1: mov c, Flash mov EY, c mov a, #1

  8. 程序清单 call Delay cpl Flash djnz r7, Loop1 clr SR ; 南北绿灯, 东西红灯 clr SY setb SG setb ER clr EY clr EG mov a, #20 call Delay clr SR ; 东西红灯, 南北黄灯闪 clr SY clr SG setb ER clr EY clr EG

  9. 程序清单 clr Flash mov r7, #9 Loop2: mov c, Flash mov SY, c mov a, #1 call Delay cpl Flash djnz r7, Loop2 ljmp Loop Delay: ; 延时子程序 mov r1, #0 mov r0, #0 DelayLoop: djnz r0, DelayLoop djnz r1, DelayLoop djnz ACC, Delay ret end

More Related