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

📄 ps_change.vhd

📁 可以很好实现一个二进制转换成BCD码的程序
💻 VHD
字号:
-----------------------------------------------------------------------
--function :parallet in sereis out, high bit first in,first out;
--并串转换,保证n位数全部串行(左移位,高位在前)输出后,又输出了一次地位,再重新自动置数,再转换
--程序中有一个人为的延时,可以从仿真图中看出,每n位数串行输出后,又输出了一次最后一位(一个clk的时间),
--此后再重复(置数,转换)过程。
--!!!!必须修改n值才能得到后续程序需要的n位二进制数串行输出!!!!!
---------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity ps_change is
 generic (n : integer :=16                 --bits of parallet input
          );
 port(in_paral :in std_logic_vector(n-1 downto 0);--parallet input
      clk :in std_logic;
      out_series:out std_logic               --series  output 
      );
end entity;

architecture behave of ps_change is
 signal tmp : std_logic_vector(n-1 downto 0);
 signal load: integer range 0 to n;          --load=0则置数,否则移位输出
begin
process(clk,tmp)
 begin
 if(clk'event and clk='1') then
   if(load=0) then                           --load=0,置数
     tmp<=in_paral;
     load<=n;                                 --置需要移位的次数n     
   else                                      --load不等于0,移位输出
     out_series<=tmp(n-1);
     tmp(n-1 downto 1)<=tmp(n-2 downto 0);
     load<=load-1;                           --移位一次,load数减一
   end if;
 end if;
end process;      
end behave;

⌨️ 快捷键说明

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