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

📄 vhdl1.vhd

📁 a simple calculator with vhdl operators performing calculator operation
💻 VHD
字号:
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

entity RPN_Calc is 
 Port ( Clk :      in  std_logic; 
        Switches : in  std_logic_vector(7 downto 0); 
        Buttons :  in  std_logic_vector(6 downto 0); 
        Result :   out std_logic_vector(7 downto 0)); 
end RPN_Calc; 

architecture Behavioral of RPN_Calc is 
 Signal Q0,Q1,Q2,Q3: std_logic_vector(7 downto 0) := (others=>'0'); 
 Signal S:           std_logic_vector(1 downto 0); 
 Signal S3S2S1S0:    std_logic_vector(3 downto 0); 
 Signal D,B,T:       std_logic_vector(7 downto 0); 
 signal Old_buttons: std_logic_vector(6 downto 0); 
begin 
 T      <= Switches; 
 B      <= (others=>'0');   
 Result <= Q0; 

 One_puls_detector: 
 process( clk) 
    variable One_pulses: std_logic_vector(6 downto 0); 
 begin 
    if rising_edge( Clk) then 
       Old_buttons <= Buttons; 
       One_pulses  := not Old_buttons and Buttons; 
       case One_pulses is 
          when "0000001" => S <= "01"; S3S2S1S0 <= "0000"; -- Enter 
          when "0000010" => S <= "10"; S3S2S1S0 <= "0000"; -- Pop 
          when "0000100" => S <= "11"; S3S2S1S0 <= "0001"; -- + 
          when "0001000" => S <= "11"; S3S2S1S0 <= "0010"; -- - 
          when "0010000" => S <= "11"; S3S2S1S0 <= "0100"; -- * 
          when "0100000" => S <= "11"; S3S2S1S0 <= "1000"; -- / 
          when "1000000" => S <= "11"; S3S2S1S0 <= "1111"; -- XOR 
          when  others   => S <= "00"; S3S2S1S0 <= "0000"; -- nop 
        end case; 
     end if; 
  end process; 
        
  The_RPN_Stack: 
  process( Clk) 
  begin 
     if rising_edge( Clk) then 
        case S is 
           When "00" => Null; 
           When "01" => Q3<=Q2; Q2<=Q1; Q1<=Q0; Q0<=T; 
           When "10" => Q0<=Q1; Q1<=Q2; Q2<=Q3; Q3<=B; 
           When "11" => Q0<=D;  Q1<=Q2; Q2<=Q3; Q3<=B; 
           When others => Null; 
        end case; 
     end if; 
  end process; 

  ALU_process: 
  process( S3S2S1S0, Q1, Q0) 
  begin 
     case S3S2S1S0 is 
        when "0001" =>  D <= Q1+Q0; 
        when "0010" =>  D <= Q1-Q0; 
        when "0100" =>  D <= Q1(3 downto 0) * Q0(3 downto 0); 
     -- When "1000" => D <= Q1/Q0; -- This one tricky - make a ROM 
        when "1111" =>  D <= Q1 xor Q0; 
        when others =>  D <= (others=>'0'); 
      end case;         
   end process;   
end Behavioral; 

⌨️ 快捷键说明

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