من یه پروژه از اینترنت پیدا کردم در مورد ماشین حساب. کدهاشونو براتون می زارم. من نیاز دارم به یه پروژه ماشین حساب ک عملیات ساده رو انجام بده و همچنین عملیات logic & shift right , shift left که از keyboard اعداد وارد شه. با انجام چه تغییراتی رو این کدها می تونم به چیزی که می خوام برسم. ممنون می شم اگه کمکم کنید و وقت زیادیم ندارم. مرسی
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity calc1 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 calc1;
architecture Behavioral of calc1 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;
Added after 6 minutes:
could anyone explain about this code since this program is about RPN calculator which i;m not familiar with
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity calc1 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 calc1;
architecture Behavioral of calc1 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;
[move][move][/move][/move]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity calc1 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 calc1;
architecture Behavioral of calc1 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;
Added after 6 minutes:
could anyone explain about this code since this program is about RPN calculator which i;m not familiar with
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity calc1 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 calc1;
architecture Behavioral of calc1 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;
[move][move][/move][/move]
دیدگاه