实验五 交通灯控制的设计.docx
- 文档编号:24179215
- 上传时间:2023-05-25
- 格式:DOCX
- 页数:16
- 大小:23.10KB
实验五 交通灯控制的设计.docx
《实验五 交通灯控制的设计.docx》由会员分享,可在线阅读,更多相关《实验五 交通灯控制的设计.docx(16页珍藏版)》请在冰豆网上搜索。
实验五交通灯控制的设计
实验五交通灯控制器的设计
一实验目的
熟悉交通灯控制器的设计原理、了解其功能、掌握设计方法。
二实验设备
PC微机一台,TD-DS实验箱一台,TD-DS-MAXII扩展板一块。
三实验内容
利用VHDL语言和原理图混合的方法设计一个设计一个由一条主干道和一条支干道的汇合点形成的十字交叉路口的交通灯控制器,具体要求如下:
(1)主、支干道各设有一个绿、黄、红指示灯,两个显示数码管。
(2)主干道处于常允许通行状态,而支干道有车来才允许通行。
(3)当主、支道均有车时,两者交替允许通行,主干道每次放行45s,支干道每次放行25s,在每次由亮绿灯变成亮红灯的转换过程中,要亮5s的黄灯作为过渡,并进行减计时显示。
根据交通灯控制器功能设计要求,本系统可由以下6个模块组成:
☐45S计时模块CNT45S;
☐25S计时模块CNT25S;
☐05S计时模块CNT05S;
☐交通灯控制模块JTDKZ;
☐显示子模块XSKZ;
☐译码器模块YMQ。
四实验步骤
1.在D盘建立七个文件夹,JTDKZ、CNT45S、CNT25S、CNT05S、XSKZ、YMQ、JTDKZQSJ。
2.运行QuartusII软件,选择File..NewProjectWizard菜单建立一个新工程。
工程名称及顶层文件名称为JTDKZ,器件设置对话框中选择EPM240T100C5芯片,完成新工程的建立。
3.选择File..New菜单,创建VHDL描述语言设计文件,打开文本编辑器界面。
4.选择File..SaveAs菜单,将创建的VHDL设计文件保存为JTDKZ.VHD。
5.在文本编辑器界面中编写VHDL程序,代码如下:
--JTDKZ.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYJTDKZIS
PORT(CLK,SM,SB:
INSTD_LOGIC;
MR,MY,MG,BR,BY,BG:
OUTSTD_LOGIC);
ENDENTITYJTDKZ;
ARCHITECTUREARTOFJTDKZIS
TYPESTATE_TYPEIS(A,B,C,D);
SIGNALSTATE:
STATE_TYPE;
BEGIN
CNT:
PROCESS(CLK)IS
VARIABLES:
INTEGERRANGE0TO45;
VARIABLECLR,EN:
BIT;
BEGIN
IF(CLK'EVENTANDCLK='1')THEN
IFCLR='0'THEN
S:
=0;
ELSIFEN='0'THEN
S:
=S;
ELSE
S:
=S+1;
ENDIF;
CASESTATEIS
WHENA=>MR<='0';MY<='0';MG<='1';
BR<='1';BY<='0';BG<='0';
IF(SBANDSM)='1'THEN
IFS=45THEN
STATE<=B;CLR:
='0';EN:
='0';
ELSE
STATE<=A;CLR:
='1';EN:
='1';
ENDIF;
ELSIF(SBAND(NOTSM))='1'THEN
STATE<=B;CLR:
='0';EN:
='0';
ELSE
STATE<=A;CLR:
='1';EN:
='1';
ENDIF;
WHENB=>MR<='0';MY<='1';MG<='0';
BR<='1';BY<='0';BG<='0';
IFS=5THEN
STATE<=C;CLR:
='0';EN:
='0';
ELSE
STATE<=B;CLR:
='1';EN:
='1';
ENDIF;
WHENC=>MR<='1';MY<='0';MG<='0';
BR<='0';BY<='0';BG<='1';
IF(SMANDSB)='1'THEN
IFS=25THEN
STATE<=D;CLR:
='0';EN:
='0';
ELSE
STATE<=C;CLR:
='1';EN:
='1';
ENDIF;
ELSIFSB='0'THEN
STATE<=D;CLR:
='0';EN:
='0';
ELSE
STATE<=C;CLR:
='1';EN:
='1';
ENDIF;
WHEND=>MR<='1';MY<='0';MG<='0';
BR<='0';BY<='1';BG<='0';
IFS=5THEN
STATE<=A;CLR:
='0';EN:
='0';
ELSE
STATE<=D;CLR:
='1';EN:
='1';
ENDIF;
ENDCASE;
ENDIF;
ENDPROCESSCNT;
ENDARCHITECTUREART;
6.选择Tools..CompilerTool菜单,编译JTDKZ.VHD源文件。
(可选项:
编译无误后建立仿真波形文件JTDKZ.VWF。
选择Tools..SimulatorTool菜单进行仿真)。
选择File..Create/Update..CreateSymbolFileforCurrentFile菜单,为当前工程生成一个符号文件JTDKZ.BSF文件。
选择File..CloseProject菜单关闭工程JTDKZ。
重复上面的过程,建立CNT45S,最后为当前工程生成一个符号文件CNT45S.BSF文件。
--CNT45S.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT45SIS
PORT(SB,CLK,EN45:
INSTD_LOGIC;
DOUT45M,DOUT45B:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYCNT45S;
ARCHITECTUREARTOFCNT45SIS
SIGNALCNT6B:
STD_LOGIC_VECTOR(5DOWNTO0);
BEGIN
PROCESS(SB,CLK,EN45)IS
BEGIN
IFSB='0'THENCNT6B<=CNT6B-CNT6B-1;
ELSIF(CLK'EVENTANDCLK='1')THEN
IFEN45='1'THENCNT6B<=CNT6B+1;
ELSIFEN45='0'THENCNT6B<=CNT6B-CNT6B-1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CNT6B)IS
BEGIN
CASECNT6BIS
WHEN"000000"=>DOUT45M<="01000101";DOUT45B<="01010000";
WHEN"000001"=>DOUT45M<="01000100";DOUT45B<="01001001";
WHEN"000010"=>DOUT45M<="01000011";DOUT45B<="01001000";
WHEN"000011"=>DOUT45M<="01000010";DOUT45B<="01000111";
WHEN"000100"=>DOUT45M<="01000001";DOUT45B<="01000110";
WHEN"000101"=>DOUT45M<="01000000";DOUT45B<="01000101";
WHEN"000110"=>DOUT45M<="00111001";DOUT45B<="01000100";
WHEN"000111"=>DOUT45M<="00111000";DOUT45B<="01000011";
WHEN"001000"=>DOUT45M<="00110111";DOUT45B<="01000010";
WHEN"001001"=>DOUT45M<="00110110";DOUT45B<="01000001";
WHEN"001010"=>DOUT45M<="00110101";DOUT45B<="01000000";
WHEN"001011"=>DOUT45M<="00110100";DOUT45B<="01101001";
WHEN"001100"=>DOUT45M<="00110011";DOUT45B<="00111000";
WHEN"001101"=>DOUT45M<="00110010";DOUT45B<="00110111";
WHEN"001110"=>DOUT45M<="00110001";DOUT45B<="00110110";
WHEN"001111"=>DOUT45M<="00110000";DOUT45B<="00110101";
WHEN"010000"=>DOUT45M<="00101001";DOUT45B<="00110100";
WHEN"010001"=>DOUT45M<="00101000";DOUT45B<="00110011";
WHEN"010010"=>DOUT45M<="00100111";DOUT45B<="00110010";
WHEN"010011"=>DOUT45M<="00100110";DOUT45B<="00110001";
WHEN"010100"=>DOUT45M<="00100101";DOUT45B<="00110000";
WHEN"010101"=>DOUT45M<="00100100";DOUT45B<="00101001";
WHEN"010110"=>DOUT45M<="00100011";DOUT45B<="00101000";
WHEN"010111"=>DOUT45M<="00100010";DOUT45B<="00100111";
WHEN"011000"=>DOUT45M<="00100001";DOUT45B<="00100110";
WHEN"011001"=>DOUT45M<="00100000";DOUT45B<="00100101";
WHEN"011010"=>DOUT45M<="00011001";DOUT45B<="00100100";
WHEN"011011"=>DOUT45M<="00011000";DOUT45B<="00100011";
WHEN"011100"=>DOUT45M<="00010111";DOUT45B<="00100010";
WHEN"011101"=>DOUT45M<="00010110";DOUT45B<="00100001";
WHEN"011110"=>DOUT45M<="00010101";DOUT45B<="00100000";
WHEN"011111"=>DOUT45M<="00010100";DOUT45B<="00011001";
WHEN"100000"=>DOUT45M<="00010011";DOUT45B<="00011000";
WHEN"100001"=>DOUT45M<="00010010";DOUT45B<="00010111";
WHEN"100010"=>DOUT45M<="00010001";DOUT45B<="00010110";
WHEN"100011"=>DOUT45M<="00010000";DOUT45B<="00010101";
WHEN"100100"=>DOUT45M<="00001001";DOUT45B<="00010100";
WHEN"100101"=>DOUT45M<="00001000";DOUT45B<="00010011";
WHEN"100110"=>DOUT45M<="00000111";DOUT45B<="00010010";
WHEN"100111"=>DOUT45M<="00000110";DOUT45B<="00010001";
WHEN"101000"=>DOUT45M<="00000101";DOUT45B<="00010000";
WHEN"101001"=>DOUT45M<="00000100";DOUT45B<="00001001";
WHEN"101010"=>DOUT45M<="00000011";DOUT45B<="00001000";
WHEN"101011"=>DOUT45M<="00000010";DOUT45B<="00000111";
WHEN"101100"=>DOUT45M<="00000001";DOUT45B<="00000110";
WHENOTHERS=>DOUT45M<="00000000";DOUT45B<="00000000";
ENDCASE;
ENDPROCESS;
ENDARCHITECTUREART;
重复上面的过程,建立CNT25S,最后为当前工程生成一个符号文件CNT25S.BSF文件。
--CNT25S.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT25SIS
PORT(SB,SM,CLK,EN25:
INSTD_LOGIC;
DOUT25M,DOUT25B:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYCNT25S;
ARCHITECTUREARTOFCNT25SIS
SIGNALCNT5B:
STD_LOGIC_VECTOR(4DOWNTO0);
BEGIN
PROCESS(SB,SM,CLK,EN25)IS
BEGIN
IFSB='0'ORSM='0'THEN
CNT5B<=CNT5B-CNT5B-1;
ELSIF(CLK'EVENTANDCLK='1')THEN
IFEN25='1'THEN
CNT5B<=CNT5B+1;
ELSIFEN25='0'THEN
CNT5B<=CNT5B-CNT5B-1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CNT5B)IS
BEGIN
CASECNT5BIS
WHEN"00000"=>DOUT25B<="00100101";DOUT25M<="00110000";
WHEN"00001"=>DOUT25B<="00100100";DOUT25M<="00101001";
WHEN"00010"=>DOUT25B<="00100011";DOUT25M<="00101000";
WHEN"00011"=>DOUT25B<="00100010";DOUT25M<="00100111";
WHEN"00100"=>DOUT25B<="00100001";DOUT25M<="00100110";
WHEN"00101"=>DOUT25B<="00100000";DOUT25M<="00100101";
WHEN"00110"=>DOUT25B<="00011001";DOUT25M<="00100100";
WHEN"00111"=>DOUT25B<="00011000";DOUT25M<="00100011";
WHEN"01000"=>DOUT25B<="00010111";DOUT25M<="00100010";
WHEN"01001"=>DOUT25B<="00010110";DOUT25M<="00100001";
WHEN"01010"=>DOUT25B<="00010101";DOUT25M<="00100000";
WHEN"01011"=>DOUT25B<="00010100";DOUT25M<="00011001";
WHEN"01100"=>DOUT25B<="00010011";DOUT25M<="00011000";
WHEN"01101"=>DOUT25B<="00010010";DOUT25M<="00010111";
WHEN"01110"=>DOUT25B<="00010001";DOUT25M<="00010110";
WHEN"01111"=>DOUT25B<="00010000";DOUT25M<="00010101";
WHEN"10000"=>DOUT25B<="00001001";DOUT25M<="00010100";
WHEN"10001"=>DOUT25B<="00001000";DOUT25M<="00010011";
WHEN"10010"=>DOUT25B<="00000111";DOUT25M<="00010010";
WHEN"10011"=>DOUT25B<="00000110";DOUT25M<="00010001";
WHEN"10100"=>DOUT25B<="00000101";DOUT25M<="00010000";
WHEN"10101"=>DOUT25B<="00000100";DOUT25M<="00001001";
WHEN"10110"=>DOUT25B<="00000011";DOUT25M<="00001000";
WHEN"10111"=>DOUT25B<="00000010";DOUT25M<="00000111";
WHEN"11000"=>DOUT25B<="00000001";DOUT25M<="00000110";
WHENOTHERS=>DOUT25B<="00000000";DOUT25M<="00000000";
ENDCASE;
ENDPROCESS;
ENDARCHITECTUREART;
重复上面的过程,建立CNT05S,最后为当前工程生成一个符号文件CNT05S.BSF文件。
--CNT05S.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT05SIS
PORT(CLK,EN05M,EN05B:
INSTD_LOGIC;
DOUT5:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYCNT05S;
ARCHITECTUREARTOFCNT05SIS
SIGNALCNT3B:
STD_LOGIC_VECTOR(2DOWNTO0);
BEGIN
PROCESS(CLK,EN05M,EN05B)IS
BEGIN
IF(CLK'EVENTANDCLK='1')THEN
IFEN05M='1'OREN05B='1'THEN
CNT3B<=CNT3B+1;
ELSE
CNT3B<="000";
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CNT3B)IS
BEGIN
CASECNT3BIS
WHEN"000"=>DOUT5<="00000101";
WHEN"001"=>DOUT5<="00000100";
WHEN"010"=>DOUT5<="00000011";
WHEN"011"=>DOUT5<="00000010";
WHEN"100"=>DOUT5<="00000001";
WHENOTHERS=>--DOUT5<="00000000";
ENDCASE;
ENDPROCESS;
ENDARCHITECTUREART;
重复上面的过程,建立XSKZ,最后为当前工程生成一个符号文件XSKZ.BSF文件。
--XSKZ.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYXSKZIS
PORT(EN45,EN25,EN05M,EN05B:
INSTD_LOGIC;
AIN45M,AIN45B:
INSTD_LOGIC_VECTOR(7DOWNTO0);
AIN25M,AIN25B,AIN05:
INSTD_LOGIC_VECTOR(7DOWNTO0);
DOUTM,DOUTB:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYXSKZ;
ARCHITECTUREARTOFXSKZIS
BEGIN
PROCESS(EN45,EN25,EN05M,EN05B)IS
BEGIN
IFEN45='1'THEN
DOUTM<=AIN45M(7DOWNTO0);DOUTB<=AIN45B(7DOWNTO0);
ELSIFEN05M='1'THEN
DOUTM<=AIN05(7DOWNTO0);DOUTB<=AIN05(7DOWNTO0);
ELSIFEN25='1'THEN
DOUTM<=AIN25M(7DOWNTO0);DOUTB<=AIN25B(7DOWNTO0);
ELSIFEN05B='1'THEN
DOUTM<=AIN05(7DOWNTO0);DOUTB<=AIN05(7DOWNTO0);
ENDIF;
ENDPROCESS;
ENDARCHITECTUREART;
重复上面的过程,建立YMQ,最后为当前工程生成一个符号文件YMQ.BSF文件。
--YMQ.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYYMQIS
PORT(AIN4:
INSTD_LOGIC_VECTOR(3DOWNTO0);
DOUT7:
OUTSTD_LOGIC_VECTOR(6DOWNTO0));
ENDENTITYYMQ;
ARCHITECTUREARTOFYMQIS
BEGIN
PROCESS(AIN4)IS
BEGIN
CASEAIN4IS
WHEN"0000
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验五 交通灯控制的设计 实验 交通灯 控制 设计
![提示](https://static.bdocx.com/images/bang_tan.gif)