⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiaotongdeng.txt.txt

📁 湖南科技大学计算机科学与工程学院的交通灯实验源码
💻 TXT
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

package traffic_package is
   	type color is(green,yellow,red);
   	type state is(highway_light_green,highway_light_yellow,
                  farmroad_light_green,farmroad_light_yellow);
	end traffic_package;

use work.traffic_package.all;

	entity traffic_light_controller is
    	generic(long_time:time;short_time:time);
    	port(car_on_farmroad:in boolean;
        	highway_light:out color;
        	farmroad_light:out color);
    end traffic_light_controller;
architecture behavior of traffic_light_controller is
  	signal present_state:state:=highway_light_green;
  	signal time_out_long:boolean:=false;
 	signal time_out_short:boolean:=false;
  	signal start_timer:boolean:=false;
   begin
   	control_process:
    	process(car_on_farmroad,time_out_long,time_out_short)
        	begin
         	case present_state is
           		when highway_light_green=>
            	if car_on_farmroad and time_out_long then
               		start_timer:=not start_timer;
               	present_state<=highway_light_yellow;
            	end if;
         		when highway_light_yellow=>
         		if time_out_short then
           			start_timer:=not start_timer;

               	present_state<=farmroad_light_green;
         		end if;
         		when farmroad_light_green=>
         		if not car_on_farmroad or time_out_long then
           			start_timer:=not start_timer;
         	 		present_state<=farmroad_light_yellow;
         		end if;
         		when farmroad_light_yellow=>
         		if time_out_short then
            		start_timer:=not start_timer;
         			present_state<=highway_light_green;
         		end if;
		end case;
	end process;
highway_light_set:
	with present_state select
    	highway_light<=green when highway_light_green;
                       yellow when highway_light_yellow;
                       red when farmroad_light_green or farmroad_light_yellow;
farmroad_light_set:
    with present_state select
        farmroad_light<=green when farmroad_ligh_green;
                        yellow when farmroad_light_yellow;
                        red when highway_ligh_green or
                        highway_light_yellow;
time_process:
	process(start_timer)
   		begin
    		time_out_long<=false,true after long_time;
     	    time_out_short<=false,true after short_time;
   	end process;
end behavior;
       

             
package traffic_package is
	type color is(green,yellow,red); 
    type state is(highway_ligh_green,highway_light_yellow,farmroad_light_green,farmroad_light_yellow);
end traffic_package;
use work.traffic_package.all;
     entity e_traffic_con is
            generic(long_time:time:=80.0 ns;
                     short_time:time:=40.0 ns);
            port(
                   car_on_farmroad:in boolean;
                   highway_light:out color;
                   farmroad_light:out color
                 );
           end e_traffic_con;
 

  architecture e_traffic_con of e_traffic_con is
      signal present_state:state:=highway_light_green;
      signal time_out_long:boolean:=false;
      signal time_out_short:boolean:=false;
      signal start_timer:boolean:false;
  begin
        control_process:
          process(car_on_farmroad,time_out_long,time_out_short)
          begin
            case present_state is
            when highway_light_green=>
               if car_on_farmroad and time_out_long then
               start_timer<=not start_timer;
               present_state<=highway_light_yellow;
               end if;
            when farmroad_light_green=>
               if not car_on_farmroad or time_out_long then
                 start_timer<=not start_timer;
                 present_state<=farmroad_ligh_yellow;
               end if;
            when farmroad_light_yellow=>
               if time_out_short then
                  start_timer<=not start_timer;
                  present_state<=highway_light_green;
               end if;
             end case;
             end process;
             highway_light_set;
               with present_state select
               highway_light<=green when highway_light_green,
                              yelliow when highway_light_yellow,
                              red when farmroad_light_green|farmroad_light_yellow;
                   farmroad_light_set:
          with present_state select
               farmroad_light<=green when farmroad_light_green,
                               yellow when farmroad_light_yellow,
                               red when highway_ligh_green|highway_light_yellow;
          time_process:
				process(start_timer)
					begin
						time_out_long<=false,true after long_time;
						time_out_short<=false,true after short_time;
				end process;

use work.traffic_package.all;
entity e_traffic_con_tb is
	generic(
		long_time:time:=80.0 ns;
		short_time:time:=40.0 ns
end e)traffic_con_tb;

architecture tb_architecture of e_traffic_con_tb is
	component e_traffic_con
	generic(
		long_time:time:=80.0 ns;
		short_time:time:=40.0 ns
	port(
		car_on_farmroad:in boolean;
		highway_light:out color;
		farmroad_light:out color);
	end component		
		signal car_on_farmroad:boolean;
		signal highway_light:color;
		signal farmroad_light:color;
	begin
		UUT:e_traffic_con
			port map
				(car_on_farmroad=>car_on_farmroad,
				highway_light=>highway_light,
				farmroad_light=>farmroad_light);
			car_on_farmroad<=false,true after 50 ns,false after 300 ns,true after 400 ns,
			false after 600 ns;
end tb_architecture;

configuation TESTBENCH_FOR_e_traffic_con of e_traffic_con_tb is
	for tb_architecture
		for UUT:e_traffic_con
			use entity work.e_traffic_con(e_traffic_con);
		end for;
	end for;
end TESTBENCH_FOR_e_traffic_con;	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -