📄 ps2_caculator_vhdl.vhd
字号:
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity ps2 isport ( kd : in std_logic; clkin : in std_logic; kc : in std_logic; rst : in std_logic; a: out std_logic_vector(3 downto 0); b: in std_logic_vector(3 downto 0); led : out std_logic_vector(7 downto 0); en : out std_logic );end entity ps2;architecture one of ps2 issignal clk,ok1,ok2,ok3,ok4,ok:std_logic:='0';signal add,sub,mul,div:std_logic:='0';signal num,num1,num2,SecSeg1,SecSeg2,SecSeg3,SecSeg4: std_logic_vector(7 downto 0):="11111111";signal m: std_logic_vector( 9 downto 0 );signal scan : std_logic_vector(18 downto 0);signal scan_clk: std_logic_vector(1 downto 0);SIGNAL rfd1,rfd2,rfd3 : std_logic;signal value,value4,value3,value2,value1,sum_value:std_logic_vector(15 downto 0):="0000000000000000";signal result,result_end:std_logic_vector(15 downto 0):="0000000000000000";signal result_std,sum_value_std,result_end_std,result_begin_std,temp1,temp2,temp3: std_logic_vector(15 downto 0):="0000000000000000";signal var,res1_std,res2_std,result1_end:std_logic_vector(15 downto 0):="0000000000000000";constant const:std_logic_vector(15 downto 0):="0000000000001010"; COMPONENT div_gen_v1_0 PORT( clk : IN std_logic; dividend : IN std_logic_vector(15 downto 0); divisor : IN std_logic_vector(15 downto 0); quotient : OUT std_logic_vector(15 downto 0); remainder : OUT std_logic_vector(15 downto 0); rfd : OUT std_logic ); END COMPONENT;begin -- Instantiate the Unit Under Test (UUT) uut1: div_gen_v1_0 PORT MAP( clk => clkin, dividend => result_std, divisor => sum_value_std, quotient => result_end_std, remainder => temp1, rfd => rfd1 ); uut2: div_gen_v1_0 PORT MAP( clk => clkin, dividend => result_begin_std, divisor => var, quotient => temp2, remainder => res1_std, rfd => rfd2 ); uut3: div_gen_v1_0 PORT MAP( clk => clkin, dividend => temp2, divisor => const, quotient => temp3, remainder => res2_std, rfd => rfd3 ); process(clkin) begin if clkin'event and clkin = '1' then if kc = '0' then clk <= kc; else clk <= '1'; end if; end if;end process; process(clk,kd,m) begin if clk'event and clk = '0' then m <= kd & m( 9 downto 1 ); end if; end process; process(clk,kd,m) begin if clk'event and clk = '1' then if rst='1' then value<="0000000000000000"; add<='0'; sub<='0'; mul<='0'; div<='0'; ok<='0'; result<="0000000000000000"; result_end<="0000000000000000"; else-- case m(7 downto 0) is-- when "00010110" => NUM <= "11010111"; --1-- value<=1;-- ok<='0';-- when "00011110" => NUM <= "00110010"; --2-- value<=2;-- ok<='0';-- when "00100110" => NUM <= "10010010"; --3-- value<=3;-- ok<='0';-- when "00100101" => NUM <= "11010100"; --4-- value<=4;-- ok<='0';-- when "00101110" => NUM <= "10011000"; --5-- value<=5;-- ok<='0';-- when "00110110" => NUM <= "00011000"; --6-- value<=6;-- ok<='0';-- when "00111101" => NUM <= "11010011"; --7-- value<=7;-- ok<='0';-- when "00111110" => NUM <= "00010000";--8-- value<=8;-- ok<='0';-- when "01000110" => NUM <= "10010000";--9-- value<=9;-- ok<='0';-- when "01000101" => NUM <= "00010001";--0-- value<=0;-- ok<='0';-- when "01010101" => NUM <= "11111111";--+-- result<=sum_value;-- add<='1';-- sub<='0';-- mul<='0';-- div<='0';-- ok<='0';-- when "01001110" => NUM <= "11111111";----- result<=sum_value;-- add<='0';-- sub<='1';-- mul<='0';-- div<='0';-- ok<='0';-- when "01010100" => NUM <= "11111111";--*-- ok<='0';-- result<=sum_value;-- add<='0';-- sub<='0';-- mul<='1';-- div<='0';-- when "01011011" => NUM <= "11111111";--/-- result<=sum_value;-- add<='0';-- sub<='0';-- mul<='0';-- div<='1';-- ok<='0';-- when "01011010" => add<='1' ;-- --if add='1' then-- result_end<=result+sum_value;---- elsif sub='1' then---- result_end<=result-sum_value;---- elsif mul='1' then---- result_end<=result*sum_value;---- elsif div='1' then---- result_end<=conv_integer(result_end_std);---- end if;-- ok<='1';--Enter-- when others => NUM <= "11111111";-- value<=0;-- ok<='0';-- end case; if m(7 downto 0)="00010110" then NUM <= "11010111"; --1 value<="0000000000000001"; ok<='0'; elsif m(7 downto 0)="00011110" then NUM <= "00110010"; --2 value<="0000000000000010"; ok<='0'; elsif m(7 downto 0)="00100110" then NUM <= "10010010"; --3 value<="0000000000000011"; ok<='0'; elsif m(7 downto 0)="00100101" then NUM <= "11010100"; --4 value<="0000000000000100"; ok<='0'; elsif m(7 downto 0)="00101110" then NUM <= "10011000"; --5 value<="0000000000000101"; ok<='0'; elsif m(7 downto 0)="00110110" then NUM <= "00011000"; --6 value<="0000000000000110"; ok<='0'; elsif m(7 downto 0)="00111101" then NUM <= "11010011"; --7 value<="0000000000000111"; ok<='0'; elsif m(7 downto 0)="00111110" then NUM <= "00010000";--8 value<="0000000000001000"; ok<='0'; elsif m(7 downto 0)="01000110" then NUM <= "10010000";--9 value<="0000000000001001"; ok<='0'; elsif m(7 downto 0)="01000101" then NUM <= "00010001";--0 value<="0000000000000000"; ok<='0'; elsif m(7 downto 0)="01010101" then NUM <= "11111111";--+ result<=sum_value; add<='1'; sub<='0'; mul<='0'; div<='0'; ok<='0'; elsif m(7 downto 0)="01001110" then NUM <= "11111111";--- result<=sum_value; add<='0'; sub<='1'; mul<='0'; div<='0'; ok<='0'; elsif m(7 downto 0)="01010100" then NUM <= "11111111";--* ok<='0'; result<=sum_value; add<='0'; sub<='0'; mul<='1'; div<='0'; elsif m(7 downto 0)="01011011" then NUM <= "11111111";--/ result<=sum_value; add<='0'; sub<='0'; mul<='0'; div<='1'; ok<='0'; elsif m(7 downto 0)="01011010" then if add='1' then result_end<=result+sum_value; elsif sub='1' then result_end<=result-sum_value; elsif mul='1' then result_end<=result*sum_value; elsif div='1' then result_std<=result; sum_value_std<=sum_value; result_end<=result_end_std; end if; ok<='1';--Enter end if; end if; end if;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -