版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、南北方向和东西方向的共六个颜色灯(红、黄、绿)按给定延迟时间循环点亮。东西方向通行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_logi
2、c;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 cur
3、rent_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;sign
4、al 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 =>le
5、dSegment := "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&quo
6、t;- 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 <= de
7、code(data1 /10 rem 10);dig0 <= decode(data1 rem 10 );dig3 <= decode(data2 /10 rem 10);dig2 <= decode(data2 rem 10 ); -状态转换-Change_state : process(current_state) begin case current_state is when S0 => ewsn <= "110011"-rgif(data1 = 1 ) then next_state <= S1 ;else next_state
8、 <= S0 ;end if ;when S1 => ewsn <= "101011"-ryif(data1 = 1 ) then next_state <= S2 ;else next_state <= S1 ;end if ;when S2 => ewsn <= "011110"if( data1 = 5 ) then next_state <= S3 ;else next_state <= S2 ;end if ;when S3 => ewsn <= "011101&quo
9、t;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_1s'event) thencurrent_state <= next_state;end if; end
10、 process Reg; -分频器输出1s时钟给数码管的定时器-Div_clock_1s : process(clk) variable count :integer range 0 to 20_000_000 ;beginif(clk = '1' and clk'event) thenif count = 19_999_999 thencount:= 0;elsecount:= count +1;end if;if(count>= 10_000_000) thenclock_1s <= '0'elseclock_1s <= '
11、;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_1s'event and clock_1s = '1')thenif( data1 = 0 ) thendata_60second := 60;data1 <= 25;else data_60second := data_60s
12、econd - 1; if( data_60second > 35 ) thendata1 <= ( data_60second - 35 ) ;else if(data_60second > 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 : int
13、eger range 60 downto 1 ; begin if(clock_1s'event and clock_1s = '1')thenif( data2 = 0 ) thendata_60second := 60;data2 <= 30;else data_60second := data_60second - 1;if( data_60second > 30 ) thendata2 <= ( data_60second - 30 ) ;else if(data_60second > 5) thendata2 <= (data_6
14、0second - 5 ) ;else data2 <= data_60second;end if; end if;end if;end if;end process counter2; -数码管刷新频率产生进程-Div_clock_5ms : process(clk) variable count :integer range 0 to 100_000 ;beginif(clk = '1' and clk'event) thenif count = 99_999 thencount:= 0;elsecount:= count +1;end if;if(count
15、>= 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_5ms'event) thenif digSelectAddress = 3 thendigSelectAddress <= 0;elsedigSelectAddress <= digSelectAddress + 1;end if;end if; end process counter3;- show : process(digSelectAddress) begincase digSelectAddress iswhen 0 => dig_sel_n <= "11111110"dat_out <= dig0;w
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 陕西艺术职业学院《环境影响评价实验》2024-2025学年第二学期期末试卷
- 味精发酵工创新实践强化考核试卷含答案
- 毛笔制作工创新方法强化考核试卷含答案
- 架子工岗前实操水平考核试卷含答案
- 环己烷装置操作工操作能力知识考核试卷含答案
- 通信接入设备装调工安全理论考核试卷含答案
- 图案打样工岗前保密考核试卷含答案
- 玻璃表面改性加工工岗前履职考核试卷含答案
- 陶瓷施釉工创新意识知识考核试卷含答案
- 单板加工工冲突管理强化考核试卷含答案
- 2026年包头铁道职业技术学院单招职业适应性考试题库及参考答案详解(新)
- 女性职场健康 保健知识课件
- 河北保定市安新县2025-2026学年第一学期期末质量监测九年级数学试题(试卷+解析)
- 2026年春季人教版(PEP)三年级下册英语教学计划附教学进度表
- 特种设备质量安全风险日管控周排查月调度管理制度
- CMA质量手册(2025版)-符合27025、评审准则
- 饲料厂复工安全培训课件
- 研学旅行PPT模板
- 急性脑梗死的影像诊断
- 2023西南财经大学会计专硕复试经验
- YS/T 73-2011副产品氧化锌
评论
0/150
提交评论