Addition of 2 numbers

Joined
May 19, 2008
Messages
1
Reaction score
0
Hello,

I have a big problem in using arithmetic functions.

i have to enter 2 decimal numbers by using the PS/2 keyboard and display the conclusion (sum of that) on a seven segment display.

But that wasn't a problem a big problem. I already get the correct value on the 7Seg when i press a button on the keyboard.

So the next step is to add these 2 decimal numbers and display the conclusion on the 7Seg.

But i don't know how to manage this. So please help me.

Thanks!

Here is an excerpt of my code (without the keyboard scanner):

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity calc is
Port ( mclk : in STD_LOGIC; -- Main clock
rst : in STD_LOGIC; -- Reset Button

SW : in STD_LOGIC_VECTOR(3 downto 0); -- Switch
PS2C : in STD_LOGIC; -- PS/2 Clock
PS2D : in STD_LOGIC; -- PS2 Data
SSD_CAT : out STD_LOGIC;
SSD_AN : out STD_LOGIC_VECTOR (6 downto 0));
end calc;

architecture Behavioral of calc is

component keyboardscanner -- Keyboard component
Port ( mclk : in std_logic; -- System Clock
PS2C : in std_logic; -- PS2 Clock
PS2D : in std_logic; -- PS2 Data
rst : in std_logic; -- Reset BTN0
Ps2Dout : out std_logic_vector(7 downto 0); -- out data
fRd : out std_logic); -- data valid
flag
end component;

signal clkdiv : std_logic_vector(20 downto 0); -- General clock
divider register
signal hex_dig : std_logic_vector(3 downto 0); -- Input to HEX
2SSD decoder
signal KBD_SC : std_logic_vector(7 downto 0); -- PS2 Keyboard
Scan Code
signal SSD_sel : std_logic_vector(1 downto 0); -- Mux select
für SSD Daten
signal KD : std_logic; -- Data valid
flag
signal operand0 : integer;
signal operand1 : integer;
signal state : Integer := 0;


begin

-- General Clock Divider
process (mclk, rst)
begin
if ( rst = '1') then clkdiv <= (others => '0');
elsif mclk = '1' and mclk'Event then
clkdiv <= clkdiv + 1;
end if;
end process;


process (mclk, rst)
begin

if ( KBD_SC = "01110000" ) then operand0 <= 0; --KP 0
elsif ( KBD_SC = "01101001" ) then operand0 <= 1; --KP 1
elsif ( KBD_SC = "01110010" ) then operand0 <= 2; --KP 2
elsif ( KBD_SC = "01111010" ) then operand0 <= 3; --KP 3
elsif ( KBD_SC = "01101011" ) then operand0 <= 4; --KP 4
elsif ( KBD_SC = "01110011" ) then operand0 <= 5; --KP 5
elsif ( KBD_SC = "01110100" ) then operand0 <= 6; --KP 6
elsif ( KBD_SC = "01101100" ) then operand0 <= 7; --KP 7
elsif ( KBD_SC = "01110101" ) then operand0 <= 8; --KP 8
elsif ( KBD_SC = "01111101" ) then operand0 <= 9; --KP 9
elsif ( KBD_SC = "01111001" ) then operand0 <= 10; --KP +
elsif ( KBD_SC = "01011010" ) then operand0 <= 11; --Enter
elsif ( KBD_SC = "00100001" ) then operand0 <= 12; --C
elsif ( KBD_SC = "00100100" ) then operand0 <= 13; --E
end if;


if(state = 0 and operand0 <= 13) then
operand1 <= operand0;
end if;

end process;


-- Assignemt of Data to SSD
SSD_CAT <= clkdiv(10);
SSD_sel <= SW(0) & clkdiv(10); -- CLKdiv muxes data between the two
LEDs


-- SSD Decoder
with operand0 select
SSD_AN <= "0111111" when 0, -- 0
"0000110" when 1, -- 1
"1011011" when 2, -- 2
"1001111" when 3, -- 3
"1100110" when 4, -- 4
"1101101" when 5, -- 5
"1111101" when 6, -- 6
"0000111" when 7, -- 7
"1111111" when 8, -- 8
"1101111" when 9, -- 9
"1000000" when 10, -- KP+
"0110111" when 11, -- Enter
"0111001" when 12, -- C
"1111001" when 13, -- E
"0000001" when others; --X



-- PS2 Keyboard Scanner
C1 : PS2_reader port map (mclk=>mclk, PS2C=>PS2C, PS2D=>PS2D, rst=>rst,
Ps2Dout=>KBD_SC, fRd=>KD);

end Behavioral;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top