交通灯的设计
1 课程设计的目的:
可编程器件与VHDL语言课程设计是本课程重要的实践性教学环节,是对程序设计语言技术掌握的应用性综合性实践训练。这种训练以通过独立进行某一课题的设计、仿真、安装、调试来具体完成,课程设计的主要目的体现在:
①熟悉系统的分析和设计方法;
②掌握合理选用集成电路的方法;
③熟悉protel 99 se设计仿真的方法;
④熟悉交通灯系统开发、设计、制作的技术流程;
⑤加强电路制版能力的锻炼,提高电路布局、布线以及检查和排除电路故障的能力;
⑥培养正确选择和运用测试仪器对系统性能正确测试的能力;
⑦培养撰写综合设计报告的能力;
⑧培养严肃认真的工作态度和团队的协作精神。
2 课题介绍:
交通灯广泛使用于十字路口,具有交替转换红·黄·绿的功能,且能够倒计时显示,路口交通灯控制系统的东西路有交通灯R(红)、Y(黄)、G(绿), 南北路有交通灯: r1(红)、y1(黄)、g1(绿)。有两组数码管作为东西和南北方向的倒计时显示, 显示时间为红灯25S, 绿灯20S, 黄灯5S。
设计要求:
①具有红·黄·绿交替转换功能;
②具有倒计时显示功能;
③红黄绿点亮时间为25S.5S.20S;
3 方案论证
4.1.1设计交通灯主模块程序: 考虑简便易行我们只制作了东西一个方向的交通灯,
程序如下:ibrary ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cont is
port(clk:in std_logic; r,g,y:out std_logic;
th:out std_logic_vector(4 downto 0));
end cont;
architecture cont1 of cont is
type rgy is(yellow,green,red);
begin
process(clk)
variable a:std_logic;
variable th1:std_logic_vector(4 downto 0);
variable state:rgy;
begin
if(clk'event and clk='1')then
case state is
when green=>if(a='0')then
th1:="10100"; a:='1';g<='1';r<='0';
else
if not(th1="00000")then
th1:=th1-1;
else a:='0';state:=yellow;
end if;
end if;
when red=> if(a='0')then
th1:="11001";a:='1';r<='1';y<='0';
else
if not(th1="00000")then
th1:=th1-1;
else
a:='0';state:=green;
end if;
end if;
when yellow=>if(a='0')then
th1:="00101";a:='1';y<='1';g<='0';
else
if not(th1="00000")then
th1:=th1-1;
else
a:='0';state:=red;
end if;
end if;
end case;
end if;
th<=th1;
end process;
end cont1;
4.1.2显示模块程序
library ieee;
use ieee.std_logic_1164.all;
entity leddx is
port(a:in std_logic_vector(4 downto 0);
led7s:out std_logic_vector(13 downto 0));
end;
architecture one of leddx is
begin
process(a)
begin
case a(4 downto 0) is
when"00000"=>led7s<="01111110111111";
when"00001"=>led7s<="01111110000110";
when"00010"=>led7s<="01111111011011";
when"00011"=>led7s<="01111111001111";
when"00100"=>led7s<="01111111100110";
when"00101"=>led7s<="01111111101101";
when"00110"=>led7s<="01111111111101";
when"00111"=>led7s<="01111110000111";
when"01000"=>led7s<="01111111111111";
when"01001"=>led7s<="01111111101111";
when"01010"=>led7s<="00001100111111";
when"01011"=>led7s<="00001100000110";
when"01100"=>led7s<="00001101011011";
when"01101"=>led7s<="00001101001111";
when"01110"=>led7s<="00001101100110";
when"01111"=>led7s<="00001101101101";
when"10000"=>led7s<="00001101111101";
when"10001"=>led7s<="00001100000111";
when"10010"=>led7s<="00001101111111";
when"10011"=>led7s<="00001101101111";
when"10100"=>led7s<="10110110111111";
when"10101"=>led7s<="10110110000110";
when"10110"=>led7s<="10110111011011";
when"10111"=>led7s<="10110111001111";
when"11000"=>led7s<="10110111100110";
when"11001"=>led7s<="10110111101101";
when"11010"=>led7s<="10110111111101";
when"11011"=>led7s<="10110110000111";
when"11100"=>led7s<="10110111111111";
when"11101"=>led7s<="10110111101111";
when others=>null;
end case;
end process;
end ;