目 录
中文摘要·····································································································Ⅰ 1. 引言········································································································1 2. 设计任务及思路························································································1 3. 单片机·····································································································3 3.1 单片机简介·····························································································3 3.2 单片机基本结构 ·····················································································3 3.3 单片机硬件特性 ·····················································································3 4. 芯片的选择······························································································4 4.1 74LS373以及74LS07芯片简介···································································4 4.2 8255芯片·······························································································5 4.2.1 8255可编程并行接口芯片简介·······························································5 4.2.2 8255可编程并行接口芯片方式控制字格式说明·········································5 4.3 晶闸管···································································································7 5. 交通灯控制原理分析及方案论证·································································8 6. 系统硬件设计···························································································9 6.1 总体设计································································································9 6.2 单片机最小系统······················································································9 6.2.1 振荡电路·····························································································9 6.2.2 复位电路···························································································10 6.3 显示及其驱动模块·················································································11 6.3.1 键盘与状态显示功能···········································································11 6.3.2 倒计时计数功能·················································································11 7. 系统软件设计·························································································12 7.1 延时程序设计························································································12 7.1.1 计数器硬件延时·················································································12 7.1.2 软件延时···························································································13 7.2 时间及信号灯的显示··············································································14 7.2.1 8031并行口的扩展·············································································14
2.设计任务及思路
设计一个能够控制十二盏交通信号灯的模拟系统。通过交通信号灯控制系统的设计。
系统工作受开关控制,起动开关 ON 则系统工作;起动开关 OFF 则系统停止工作。控制对象如下:
东西方向红灯两个 , 南北方向红灯两个, 东西方向黄灯两个 , 南北方向黄灯两个, 东西方向绿灯两个 , 南北方向绿灯两个,
西
图1 交通信号示意 北东
南十字路口东西方向和南北方向各装有直行(包括右拐弯)控制红、黄、绿交通信号灯(如图1所示)。还有倒计时显示器,显示器用于显示相应方向直行控制当前点亮信号灯还要持续的时间(即剩余时间)。系统中有两个按钮-启动和停止,启动按钮按下后信号灯系统开始工作,并周而复始地循环;停止按钮按下,所有信号灯都熄灭。信号灯的控制规律如表1所示。即系统启动后,东西方向先绿灯亮25s,然后绿灯闪烁3s,最后黄灯亮2s,与此同时南北方向红灯亮30s。南北方向红灯亮30s后转为先绿灯亮25s,然后绿灯闪烁3s,最后黄灯亮2s,东西向红灯亮30s。由此周而复始地循环。要求采用单片机实现交通灯的控制规律。
表1 信号灯控制规律
东西方向 信号 时间 南北方向 信号 时间 绿灯亮 25s 绿灯闪烁 3s 红灯亮 30s 黄灯亮 2s 绿灯亮 25s 红灯亮 30s 绿灯闪烁 3s 黄灯亮 2s 设计电路中使用到的主要元器件,单片机芯片、8255芯片和晶闸管。十字路口分四条道,每条道有三个红绿灯,共十二个。每个红绿灯由一块8031芯片单独控制,我们只设计一个红绿灯的燃亮情况,同理根据燃亮顺序设计其它红绿灯。然后再组合起来,达到设计要求。
3.单片机
3.1单片机简介
单片机是一种集成电路芯片,简称为单片微型计算机。是采用超大规模集成电路技术把具有数据处理能力的中央处理器CPU,随机存储器RAM,只读存储器ROM,多种I\\0口和中断系统,定时器,计时器等功能,集成在一块硅片上构成的一个小而完善
的计算机系统。
3.2单片机基本结构
单片机由运算器,控制器,存储器,输入输出设备组成。
3.3单片机硬件特性
(1)单片机集成度很高,单片机包括CPU、4KB容量的ROM(8031无)、128B容量的RAM、2个16定时计时器、4个8位并行口、全双工串口行口。 (2)单片机系统结构简单,使用方便,实现了模块化。 (3)单片机可靠性能好,可工作很长时间。 (4)处理功能强,速度快
4.芯片的选择
4.1 74LS373以及74LS07简介
74LS373 是一种带三态门的8D锁存器,其管脚示意图2如下所示:
图2 74LS373管脚示意图
其中:1D-8D为8个输入端。
1Q-8Q为8个输出端。
LE为数据打入端:当LE为“1”时,锁存器输出 状态同输入状态;当LE由“1”变“0”时,数据 打入锁存器
OE为输出允许端;当OE=0时,三态门打开; 当OE=1时,三态门关闭,输出高阻。 六驱动器(OC高压输出) 74LS07
Vcc 6A 6Y 5A 5Y ┌┴─┴─┴─┴─┴─┴─┴┐
│14 13 12 11 10 9 Y = A ) │ 1 2 3 4 5 6 └┬─┬─┬─┬─┬─┬─┬┘7805实现正电压输出,负电压截止。
4A 4
8│ │ 7│
4.2 8255芯片
4.2.1 8255可编程并行接口芯片简介
8255可编程并行接口芯片有三个输入输出端口,即A口、B口和C口,对应于引脚PA7~PA0、PB7~PB0和PC7~PC0。其内部还有一个控制寄存器,即控制口。通常A口、B口作为输入输出的数据端口。C口作为控制或状态信息的端口,它在方式字的控制下,可以分成4位的端口,每个端口包含一个4位锁存器。它们分别与端口A/B配合使用,可以用作控制信号输出或作为状态信号输入。8255的内部组成框图如 图3所示:
图3 8255内部组成框图
4.2.2 8255可编程并行接口芯片方式控制字格式说明
8255有两种控制命令字:一个是方式选择控制字;另一个是C口按位置位/复位控制字。其中C口按位置位/复位控制字方式使用较为繁难,说明也较冗长,故在 此不作叙述。方式控制字格式说明如图4所示: