数字电路与系统设计--vhdl代码总结

数电代码总结

decoder3-8

library ieee;
use ieee.std_logic_1164.all;

entity decoder38 is
port(
	A2,A1,A0 : in std_logic;
	yout : out std_logic_vector(7 downto 0) 
	
);
end entity;

architecture decoder of decoder38 is
signal cinA : std_logic_vector(2 downto 0);
begin
	cinA <= A2&A1&A0 ;
	yout <="01111111" when cinA ="000" else
				 "10111111" when cinA ="001" else
				 "11011111" when cinA ="010" else
				 "11101111" when cinA ="011" else
				 "11110111" when cinA ="100" else
				 "11111011" when cinA ="101" else
				 "11111101" when cinA ="110" else
				 "11111110" when cinA ="111" else
				 "ZZZZZZZZ";

end decoder;

mux41bus

library ieee;
use ieee.std_logic_1164.all;

entity mux41bus is
port(
	A : in std_logic_vector(7 downto 0) ;
	B : in std_logic_vector(7 downto 0) ;
	C : in std_logic_vector(7 downto 0) ;
	D : in std_logic_vector(7 downto 0) ;
	SEL1 : in std_logic;
	SEL0 : in std_logic;
	Yout : out std_logic_vector(7 downto 0) 
);
end entity;

architecture mux41 of mux41bus is
signal cins : std_logic_vector(1 downto 0);
begin
	cins <= SEL1&SEL0 ;
	with cins select
	Yout <= A when "00",
			  B when "01",
			  C when "10",
			  D when "11",
			  "ZZZZZZZZ" when others;
end mux41;

priencoder83

-----------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity priencoder83 is
port(
	Indata : in std_logic_vector(7 downto 0) ;
	Yout   : out std_logic_vector(2 downto 0) 
);
end entity;
-----------------------------------------------------
architecture rtl of priencoder83 is

begin
	Yout <= "000" when Indata(0) = '0' else
			"001" when Indata(1) = '0' else
			"010" when Indata(2) = '0' else
			"011" when Indata(3) = '0' else
			"100" when Indata(4) = '0' else
			"101" when Indata(5) = '0' else
			"110" when Indata(6) = '0' else
			"111" when Indata(7) = '0' else
			"ZZZ";
end rtl;
-------------------------------------------------------

halfadd

-----------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity halfadd is
port(
	a,b : in std_logic ;
    s,c : out std_logic
);
end entity;
-----------------------------------------------------
architecture halfadd01 of halfadd is

begin
    s <= a xor b;
    c <= a and b;
end halfadd01;
-------------------------------------------------------

fulladd01

-----------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity fulladd01 is
port(
	A,B     : in std_logic ;
	cin     : in std_logic ;
    sum,co  : out std_logic
);
end entity;
-----------------------------------------------------
architecture rtl of fulladd01 is
component halfadd is 
port (
    a,b : in std_logic ;
    s,c : out std_logic  
);
end component halfadd;

signal temp_c: std_logic_vector(1 downto 0);
signal temp_s: std_logic;

begin
    u0: halfadd port map(a=>A,b=>B,s=>temp_s,c=>temp_c(0));
    u1: halfadd port map(a=>cin,b=>temp_s,s=>sum,c=>temp_c(1));
    co<=temp_c(0) or temp_c(1); 
end rtl;
-------------------------------------------------------

fulladd02

-----------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity fulladd02 is
port(
	A,B     : in std_logic ;
	cin     : in std_logic ;
   sum,co  : out std_logic
);
end entity;
-----------------------------------------------------
architecture rtl of fulladd02 is
begin
    sum <= A xor B xor cin;
	co <=( A and B ) or ((A xor B) and cin);
	 
end rtl;
-------------------------------------------------------

add4bit_vhd

-----------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity add4bit_vhd is
port(
	CINA	   : in  std_logic_vector(3 downto 0);
	CINB       : in  std_logic_vector(3 downto 0);
    COUTS      : out std_logic_vector(3 downto 0)
);
end entity;
-----------------------------------------------------
architecture rtl of add4bit_vhd is
component fulladd01 is
port(
		A,B     : in std_logic ;
		cin     : in std_logic ;
		sum,co  : out std_logic
); 
end component fulladd01;
signal temp_co:std_logic_vector(3 downto 0);
begin
    u0:fulladd01 port map (A=>CINA(0),B=>CINB(0),cin=>'0',         sum=>COUTS(0),co=>temp_co(0));
	u1:fulladd01 port map (A=>CINA(1),B=>CINB(1),cin=>temp_co(0),sum=>COUTS(1),co=>temp_co(1));
	u2:fulladd01 port map (A=>CINA(2),B=>CINB(2),cin=>temp_co(1),sum=>COUTS(2),co=>temp_co(2));
	u3:fulladd01 port map (A=>CINA(3),B=>CINB(3),cin=>temp_co(2),sum=>COUTS(3),co=>temp_co(3));
end rtl;
-------------------------------------------------------

decoder47

library ieee;
use ieee.std_logic_1164.all;
----------------------------------
entity decoder47 is
 port (bcd: in  std_logic_vector(3 downto 0);
      led: out std_logic_vector(6 downto 0));
 end;
----------------------------------
architecture bhv of decoder47 is
begin
 process(bcd)
 begin
   case bcd is
     when"0000"=>led<="0111111";
     when"0001"=>led<="0000110";
     when"0010"=>led<="1011011";
     when"0011"=>led<="1001111";
     when"0100"=>led<="1100110";
     when"0101"=>led<="1101101";
     when"0110"=>led<="1111101";
     when"0111"=>led<="0000111";
     when"1000"=>led<="1111111";
     when"1001"=>led<="1100111";
     when others=>led<="0000000";
   end case;
 end process;
end bhv;

NbitShift

N 位串行移位寄存器

library ieee;                        -- 注意:library
use ieee.std_logic_1164.all;         --注意:_1164.all

entity NbitShift005 is 
    generic (N:integer := 4);
port(
    clk : in  std_logic ;
    Din : in  std_logic ;
    Qout: out std_logic
);
end NbitShift005;

architecture RTL of NbitShift005 is 
signal  Dreg : std_logic_vector(N-1 downto 0 ) ;
begin
    process(clk)
    begin                            --注意:这里别忘了begin
        if clk'event and clk='1' then
            Dreg(0)<=Din;
            Qout<=Dreg(N-1);
            for i in 0 to N-2 loop 
                Dreg(i+1)<=Dreg(i);
            end loop;
        end if;
    end process;
end RTL;

GenSignal

生成信号

library ieee;
use ieee.std_logic_1164.all;

entity GenSignal005 is 
port(
    clk  : in std_logic;
    Yout : out std_logic 
);
end GenSignal005;

architecture RTL of GenSignal005 is
    signal Dreg:std_logic_vector(3 downto 0);
begin
    process(clk)
    begin
        if clk'event and clk='1' then
            dreg(0)<=(dreg(2) xor dreg(3)) or ((not dreg(0))and(not dreg(1))and(not dreg(2))and(not dreg(3)));
            dreg(1)<=dreg(0);
            dreg(2)<=dreg(1);
            dreg(3)<=dreg(2);
        end if;
		  Yout<=dreg(3);
    end process;
end RTL;

BiShift

双向移位寄存器

library ieee;
use ieee.std_logic_1164.all;
entity BiShift005 is 
port(
    clk,clr,load,dir : in std_logic;
    Din              : in std_logic_vector(7 downto 0);
    Qout             : out std_logic_vector(7 downto 0)
);
end BiShift005;
architecture RTL of BiShift005 is
signal Dreg:std_logic_vector(7 downto 0);
begin
    Qout<=Dreg;
    process(clk,clr)
    begin
        if clr='0' then Dreg<="00000000"; 			    --异步清零 
        elsif clk'event and clk='1' then 
            if load='0' then  							--同步装载
                Dreg<=Din;
            elsif dir='0'  then 						--循环左移
                for i in 0 to 6 loop 
                    Dreg(i+1)<=Dreg(i);
                end loop;
                Dreg(0)<=Dreg(7); 
            else              							--循环右移
                for i in 0 to 6 loop 
                    Dreg(i)<=Dreg(i+1);
                end loop;
                Dreg(7)<= Dreg(0);  
            end if ;          
        end if ;         
    end process;      
end RTL;

BiCNT6Bit

6 为二进制计数器

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity BiCNT6Bit005 is         ---005 改成学号
port(
    CLR005,UPDN005,CLK005,EN005 :in  std_logic;    ---005 改成学号
    Qf,Qe,Qd,Qc,Qb,Qa           :out std_logic
);
end entity;

architecture Xiaozhuge of  BiCNT6Bit005 is          ---005 改成学号
signal CNT : std_logic_vector(5 downto 0) ;
begin
    Qf<=CNT(5);Qe<=CNT(4);Qd<=CNT(3);Qc<=CNT(2);Qb<=CNT(1);Qa<=CNT(0);
    process(CLK005,CLR005)
    begin
        if CLR005='1' then CNT<="000000";
        elsif CLK005'event and CLK005='1' then  
            if EN005='0' then CNT<=CNT;
            else 
                if UPDN005='1' then CNT<=CNT+'1';
                else CNT<=CNT-'1';
                end if;
            end if;
        end if;
    end process;
end Xiaozhuge;

DivFreq

分频器,CLK 是时钟输入,f1 和 f2 是分频器的输出信号。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity DivFreq005 is ---005 改成学号
port(
    clk005            :in  std_logic;
    f1out005,f2out005 :out std_logic
);
end entity;

architecture Xiaozhuge of  DivFreq005 is
signal  cnt1 :integer  range 0 to 7;
signal  cnt2 :integer  range 0 to 127;
begin
    process(clk005)                         --计数
    begin 
        if clk005'event and clk005='1' then
            if cnt1=4 then cnt1<=0;
            else cnt1<=cnt1+1;
            end if;
        end if;

        if clk005'event and clk005='1' then
            if cnt2=123 then cnt2<=0;
            else cnt2<=cnt2+1;
            end if;
        end if;   
    end process;

    process(cnt1)
    begin
        case cnt1 is                         -- case语句
            when 0 to 3 => f1out005<='0';
            when 4 to 4=> f1out005<='1';     --这里很有意思:4-4和4 有区别
            when others => f1out005<='0';
        end case;
    end process;

    process(cnt2)
    begin
        case cnt2 is                         -- case语句
            when 0 to 108 =>  f2out005<='0';
            when 109 to 123 => f2out005<='1';
            when others => f2out005<='0';
        end case;
    end process;
    
end Xiaozhuge;

BCD60

满足时钟设计的秒信号和分钟信号的计数要求,采用 BCD 表

示个位和十位,计数周期为 60,从 00 计数到 59。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity BCD60005 is
port(
    CLK,EN,RST : in  std_logic;
    COUT005    : out std_logic;
    BCDH005,BCDL005 : out std_logic_vector(3 downto 0)
);
end entity;

architecture Xiaozhuge of  BCD60005 is
signal cnth,cntl : std_logic_vector(3 downto 0); --计数
signal colh : std_logic;
begin
    BCDH005<=cnth;
    BCDL005<=cntl;
 ----------------------------------------------------------   
    process(clk,RST) 
    begin
        if RST='1' then cntl<="0000"; --异步清零 colh
        elsif clk'event and clk='1' then 
            if EN='1' then
                if cntl="1001" then cntl<="0000";--计数0-9 
                else cntl<=cntl+'1';
                end if;
            end if;
        end if ;
    end process;
--------------------------------------------------------------
colh<='1' when cntl="1001" else '0';
----------------------------------------------------------------
    process(clk,RST) 
    begin
        if RST='1' then cnth<="0000"; --异步清零 coth
        elsif clk'event and clk='1' then 
            if colh='1' then
                if cnth="0101" then cnth<="0000";--计数0-5 
                else cnth<=cnth+'1';
                end if;
            end if;
        end if ;
    end process;
    COUT005<='1' when cnth="0101" and cntl="1001"
                else '0';

end Xiaozhuge;

BCD24

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity BCD24005 is
port(
    CLK,EN,RST : in  std_logic;
    COUT005    : out std_logic;
    BCDH005,BCDL005 : out std_logic_vector(3 downto 0)
);
end entity;

architecture Xiaozhuge of  BCD24005 is
signal sh,sl : std_logic_vector(3 downto 0); --计数
signal colh : std_logic;
begin
    BCDH005<=sh;
    BCDL005<=sl;
    process(clk,RST)
    begin 
        if RST='1' then sh<="0000";sl<="0000";
        elsif clk'event and clk='1' then
            if en='1' then 
                if sh="0000" or sh="0001" then
                    if sl="1001" then sl<="0000";sh<=sh+'1';--个位计数0-9
                    else sl<=sl+'1';
                    end if;
                elsif sh="0010"  then
                    if sl="0011" then sl<="0000";sh<="0000";--个位计数0-3 注意sh清零
                    else sl<=sl+'1';
                    end if; 
                end if;
            end if;
        end if;
    end process;
    COUT005<='1' when sh="0010" and sl="0011"
                else '0';
end Xiaozhuge;

CheckSeq005

library ieee;
use ieee.std_logic_1164.all;

entity CheckSeq005 is

	port(
		CLK005		 : in	std_logic;
		Xin005	    : in	std_logic;
		nRST005	    : in	std_logic;
		Zout	   : out	std_logic
	);

end entity;

architecture rtl of CheckSeq005 is

	-- Build an enumerated type for the state machine
	type state_type is (A,B,C,D,E,F);

	-- Register to hold the current state
	signal state   : state_type;

begin

	-- Logic to advance to the next state
	process (CLK005, nRST005)
	begin
		if nRST005 = '1' then
			state <= A;
		elsif (rising_edge(CLK005)) then
			case state is
				when A=>
					if Xin005 = '1' then
						state <= B;
					else
						state <= A;
					end if;
				when B=>
					if Xin005 = '1' then
						state <= C;
					else
						state <= A;
					end if;
				when C=>
					if Xin005 = '0' then
						state <= D;
					else
						state <= C;
					end if;
				when D =>
					if Xin005 = '1' then
						state <= E;
					else
						state <= A;
					end if;
				when E =>
					if Xin005 = '0' then
						state <= F;
					else
						state <= C;
					end if;
				when F =>
					if Xin005 = '0' then
						state <= A;
					else
						state <= B;---注意F再次输入1 应到状态B
					end if;
			end case;
		end if;
	end process;

	-- Output depends solely on the current state
	process (state)
	begin
		case state is
			when A =>
				Zout <= '0';
			when B =>
				Zout <= '0';
			when C =>
				Zout <= '0';
			when D =>
				Zout <= '0';
			when E =>
				Zout <= '0';
			when F =>
				Zout <= '1';
		end case;
	end process;

end rtl;

GenSeq005

library ieee;
use ieee.std_logic_1164.all;

entity GenSeq005 is

	port(
		CLK005		 : in	std_logic;
		nRST005	 : in	std_logic;
		Yout	 : out	std_logic
	);

end entity;

architecture rtl of GenSeq005 is

	-- Build an enumerated type for the state machine
	type state_type is (A,B,C,D,E,F,G,H,I,J);

	-- Register to hold the current state
	signal state   : state_type;

begin

	-- Logic to advance to the next state
	process (CLK005)
	begin
		if (rising_edge(CLK005)) then
			case state is
				when A=>
					if nRST005 = '1' then state <= B;
					else                  state <= J;
					end if;
				when B=>
					if nRST005 = '1' then state <= C;
					else                  state <= J;
					end if;
				when C=>
					if nRST005 = '1' then state <= D;
					else                  state <= J;
					end if;
				when D=>
					if nRST005 = '1' then state <= E;
					else                  state <= J;
					end if;
				when E=>
					if nRST005 = '1' then state <= F;
					else                  state <= J;
					end if;
				when F=>
					if nRST005 = '1' then state <= G;
					else                  state <= J;
					end if;
				when G=>
					if nRST005 = '1' then state <= H;
					else                  state <= J;
					end if;
				when H=>
					if nRST005 = '1' then state <= I;
					else                  state <= J;
					end if;
				when I=>
					if nRST005 = '1' then state <= A;
					else                  state <= J;
					end if;
				when J=>
					if nRST005 = '1' then state <= A;
					else                  state <= J;
					end if;
			end case;
		end if;
	end process;

	-- Output depends solely on the current state
	process (state)
	begin
		case state is
			when A => Yout <= '0';
			when B => Yout <= '1';
			when C => Yout <= '0';
			when D => Yout <= '1';
			when E => Yout <= '1';
			when F => Yout <= '0';
			when G => Yout <= '1';
			when H => Yout <= '1';
			when I => Yout <= '1';
			when J => Yout <= '0';
		end case;
	end process;

end rtl;

LEDLight005

library ieee;
use ieee.std_logic_1164.all;

entity LEDLight005 is 
port(
    CLK005,SEL1005,SEL0005: in  std_logic ;
    LED                   : out std_logic_vector(7 downto 0)
);
end entity;

architecture rtl of LEDLight005 is 
signal   temp_led :std_logic_vector(7 downto 0);
begin 
    LED<=temp_led;
    process(CLK005,SEL1005,SEL0005)
    begin
        if CLK005'event and  CLK005='1' then
            if    SEL0005='0'and SEL1005='0' then
                 temp_led<="00000000";
            elsif SEL0005='1'and SEL1005='1' then
                temp_led<="11111111";
            elsif SEL0005='0'and SEL1005='1' then
                if temp_led="11111111" or temp_led="00000000" then temp_led<= not temp_led;
                else temp_led<="00000000";
                end if;
            elsif SEL0005='1'and SEL1005='0' then
                if temp_led="11111111" or temp_led="00000000" then temp_led<= "10000000";
                else temp_led<= temp_led(0) & temp_led(7 downto 1);
                end if;
            end if;
        end if;
    end process;
end rtl;
VHDL语言100例 目录检索: 第1例 带控制端口的加法器 第2例 无控制端口的加法器 第3例 乘法器 第4例 比较器 第5例 二路选择器 第6例 寄存器 第7例 移位寄存器 第8例 综合单元库 第9例 七值逻辑与基本数据类型 第10例 函数 第11例 七值逻辑线或分辨函数 第12例 转换函数 第13例 左移函数 第14例 七值逻辑程序包 第15例 四输入多路器 第16例 目标选择器 第17例 奇偶校验器 第18例 映射单元库及其使用举 第19例 循环边界常数化测试 第20例 保护保留字 第21例 进程死锁 第22例 振荡与死锁 第23例 振荡电路 第24例 分辨信号与分辨函数 第25例 信号驱动源 第26例 属性TRANSACTION和分辨信号 第27例 块保护及属性EVENT, 第28例 形式参数属性的测试 第29例 进程和并发语句 第30例 信号发送与接收 第31例 中断处理优先机制建模 第32例 过程限定 第33例 整数比较器及其测试 第34例 数据总线的读写 第35例 基于总线的数据通道 第36例 基于多路器的数据通道 第37例 四值逻辑函数 第38例 四值逻辑向量按位或运算 第39例 生成语句描述规则结构 第40例 带类属的译码器描述 第41例 带类属的测试平台 第42例 行为与结构的混合描述 第43例 四位移位寄存器 第44例 寄存/计数器 第45例 顺序过程调用 第46例 VHDL中generic缺省值的使用 第47例 无输入元件的模拟 第48例 测试激励向量的编写 第49例 delta延迟例释 第50例 惯性延迟分析 第51例 传输延迟驱动优先 第52例 多倍(次)分频器 第53例 三位计数器与测试平台 第54例 分秒计数显示器的行为描述6 第55例 地址计数器 第56例 指令预读计数器 第57例 加.c减.c乘指令的译码和操作 第58例 2-4译码器结构描述 第59例 2-4译码器行为描述 第60例 转换函数在元件例示中的应用 第61例 基于同一基类型的两分辨类型的赋值相容问题 第62例 最大公约数的计算 第63例 最大公约数七段显示器编码 第64例 交通灯控制器 第65例 空调系统有限状态自动机 第66例 FIR滤波器 第67例 五阶椭圆滤波器 第68例 闹钟系统的控制 第69例 闹钟系统的译码 第70例 闹钟系统的移位寄存器 第71例 闹钟系统的闹钟寄存器和时间计数器 第72例 闹钟系统的显示驱动器 第73例 闹钟系统的分频器 第74例 闹钟系统的整体组装 第75例 存储器 第76例 电机转速控制器 第77例 神经元计算机 第78例ccAm2901四位微处理器的ALU输入 第79例ccAm2901四位微处理器的ALU 第80例ccAm2901四位微处理器的RAM 第81例ccAm2901四位微处理器的寄存器 第82例ccAm2901四位微处理器的输出与移位 第83例ccAm2910四位微程序控制器中的多路选择器 第84例ccAm2910四位微程序控制器中的计数器/寄存器 第85例ccAm2910四位微程序控制器的指令计数器 第86例ccAm2910四位微程序控制器的堆栈 第87例 Am2910四位微程序控制器的指令译码器 第88例 可控制计数器 第89例 四位超前进位加法器 第90例 实现窗口搜索算法的并行系统(1)——协同处理器 第91例 实现窗口搜索算法的并行系统(2)——序列存储器 第92例 实现窗口搜索算法的并行系统(3)——字符串存储器 第93例 实现窗口搜索算法的并行系统(4)——顶层控制器 第94例 MB86901流水线行为描述组成框架 第95例 MB86901寄存器文件管理的描述 第96例 MB86901内ALU的行为描述 第97例 移位指令的行为描述 第98例 单周期指令的描述 第99例 多周期指令的描述 第100例 MB86901流水线行为模型 VHDL收藏参考资料.part1.rar (5.72 MB, 下载次数: 1436 ) VHDL收藏参考资料.part2.rar (5.72 MB, 下载次数: 1257 ) VHDL收藏参考资料.part3.rar (5.72 MB, 下载次数: 988 ) VHDL收藏参考资料.part4.rar (5.72 MB, 下载次数: 1140 ) VHDL收藏参考资料.part5.rar (2.88 MB, 下载次数: 1008 ) 资料内容不断更新和增加中。。。 fpga , VHDL , 例程 , 资料
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值