【正文】
mux is port( ain, bin: in std_logic_vector(1 downto 0)。 sel: in std_logic_vector(1 downto 0)。 count: out std_logic_vector(1 downto 0))。 end mux。 architecture archmux1 of mux is begin mux4_1: process (ain, bin,sel) begin if sel = 00 then count = ain or bin。 elsif sel = 01 then count = ain nand bin。 elsif sel = 10 then count = ain xor bin。 elsif sel = 11 then count = not bin。 else count =xx。 end if。 end process mux4_1。 end archmux1。 (b) architecture archmux2 of mux is signal temp_sel : integer range o to 3 。 begin mux4_1:process (ain, bin,sel) begin temp_sel = 39。039。 if ( sel (0) = 39。139。 ) then temp_sel = temp_sel + 1 。 end if 。 if ( sel (1) =39。139。) then temp_sel = temp_sel +2。 end if。 case temp_sel is 52 when 0 = count = ain or bin。 when 1 = count = ain nand bin。 when 2 = count = ain xor bin。 when 3 = count = not bin。 when others = count = 39。xx39。 end case 。 end process mux4_1。 end archmux2 。 (c) architecture archmux3 of mux is begin count = ain or bin when sel = 39。0039。 else count = ain nand bin when sel = 39。0139。 else count = ain xor bin when sel = 39。0139。 else count = not bin when sel = 39。0139。 else count = 39。xx39。 end architecture archmux3 。 : library ieee 。 use 。 entity dff_latch is port (clk, din : in std_logic。 qout : out std_logic)。 end dff_latch。 architecture maxpld of dff_latch is signal temp:std_logic。 begin p1 : process (clk, temp) begin if (enable = 39。139。) then q =not temp。 end if。 end process p1。 p2: process(din,clk) begin if (clk39。event and clk=39。139。)then temp =din。 end if。 end process。 end maxpld。 : library ieee。 use 。 use 。 entity counter_up_down_24 is 53 port(reset,ctrl,follow,clk:in std_logic。 cin:in std_logic_vector(4 downto 0)。 cout:out std_logic_vector(4 downto 0)。 jin,jie: out std_logic)。 end counter_up_down_24。 architecture rtl of counter_up_down_24 is signal temp:std_logic_vector(4 downto 0)。 begin process(clk,reset,ctrl,follow,cin) begin if reset=39。039。then temp=00000。 jin=39。139。 jie=39。139。 elsif follow=39。039。 then temp=cin。 elsif( clk39。event and clk=39。039。 )then if ctrl=39。139。then if (temp=23)then temp=00000。 jin=39。039。 else temp=temp+1。 jin=39。139。 end if。 else if (temp=0) then temp=10111。 jie=39。039。 else temp=temp1。 jie=39。139。 end if。 end if 。 end if。 end process。 cout=temp。 end rtl。 : library ieee 。 use 。 entity schk is port(din, clk, clr : in std_logic。 串行輸入數(shù)據(jù)位 /工作時鐘 /復(fù)位信號 ab : out std_logic_vector(3 downto 0))。 檢測結(jié)果輸出 end schk。 architecture behav of schk is signal q : integer range 0 to 8 。 54 signal d : std_logic_vector(4 downto 0)。 5 位待檢測預(yù) 置數(shù) begin d = 10010 。 5 位待檢測預(yù)置數(shù) process( clk, clr ) begin if clr = 39。139。 then q = 0 。 elsif clk39。event and clk=39。139。 then 時鐘到來時,判斷并處理當(dāng)前輸入的位 case q is when 0= if din = d(4) then q = 1 。 else q = 0 。 end if 。 when 1= if din = d(3) then q = 2 。 else q = 0 。 end if 。 when 2= if din = d(2) then q = 3 。 else q = 0 。 end if 。 when 3= if din = d(1) then q = 4 。 else q = 0 。 end if 。 when 4= if din = d(0) then q = 5 。 else q = 0 。 end if 。 when others = q = 0 。 end case 。 end if 。 end process 。 process( q ) 檢測結(jié)果判斷輸出 begin if q =5 then ab = 1010 。 序列數(shù)檢測正確,輸出 a else ab = 1011 。 序列數(shù)檢測錯誤,輸出 b end if 。 end process 。 end behav 。 習(xí)題 5 : library ieee。 use 。 use 。 entity counter_plus is port(clk,clr:in std_logic。 dout: buffer std_logic_vector(7 downto 0))。 end。 architecture art of counter_plus is begin process(clk,clr) begin if clr=39。139。then dout=00000000。 elsif clk39。event and clk=39。139。 then if(dout=255)then dout=00000000。計數(shù)到 256 時清零 else dout=dout+1。 end if。 end if。 end process。 end art。 仿真波形如圖 所示: 55 圖 : library ieee。 use 。 use 。 entity counter4b is port(clk,clr,s,load:in std_logic。s=1 加法計數(shù), s=0 減法計數(shù) din: in std_logic_vector(7 downto 0)。 dout: buffer std_logic_vector(7 downto 0))。 end。 architecture art of counter4b is begin process(clk,clr,s,load,din) begin if clk39。event and clk=39。139。 then if clr=39。139。then dout=(others=39。039。)。清零 elsif load=39。139。 then dout=din。 elsif s=39。139。 then if(dout=11111111)then dout=00000000。計數(shù)到 FF 時清零 else dout=dout+1。 end if。 elsif s=39。039。 then if(dout=00000000)then dout=11111111。設(shè)定容量 FF else dout=dout1。 end if。 end if。 end if。 end process。 end art。 仿真波形如圖 所示: 56 圖 , 參考 原理圖 如 圖 所示: 圖 仿真波形如圖 所示: 圖 57 4位二進制數(shù)相乘,它們的乘積最大值為 1515=225,而一個 8位二進制數(shù)能表示的最大數(shù)值為 255。故此題中,乘法器只需要有 8 位二進制輸出即可,不會產(chǎn)生第 9 位的進位輸出。 參考程序如下所示: 子模塊源程序: 1) 4 位右移寄存器模塊源程 序 library ieee。 use 。 entity shiftr_4 is port(clk,load:in std_logic。 a: in std_logic_vector(3 downto 0)。 qout: out std_logic)。 end。 architecture art of shiftr_4 is begin process(clk,load) variable q: std_logic_vector(3 downto 0):=0000。 begin if load=39。139。 then q:=a。 elsif clk39。event and clk=39。139。 then qout=q(0)。 q(2 downto 0):= q(3 downto 1)。 q(3):=39。039。 e