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

📄 exp9.vhd

📁 四人抢答器
💻 VHD
字号:
 -------------------------------------
                             --  Title: 四位全加器              --
		                     --  Author:Pan  hongtao    --
                             --  Data: 2004-9-15                --
                             -------------------------------------
library ieee;        --库函数
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------------
entity exp9 is
  port(  X,Y     :  in   std_logic_vector(3 downto 0);   --输入:2个4位二进制码
         Clk       :  in   std_logic;   --时钟输入
        
         result:  buffer  std_logic_vector(7 downto 0) ;   --计算结果  
         SEG_SEL   :  buffer  std_logic_vector(2 downto 0); --七段码管扫描驱动 
         Display   :  out  std_logic_vector(7 downto 0) --七段码管显示输出       
       );      
end exp9;
--------------------------------------------------------------------
architecture behave of exp9 is
  signal S1,S2,S3 : std_logic;    --中间进位
  signal SEC10    : std_logic_vector(7 downto 0) ;
  signal SEC1:std_logic_vector(7 downto 0) ;
   signal Disp_Decode   : std_logic_vector(7 downto 0);
  signal  Disp_Temp:std_logic_vector(7 downto 0) ;
  signal m_Result: std_logic_vector(7 downto 0) ;
  constant  m10:STD_LOGIC_VECTOR(3 DOWNTO 0):="1010";--10
  constant  m20:STD_LOGIC_VECTOR(4 DOWNTO 0):="10100";--20
  constant  m30:STD_LOGIC_VECTOR(4 DOWNTO 0):="11110";--30
  begin
--function e2to10(x0,x1,x2,x3,x4,x5,x6,x7:in std_logic) ;
                -- return integer is 
    --begin
      --return (x7*128+x6*64+x5*32+x4*16+x3*8+x2*4+x1*2+x0*1);
  --end function e2to10;
    process(X,Y)      --计算
      begin
        result(0)<=X(0) xor Y(0);      --异或,产生低位
        S1<=X(0) and Y(0);               --- 与,产生低位进位
        result(1)<=X(1) xor Y(1) xor S1;
        S2<=((X(1) xor Y(1)) and S1) or (X(1) and Y(1));
        result(2)<=X(2) xor Y(2) xor S2;
        S3<=((X(2) xor Y(2)) and S2) or (X(2) and Y(2));
        result(3)<=X(3) xor Y(3) xor S3;
        result(4)<=((X(3) xor Y(3)) and S3) or (X(3) and Y(3));
        result(7 downto 5)<="000";
        
    end process;   
   m_Result<=result;
    process(X,Y)
      begin 
       if (m_Result<m10) then 
           sec1<= m_Result;sec10<="00000000";
          elsif (m_Result<m20) then 
              sec1<= m_Result-m10; sec10<="00000001";
           elsif (result<30) then 
              sec1<=m_Result-m20; sec10<="00000010";
           elsif (m_result<40) then 
              sec1<=m_Result-m30;  sec10<="00000011";
         end if ;
    end process;
process(SEG_SEL)      
      begin
        case (SEG_SEL+1) is
          when "000"=>Disp_Temp<="00001010";
          when "001"=>Disp_Temp<="00001011";
          when "010"=>Disp_Temp<=SEC10;
          when "011"=>Disp_Temp<=SEC1;
          when "100"=>Disp_Temp<="00001010";
          when "101"=>Disp_Temp<="00001011";
          when "110"=>Disp_Temp<=SEC10;
          when "111"=>Disp_Temp<=SEC1;
       end case;   
    end process;

    process(Clk)
      begin
        if(Clk'event and Clk='1') then    --扫描累加 
           SEG_SEL<=SEG_SEL+1;
           Display<=Disp_Decode;
        end if;
   end process;
process(Disp_Temp)      --交通灯的时间值的显示转换
      begin
        case Disp_Temp is
          when "00000000"=>Disp_Decode<="00111111";   --'0'
          when "00000001"=>Disp_Decode<="00000110";   --'1'
          when "00000010"=>Disp_Decode<="01011011";   --'2'
          when "00000011"=>Disp_Decode<="01001111";   --'3'
          when "00000100"=>Disp_Decode<="01100110";   --'4'
          when "00000101"=>Disp_Decode<="01101101";   --'5'
          when "00000110"=>Disp_Decode<="01111101";   --'6'
          when "00000111"=>Disp_Decode<="00000111";   --'7'
          when "00001000"=>Disp_Decode<="01111111";   --'8'
          when "00001001"=>Disp_Decode<="01101111";   --'9'
          when "00001010"=>Disp_Decode<="01001000";   --'='
          when "00001011"=>Disp_Decode<="00010100";   --'||'
          when others=>Disp_Decode<="00000000";   --全灭
        end case;
    end process;
  
end behave;

⌨️ 快捷键说明

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