【正文】
hen q3=39。039。q2=39。139。q1=39。039。q0=39。139。 gs=39。039。eo=39。139。 elsif(d(11)=39。039。 and ei=39。039。)then q3=39。039。q2=39。139。q1=39。039。q0=39。039。 gs=39。039。eo=39。139。 elsif(d(12)=39。039。 and ei=39。039。)then q3=39。039。q2=39。039。q1=39。139。q0=39。139。 gs=39。039。eo=39。139。 elsif(d(13)=39。039。 and ei=39。039。)then q3=39。039。q2=39。039。q1=39。139。q0=39。039。 gs=39。039。eo=39。139。 63 elsif(d(14)=39。039。 and ei=39。039。)then q3=39。039。q2=39。039。q1=39。039。q0=39。139。 gs=39。039。eo=39。139。 elsif(d(15)=39。039。 and ei=39。039。)then d15 prioty encoder q3=39。039。q2=39。039。q1=39。039。q0=39。039。 gs=39。039。eo=39。139。 elsif(ei=39。139。)then q3=39。139。q2=39。139。q1=39。139。q0=39。139。 gs=39。139。eo=39。139。 elsif(d=1111111111111111 and ei=39。039。)then q3=39。139。q2=39。139。q1=39。139。q0=39。139。 gs=39。139。eo=39。039。 end if。 end process。 end encoder。 仿真波形如圖 所示: 圖 : library ieee。 use 。 entity led is port(d:in std_logic_vector(3 downto 0)。 dout:out std_logic_vector(6 downto 0))。 end。 architecture art of led is begin process(d) begin if(d=0000)then dout=1111110。 elsif(d=0001)then dout=0110000。 elsif(d=0010)then dout=1101101。 elsif(d=0011)then dout=1111001。 elsif(d=0100)then dout=0110011。 elsif(d=0101)then dout=1011011。 elsif(d=0110)then dout=1011111。 64 elsif(d=0111)then dout=1110000。 elsif(d=1000)then dout=1111111。 elsif(d=1001)then dout=1111011。 elsif(d=1010)then dout=1110111。 elsif(d=1011)then dout=0011111。 elsif(d=1100)then dout=1001110。 elsif(d=1101)then dout=1111110。 elsif(d=1110)then dout=1001111。 elsif(d=1111)then dout=1000111。 end if。 end process。 end。 仿真波形如圖 所示: 圖 : library ieee。 use 。 use 。 entity adder12b is port(clr,cin: in std_logic。 a,b: in std_logic_vector(11 downto 0)。 s: out std_logic_vector(11 downto 0)。 cout:out std_logic)。 end adder4b。 architecture art of adder12b is signal sint:std_logic_vector(12 downto 0)。 signal aa,bb:std_logic_vector(12 downto 0)。 begin process(clr) begin if clr=39。139。then sint=0000000000000。 else aa=39。039。amp。a。 bb=39。039。amp。b。 sint=aa+bb+cin。 end if。 65 s=sint(11 downto 0)。 cout=sint(12)。 end process。 end art。 仿真波形如圖 所示: 圖 : library ieee。 use 。 entity dff_logic is port(d,clk,clr,set:in std_logic。 q:out std_logic)。 end dff_logic。 architecture art of dff_logic is begin process(clk,clr,set) begin if set=39。039。 then q=39。139。 elsif clr=39。139。 then q=39。039。 elsif clk39。event and clk=39。139。 then q=d。 end if。 end process。 end art。 仿真波形如圖 所示: 66 圖 : library ieee。 use 。 entity jkff_logic is port(j,k,clk,clr,set:in std_logic。 q:out std_logic)。 end jkff_logic。 architecture art of jkff_logic is signal q_s:std_logic。 begin process(clk,clr,set,j,k) begin if clk39。event and clk=39。139。 then if set=39。039。 then q_s=39。139。 elsif clr=39。139。 then q_s=39。039。 if (j=39。039。) and (k=39。139。) then q_s=39。039。 elsif(j=39。139。) and (k=39。039。) then q_s=39。139。 elsif(j=39。139。) and (k=39。139。) then q_s=not q_s。 end if。 end if。 end if。 q=q_s。 end process。 end art。 仿真波形如圖 所示: 圖 : 1 位鎖存器 子模塊源程序: library ieee。 use 。 entity latch1 is 67 port(d: in std_logic。 ena: in std_logic。使能端 q: out std_logic)。 end latch1。 architecture art of latch1 is begin process(d,ena) begin if ena=39。139。 then q=d。 end if。 end process。 end art。 元件聲明程序包源程序: library ieee。 use 。 package my_pkg is ponent latch1 port(d:in std_logic。 ena:in std_logic。 q: out std_logic)。 end ponent。 end my_pkg。 16 位鎖存器頂層模塊源程 序: library ieee。 use 。 use 。 entity latch16b is port(d: in std_logic_vector(15 downto 0)。 oen: in bit。 g: in std_logic。 q:out std_logic_vector(15 downto 0))。 end。 architecture one of latch16b is signal sig_save:std_logic_vector(15 downto 0)。 begin gelatch:for n in 0 to 15 generate latchx:latch1 port map(d(n),g,sig_save(n))。 end generate。 q=sig_save when oen=39。039。 else ZZZZZZZZZZZZZZZZ。 end one。 仿真波形如圖 所示: 68 圖 : library ieee。 use 。 use 。 entity counter16b is port(clk,load,s:in std_logic。s=1 加法計(jì)數(shù), s=0 減法計(jì)數(shù) din: in std_logic_vector(15 downto 0)。 dout: buffer std_logic_vector(15 downto 0))。 end。 architecture art of counter16b is begin process(clk) begin if clk39。event and clk=39。139。 then if load=39。139。 then dout =din。 elsif s=39。139。 then dout=dout+1。 else dout=dout1。 end if。 end if。 end process。 end art。 仿真波形如圖 所示: 圖 : library ieee。 69 use 。 use 。 entity counter10 is port(clk,clr,load,s:in std_logic。s=1 加法計(jì)數(shù), s=0 減法計(jì)數(shù) din: in std_logic_vector(3 downto 0)。 dout: out std_logic_vector(3 downto 0))。 end。 architecture art of counter10 is signal d: std_logic_vector(3 downto 0)。 begin process(clk,clr,load,s) begin if clr=39。139。then d=0000。 elsif load=39。139。 then d=din。 elsif clk39。event and clk=39。139。 then if s=39。139。 then if(d=9)then d=0000。 else d=d+1。 end if。 elsif s=39。039。 then if(d=0)then d=1001。 else d=d1。 end if。 end if。 end if。 dout=d。 end process。 end art。 仿真波形如圖 所示: 圖 : library ieee。 use 。 entity dcshift32b is port(clr,load,clk,s,dir,dil:in std_logic。 data: in std_logic_vector(31 downto 0)。 70 dout: buffer std_logic_vector(31 downto 0))。 end dcshift32b。 architecture art of dcshift32b is signal temp:std_logic_vector(31 downto 0)。 begin pro