交通灯报告实训.docx
- 文档编号:27031175
- 上传时间:2023-06-25
- 格式:DOCX
- 页数:13
- 大小:110.17KB
交通灯报告实训.docx
《交通灯报告实训.docx》由会员分享,可在线阅读,更多相关《交通灯报告实训.docx(13页珍藏版)》请在冰豆网上搜索。
交通灯报告实训
广东水利电力技术学院实训实验报告
课程名可编程逻辑器件应用
实验项目名称交通灯控制器
学生班级12电子2班
学生姓名许炎庆
指导老师龚兰芳
2013年05月19日
前言
课堂上老师叫我们实验的基本步骤及基本思路,然后我们应用所学知识自己编程序,再测试程序,最后下载在下载板。
动手去实验它,亲手把那个看起来颇为复杂的东西给弄个明白,才能更加深刻的将知识印入脑中,有利加强学生个人的动手能力。
同时使学生能熟练掌握一种EDA软件(MAXPLUS2或QUARTUS2)的使用方法,能熟练进行设计输入、编译、管脚分配、下载等过程。
目录
1.实验目的与要求
2.实验方案设计及其原理
3.硬件要求
4.设计步骤
5.源程序和下载结果
6.实验结果分析
7.实验收获和体验,
一、实验要求
1.在十字路口的两个方向上各设一组红、绿、黄灯,显示顺序为其中一方向(东西方向)是绿灯,黄灯,红灯;另一方向为红灯,绿灯,黄灯。
2.设置一组数码管,以倒计时的方式显示允许通行或禁止通行的时间,其中绿灯、黄灯、红灯的持续时间分别是20s、5s、和25s。
3.当各路上任意一条出现特殊情况时,如消防车、救护车或其他需要优先放行的车辆通过时,各方向上均是红灯亮,倒计时停止,且显示数字在闪烁。
当特殊运行状态结束后,控制器恢复原来状态,继续正常运行。
4.选做:
用两组数码管实现双向倒计时显示。
目的:
1、掌握多个计数器倒计时的方法。
2、掌握多位共阳极数码管动态扫描显示驱动及编码、译码的方法。
3、掌握彩灯二极管的扫描及显示方法。
4、进一步熟悉EDA的VHDL的程序设计方法,熟练所学课程一些基本常用的软件,如此次的QuartusII,实操该软件的基本操作,学习掌握VHDL的描述方法,进一步掌握应用EDA常用工具进行组合逻辑电路的设计、分析、仿真等技巧。
同时
使自己能够编码程序,理解并学会。
二、实验设计方案及原理
设计一个交通灯需要红、黄、绿灯,所以需要彩灯,需要对彩灯进行扫描。
而且需要数码管位扫描,还要两个分频,一个(1000hz左右)用于数码管位扫描和彩灯扫描,另一个(1hz)用于计数。
另外还需要分位及译码部分。
三、硬件要求
主芯片EPM240T100C5,2个开关、LED灯,四个数码管。
四、设计步骤
首先对输入的脉冲clk进行多级分频,让有不同的频率,然后再通过相对应的脉冲进行扫描与计数,分位译码、控制器、红、黄、绿灯的亮灭等进程,最后测试,下载,再通过下载板看到结果
五、源程序
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entitydyis
port(
clk,rst,hold:
instd_logic;----脉冲,异步清零,紧急
r,y,g:
outstd_logic;--红,黄,绿
row:
outstd_logic_vector(3downto0);----灯扫描
duan:
outstd_logic_vector(6downto0);------七段数码管
wei:
outstd_logic_vector(5downto0)------数码管位
);
end;
architectureoneofdyis
signalwei1:
std_logic_vector(5downto0);
signalclk_1k,clk_1h:
std_logic;--脉冲1khz,1hz
signalr0,y0,g0:
std_logic;--东路口红,黄,绿信号,r<=r0
signalr1,y1,g1:
std_logic;--西路口红,黄,绿信号,r<=r1
signalcount4:
integerrange0to3;--计数器用于灯扫描
signalcount6:
integerrange0to5;--计数器用于数码管位扫描
signalt:
std_logic_vector(5downto0);--扫描时不同的位为1时把numa~numd赋值给shu(shu为变量)
signalf:
integerrange0to3;--寄存器
signalnumx,numy:
integerrange0to24;--两个显示器各自的数
signalnuma,numb,numc,numd:
integerrange0to9;--每个数由两个一位数组成
begin
process(clk)--分频得1000hz用于数码管位扫描和灯扫描
variablecnt1:
integerrange0to250;
variablecnt2:
integerrange0to100;
begin
ifclk'eventandclk='1'then
ifcnt1=250then
cnt1:
=0;
ifcnt2=100then
cnt2:
=0;
clk_1k<=notclk_1k;
else
cnt2:
=cnt2+1;
endif;
else
cnt1:
=cnt1+1;
endif;
endif;
endprocess;
process(clk_1k)--分频得1hz
variablecnt1:
integerrange0to500;
begin
ifclk_1k'eventandclk_1k='1'then
ifcnt1=500then
cnt1:
=0;
clk_1h<=notclk_1h;
else
cnt1:
=cnt1+1;
endif;
endif;
endprocess;
process(clk_1k,count6,hold)
begin
ifclk_1k'eventandclk_1k='1'then
ifcount6=5then
count6<=0;
else
count6<=count6+1;
endif;
endif;
casecount6is--数码管位扫描,当wei<='111110'时,只有t(0)=1,且shu:
=numa,则数码管第一位显示numa
when0=>wei<="111110";t<="000001";--t(0)='1'thenshu:
=numa;东路个位
when1=>wei<="111101";t<="000010";--t
(1)='1'thenshu:
=numb;东路十位
when2=>wei<="111111";t<="000100";--t
(2)='1'thenshu:
=0;
when3=>wei<="111111";t<="001000";--t(3)='1'thenshu:
=0;
when4=>wei<="101111";t<="010000";--t(4)='1'thenshu:
=numc;西路个位
when5=>wei<="011111";t<="100000";--t(5)='1'thenshu:
=numd;西路十位
whenothers=>wei<="111111";
endcase;
endprocess;
process(clk_1k,count4)-----灯扫描
begin
ifclk_1k'eventandclk_1k='1'then
ifcount4=3then
count4<=0;
else
count4<=count4+1;
endif;
casecount4is
when0=>row<="1110";r<=r1;y<=y1;g<=g1;--西路(每条路显示两行)
when1=>row<="1101";r<=r0;y<=y0;g<=g0;--东路
when2=>row<="1011";r<=r1;y<=y1;g<=g1;
when3=>row<="0111";r<=r0;y<=y0;g<=g0;
whenothers=>row<="1111";
endcase;
endif;
endprocess;
process(rst,hold,clk_1h)
begin
ifrst='1'then--复位(初始状态,numx为东路,刚开始路灯亮20秒,
numx<=19;r0<='0';y0<='0';g0<='1';f<=0;--此时numy西路为红灯亮25秒,f为0
numy<=24;r1<='1';y1<='0';g1<='0';
elsifhold='1'then--紧急(救护车)红灯闪,计数暂停
numx<=numx;r0<=clk_1h;y0<='0';g0<='0';
numy<=numy;r1<=clk_1h;y1<='0';g0<='0';
elsifclk_1h'eventandclk_1h='1'then--当上升沿到来时
casefis
when0=>--当f=0时为东路绿,西路红阶段
ifnumx=0then--如果东路绿灯20秒过去,那么东路黄灯亮,西路还是红灯亮,
numx<=4;numy<=4;f<=1;--两路同时显示剩4秒,f赋值为1
r0<='0';y0<='1';g0<='0';
r1<='1';y1<='0';g1<='0';
else--如果20秒还没过去,则同时减1
numx<=numx-1;
numy<=numy-1;
r0<='0';y0<='0';g0<='1';
r1<='1';y1<='0';g1<='0';
endif;
--当f=1为东路黄,西路红阶段
when1=>ifnumy=0then--当f=1时,如果东路黄灯5秒过去,那么东路红灯亮,西路是绿灯亮,f赋值为2
numx<=24;numy<=19;f<=2;
r0<='1';y0<='0';g0<='0';
r1<='0';y1<='0';g1<='1';
else--如果东路黄灯5秒还没过去,那么显示器各减1
numx<=numx-1;
numy<=numy-1;
r0<='0';y0<='1';g0<='0';
r1<='1';y1<='0';g1<='0';
endif;
when2=>ifnumy=0then--当f=2为东路红,西路绿阶段
numx<=4;numy<=4;f<=3;--当f=2时,如果西路绿灯20秒过去,那么东路红灯亮,西路是黄灯亮,f赋值为3
r0<='1';y0<='0';g0<='0';--两路同时显示剩4秒
r1<='0';y1<='1';g1<='0';
else
numx<=numx-1;--如果西路绿灯20秒还没过去,那么显示器各减1
numy<=numy-1;
r0<='1';y0<='0';g0<='0';
r1<='0';y1<='0';g1<='1';
endif;
when3=>ifnumy=0then--当f=3为东路红,西路黄阶段
numx<=19;numy<=24;f<=0;--当f=3时,如果西路黄灯5秒过去,那么东路红灯亮,西路是绿灯亮,f赋值为0
r0<='0';y0<='0';g0<='1';
r1<='1';y1<='0';g1<='0';
else--如果西路黄灯5秒还没过去,那么显示器各减1
numx<=numx-1;
numy<=numy-1;
r0<='1';y0<='0';g0<='0';
r1<='0';y1<='1';g1<='0';
endif;
whenothers=>r0<='1';y0<='0';g0<='0';r1<='1';y1<='0';g1<='0';
endcase;
endif;
endprocess;
process(numx,numy)
begin
ifnumx>=20then--分位,如果大于20,那么。
。
。
numa<=2;
numb<=numx-20;
elsifnumx>=10then--如果大于10,。
。
。
numa<=1;
numb<=numx-10;
else
numa<=0;
numb<=numx;
endif;
ifnumy>=20then
numc<=2;
numd<=numy-20;
elsifnumy>=10then
numc<=1;
numd<=numy-10;
else
numc<=0;
numd<=numy;
endif;
endprocess;
process(t)
variableshu:
integerrange0to9;
begin
ift(0)='1'thenshu:
=numa;
elsift
(1)='1'thenshu:
=numb;
elsift
(2)='1'thenshu:
=0;
elsift(3)='1'thenshu:
=0;
elsift(4)='1'thenshu:
=numc;
elseshu:
=numd;
endif;
ifhold='0'then
caseshuis----译码部分
when0=>duan<="0111111";
when1=>duan<="0000110";
when2=>duan<="1011011";
when3=>duan<="1001111";
when4=>duan<="1100110";
when5=>duan<="1101101";
when6=>duan<="1111101";
when7=>duan<="0000111";
when8=>duan<="1111111";
when9=>duan<="1101111";
whenothers=>duan<="0000000";
endcase;
else
ifclk_1h='1'then
duan<="0000000";
else
caseshuis
when0=>duan<="0111111";
when1=>duan<="0000110";
when2=>duan<="1011011";
when3=>duan<="1001111";
when4=>duan<="1100110";
when5=>duan<="1101101";
when6=>duan<="1111101";
when7=>duan<="0000111";
when8=>duan<="1111111";
when9=>duan<="1101111";
whenothers=>duan<="0000000";
endcase;
endif;
endif;
endprocess;
end;
下载结果:
引脚分配:
六.实验结果分析及遇到的难题
实验的开始,总是有点小问题,因为编写的程序有一点小小的不同,该程序就无法执行,所以总需要经过多次的修改,往复地测试,直到成功。
如刚开始出现紧急情况是,红灯亮且闪,显示数码管倒计时停止但数字不闪,改了之后程序总是编不过,最后通过紧急开关实现。
七、实验收获和体验
通过实训能够让我们更加熟悉的对其软件的操作外,减少一些细节的出错率。
最重要的是通过此次实验能让我们知道编写程序的基本语法与一些基本注意的地方。
同时能够从多次失败的结果总结出经验,编程的时候应该细心谨慎,通过自己动手,可以有自己理清思路,一点点地提高自己的程序编写能力。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 交通灯 报告