.用VHDL写出在DISP7-DISP3数码管上显示20413 2. 设计并生成一个随机数生成电路,每两秒生成一个0~999之间的随机数,并且在数码管DISP2-DISP0上显示生成的随机数。 3. 为系统设置一个复位键,复位后数码管DISP2~DISP0上显示”000”,2秒后生成并且显示随机数,并且使用复位键进行复位,

时间: 2024-02-03 20:12:36 浏览: 43
1. VHDL代码如下: ```vhdl library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity display is port( clk: in std_logic; -- 输入时钟信号 reset: in std_logic; -- 复位信号 data_in: in unsigned(15 downto 0); -- 输入数据 seg: out std_logic_vector(6 downto 0); -- 数码管段选信号 dig: out std_logic_vector(3 downto 0) -- 数码管位选信号 ); end entity; architecture behavior of display is signal cnt: integer range 0 to 4999 := 0; -- 计数器,用于分频 signal num: unsigned(3 downto 0) := (others => '0'); -- 当前显示的数码管 signal data_out: unsigned(3 downto 0); -- 当前显示的数值 begin process(clk, reset) is begin if reset = '1' then -- 复位 cnt <= 0; num <= (others => '0'); data_out <= (others => '0'); seg <= (others => '1'); dig <= "1110"; -- DISP3-DISP0 数码管关闭 elsif rising_edge(clk) then -- 时钟上升沿 if cnt = 4999 then -- 2秒计数 cnt <= 0; num <= num + 1; if num > 3 then num <= (others => '0'); end if; else cnt <= cnt + 1; end if; case num is -- 根据当前显示的数码管选择输出数值 when "0000" => data_out <= data_in(3 downto 0); dig <= "0111"; -- 选择 DISP7 数码管 when "0001" => data_out <= data_in(7 downto 4); dig <= "1011"; -- 选择 DISP6 数码管 when "0010" => data_out <= data_in(11 downto 8); dig <= "1101"; -- 选择 DISP5 数码管 when "0011" => data_out <= data_in(15 downto 12); dig <= "1110"; -- 选择 DISP4 数码管 end case; end if; end process; seg <= "0111111" when data_out = 0 else -- 数值为0时显示0 "0000110" when data_out = 1 else "1011011" when data_out = 2 else "1001111" when data_out = 3 else "1100110" when data_out = 4 else "1101101" when data_out = 5 else "1111101" when data_out = 6 else "0000111" when data_out = 7 else "1111111" when data_out = 8 else "1101111" when data_out = 9; -- 根据数值选择不同的段选信号 end architecture; ``` 2. 随机数生成电路的VHDL代码如下: ```vhdl library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity random_generator is port( clk: in std_logic; -- 输入时钟信号 reset: in std_logic; -- 复位信号 data_out: out unsigned(9 downto 0) := (others => '0') -- 输出随机数 ); end entity; architecture behavior of random_generator is signal cnt: integer range 0 to 49999999 := 0; -- 计数器,用于分频 signal seed: unsigned(9 downto 0) := (others => '0'); -- 随机数种子 begin process(clk, reset) is variable temp: unsigned(9 downto 0); begin if reset = '1' then -- 复位 cnt <= 0; seed <= (others => '0'); data_out <= (others => '0'); elsif rising_edge(clk) then -- 时钟上升沿 if cnt = 49999999 then -- 2秒计数 cnt <= 0; temp := seed xor (seed(2) xor seed(6)); seed <= temp; data_out <= temp; else cnt <= cnt + 1; end if; end if; end process; end architecture; ``` 3. 系统的VHDL代码如下: ```vhdl library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity system is port( clk: in std_logic; -- 输入时钟信号 reset: in std_logic; -- 复位信号 data_in: in unsigned(15 downto 0); -- 输入数据 disp: out std_logic_vector(20 downto 0) := (others => '1'); -- 数码管显示 key: in std_logic -- 复位键 ); end entity; architecture behavior of system is signal num: unsigned(3 downto 0) := (others => '0'); -- 当前显示的数码管 begin display_inst: entity work.display port map( clk => clk, reset => reset, data_in => data_in, seg => disp(6 downto 0), dig => disp(20 downto 16) ); random_generator_inst: entity work.random_generator port map( clk => clk, reset => reset or key, -- 使用复位键进行复位 data_out => disp(13 downto 4) ); process(clk, reset) is begin if reset = '1' then -- 复位 num <= (others => '0'); disp(3 downto 0) <= "0000"; disp(20 downto 4) <= (others => '1'); elsif rising_edge(clk) then -- 时钟上升沿 if key = '1' then -- 复位键按下 num <= (others => '0'); disp(3 downto 0) <= "0000"; wait for 2 sec; disp(20 downto 4) <= (others => '1'); else if num = "0011" then -- 显示完最后一个数码管后等待2秒 wait for 2 sec; end if; num <= num + 1; end if; end if; end process; end architecture; function sec2time(constant sec: integer) return time is begin return sec * 1 sec; end function; -- 定义将秒转换为时间的函数 ```

相关推荐

最新推荐

recommend-type

VHDL课程设计--万年历,课程设计报告。包括各个模块的代码及仿真图

设计一个万年历系统,通过数码管显示。 1) 显示分钟、小时,秒通过一个LED来进行闪烁显示。 2) 可设置时间,通过按键进行设置,设置方式可采用增加或者减小来进行显示; 3) 显示年、月、日等,通过按键进行显示...
recommend-type

基于VHDL语言的按键消抖电路设计及仿真

用VHDL语言编程的有限状态机的设计方法来实现按键的消抖,经仿真分析和下载实现,这种方法设计的消抖电路能够很好地实现电路功能,进行快速按键时都能保证每按一次做一次的响应,且性能稳定。
recommend-type

基于VHDL语言的8位RISC-CPU设计

基于VHDL的RISC设计 在现代电路设计中,经常需要嵌入特定功能的CPU。在FPGA中实现这样的CPU,具有高速、灵活等优点。RISC是最通用的处理器结构,...本论文拟利用VHDL语言,完成一种简易的RISC的设计,并利用FPGA实现。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、