vhdl红绿灯实验.doc_第1页
vhdl红绿灯实验.doc_第2页
vhdl红绿灯实验.doc_第3页
vhdl红绿灯实验.doc_第4页
vhdl红绿灯实验.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

南北方向和东西方向的共六个颜色灯(红、黄、绿)按给定延迟时间循环点亮。东西方向通行30秒,南北方向通行30秒。选用2个七段码显示时间,进行倒计时。当时间到后,进行红黄绿灯显示切换。交通灯控制器的4个状态南北公路东西公路状态0 25秒绿红状态1 5秒红灯红+黄状态2 25秒红绿状态3 5秒红+黄红交通灯控制器的状态转换图library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity traffic_signal_light is port (clk:instd_logic;clr:instd_logic;rst:instd_logic; dig_sel_n:out std_logic_vector(7 downto 0);ewsn : out std_logic_vector(5 downto 0);dat_out:out std_logic_vector(7 downto 0);useless : out std_logic_vector(5 downto 0);end entity traffic_signal_light;architecture bhv of traffic_signal_light istype states is (S0,S1,S2,S3);signal current_state,next_state : states := S0; signal dig0,dig1,dig2,dig3 : std_logic_vector(7 downto 0);signal digSelectAddress : integer range 0 to 3;-当前将要显示数码管的地址控制线; signal data1: integer range 40 downto 0 ; -data = 送显示的时钟数字信号;signal data2 : integer range 40 downto 0 ;signal clock_1s : std_logic;signal clock_5ms: std_logic;-数码管的译码函数- - 形参 data :为要译码的数字,范围为:09; - 返回值 ledSegment :为译码好的七段数码管断码;function decode( data: integer range 0 to 9 )return std_logic_vector isvariable ledSegment: std_logic_vector(7 downto 0);beginCASE data ISWHEN 0 =ledSegment := 11000000;- 0xC0;0 WHEN 1 =ledSegment := 11111001;- 0xf9;1WHEN 2 =ledSegment := 10100100;- 0xa4;2WHEN 3 =ledSegment := 10110000;- 0xb0 3WHEN 4 =ledSegment := 10011001;- 0x99 4WHEN 5 =ledSegment := 10010010;- 0x92;5WHEN 6 =ledSegment := 10000010;- ox82;6WHEN 7 =ledSegment := 11111000;- 0xf8;7WHEN 8 =ledSegment := 10000000;- 0x80;8WHEN 9 =ledSegment := 10010000;- 0x90;9WHEN OTHERS =null; END CASE; return ledSegment;end decode;-begin -architecture useless = 111111;dig1 = decode(data1 /10 rem 10);dig0 = decode(data1 rem 10 );dig3 = decode(data2 /10 rem 10);dig2 ewsn = 110011;-rgif(data1 = 1 ) then next_state = S1 ;else next_state ewsn = 101011;-ryif(data1 = 1 ) then next_state = S2 ;else next_state ewsn = 011110;if( data1 = 5 ) then next_state = S3 ;else next_state ewsn = 011101;if( data1 = 1 ) then next_state = S0 ;else next_state = S3 ;end if ;end case ;end process Change_state;-时序进程-Reg : process(clock_1s,rst)beginif rst = 1 then current_state = S0;elsif (clock_1s = 1 and clock_1sevent) thencurrent_state = 10_000_000) thenclock_1s = 0;elseclock_1s = 1;end if;end if; end process Div_clock_1s; -25秒和5秒倒计时- -东西红路灯数码管倒计时- counter1 : process(clock_1s) variable data_60second : integer range 60 downto 1 ; begin if(clock_1sevent and clock_1s = 1)thenif( data1 = 0 ) thendata_60second := 60;data1 35 ) thendata1 30) thendata1 = (data_60second - 30 ) ;elsedata1 = data_60second;end if;end if;end if;end if;end process counter1; -南北红路灯数码管倒计时- counter2 : process(clock_1s) variable data_60second : integer range 60 downto 1 ; begin if(clock_1sevent and clock_1s = 1)thenif( data2 = 0 ) thendata_60second := 60;data2 30 ) thendata2 5) thendata2 = (data_60second - 5 ) ;else data2 = 50_000) thenclock_5ms = 0;elseclock_5ms = 1;end if;end if; end process Div_clock_5ms;-counter3 : process(clock_5ms) beginif(clock_5ms = 1 and clock_5msevent) thenif digSelectAddress = 3 thendigSelectAddress = 0;elsedigSelectAddress dig_s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论