vhdl语言里的cnt1:=(others=>‘1‘)是什么意思

本文介绍了VHDL中Others关键字的使用方法及其优势。通过一个具体的信号赋值示例,展示了如何利用Others实现对多位宽数据的统一初始化,并讨论了这种方式在位宽变化时的便利性。

来自:https://zhidao.baidu.com/question/34437388.html?qbl=relate_question_0&word=vhdl%20others

答复:

定义了一个多位宽数据cnt1:
singal cnt1: std_logic_vector(3 downto 0)
下面对他赋值:

cnt1 <= (others => '0');

表示的意思是
cnt1(3) <= '0';
cnt1(2) <= '0';
cnt1(1) <= '0';
cnt1(0) <= '0';

也可以写成
cnt1 <= "0000";

用OTHERS写法的好处是,不需要介意位宽,如果使用下面的方法,这样如果修改位宽为5位后,“0000”要改成“00000”,

而开始的写法则不用改。

library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity Counter_60 is Port ( clk_50m : in STD_LOGIC; -- 50MHz时钟 rst : in STD_LOGIC; -- 复位 dir : in STD_LOGIC; -- 计数方向 (1=递增, 0=递减) seg : out STD_LOGIC_VECTOR(7 downto 0); -- 七段码输出 an : out STD_LOGIC_VECTOR(1 downto 0) -- 数码管位选 ); end Counter_60; architecture Behavioral of Counter_60 is -- 时钟分频信号 signal clk_2hz : STD_LOGIC := '0'; signal clk_1k : STD_LOGIC := '0'; -- 计数器信号 signal cnt_ten : UNSIGNED(3 downto 0) := (others => '0'); signal cnt_unit : UNSIGNED(3 downto 0) := (others => '0'); -- 显示扫描信号 signal scan_cnt : INTEGER range 0 to 1 := 0; begin -- 时钟分频模块(50MHz -> 2Hz & 1kHz) process(clk_50m, rst) variable cnt2 : INTEGER := 0; variable cnt1 : INTEGER := 0; begin if rst = '1' then cnt2 := 0; cnt1 := 0; clk_2hz <= '0'; clk_1k <= '0'; elsif rising_edge(clk_50m) then -- 2Hz分频 (50MHz/25,000,000) if cnt2 = 12499999 then clk_2hz <= not clk_2hz; cnt2 := 0; else cnt2 := cnt2 + 1; end if; -- 1kHz分频 (50MHz/50,000) if cnt1 = 24999 then clk_1k <= not clk_1k; cnt1 := 0; else cnt1 := cnt1 + 1; end if; end if; end process; -- 60进制可逆计数器 process(clk_2hz, rst) begin if rst = '1' then cnt_ten <= (others => '0'); cnt_unit <= (others => '0'); elsif rising_edge(clk_2hz) then if dir = '1' then -- 递增模式 if cnt_unit = 9 then cnt_unit <= "0000"; if cnt_ten = 5 then cnt_ten <= "0000"; else cnt_ten <= cnt_ten + 1; end if; else cnt_unit <= cnt_unit + 1; end if; else -- 递减模式 if cnt_unit = 0 then cnt_unit <= "1001"; if cnt_ten = 0 then cnt_ten <= "0101"; else cnt_ten <= cnt_ten - 1; end if; else cnt_unit <= cnt_unit - 1; end if; end if; end if; end process; -- 动态扫描显示 process(clk_1k) begin if rising_edge(clk_1k) then scan_cnt <= scan_cnt + 1; if scan_cnt = 1 then scan_cnt <= 0; end if; end if; end process; -- 七段码译码器 process(scan_cnt, cnt_ten, cnt_unit) begin an <= "11"; -- 默认关闭所有数码管 case scan_cnt is when 0 => -- 显示十位 an <= "10"; case cnt_ten is when "0000" => seg <= "00111111"; -- 0 when "0001" => seg <= "00000110"; -- 1 when "0010" => seg <= "01011011"; -- 2 when "0011" => seg <= "01001111"; -- 3 when "0100" => seg <= "01100110"; -- 4 when "0101" => seg <= "01101101"; -- 5 when others => seg <= "00000000"; -- 灭 end case; when 1 => -- 显示个位 an <= "01"; case cnt_unit is when "0000" => seg <= "00111111"; -- 0 when "0001" => seg <= "00000110"; -- 1 when "0010" => seg <= "01011011"; -- 2 when "0011" => seg <= "01001111"; -- 3 when "0100" => seg <= "01100110"; -- 4 when "0101" => seg <= "01101101"; -- 5 when "0110" => seg <= "01111101"; -- 6 when "0111" => seg <= "00000111"; -- 7 when "1000" => seg <= "01111111"; -- 8 when "1001" => seg <= "01101111"; -- 9 when others => seg <= "00000000"; -- 灭 end case; when others => null; end case; end process; end Behavioral; 这些代码有什么问题吗,为什么输出到FPGA板上有六个数码管显示为横杠
05-12
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity counter_8bit is Port ( CLK : in STD_LOGIC; CNT_EN : in STD_LOGIC; F_IN : in STD_LOGIC; CLR : in STD_LOGIC; LOCK : in STD_LOGIC; Q_H : buffer STD_LOGIC_VECTOR (3 downto 0); Q_L : out STD_LOGIC_VECTOR (3 downto 0); H : out STD_LOGIC_VECTOR (6 downto 0); L : out STD_LOGIC_VECTOR (6 downto 0); COUT : out STD_LOGIC ); end counter_8bit; architecture Behavioral of counter_8bit is signal count : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); signal locked_count : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); -- 7段译码器函数 function seg7_decode (bcd : STD_LOGIC_VECTOR (3 downto 0)) return STD_LOGIC_VECTOR is variable seg : STD_LOGIC_VECTOR (6 downto 0); begin case bcd is when "0000" => seg := "0000001"; -- 0 when "0001" => seg := "1001111"; -- 1 when "0010" => seg := "0010010"; -- 2 when "0011" => seg := "0000110"; -- 3 when "0100" => seg := "1001100"; -- 4 when "0101" => seg := "0100100"; -- 5 when "0110" => seg := "0100000"; -- 6 when "0111" => seg := "0001111"; -- 7 when "1000" => seg := "0000000"; -- 8 when "1001" => seg := "0000100"; -- 9 when others => seg := "1111111"; -- 其他情况显示空白 end case; return seg; end function; begin -- 计数器逻辑 process(CLK) begin if rising_edge(CLK) then if CLR = '1' then count <= (others => '0'); elsif CNT_EN = '1' then if F_IN = '1' then if count = "11111111" then count <= (others => '0'); COUT <= '1'; else count <= count + 1; COUT <= '0'; end if; end if; end if; end if; end process; -- 锁存逻辑 process(CLK) begin if rising_edge(CLK) then if LOCK = '1' then locked_count <= count; end if; end if; end process; -- 输出逻辑 Q_H <= locked_count(7 downto 4); Q_L <= locked_count(3 downto 0); H <= seg7_decode(Q_H); L <= seg7_decode(locked_count(3 downto 0)); end Behavioral; Q_H,Q_L,H,L的值一直是恒定的,怎么改
10-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值