Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Addition of 2 numbers

 
Thread Tools Search this Thread
Old 05-19-2008, 01:07 PM   #1
Default Addition of 2 numbers


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;


xcite
xcite is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Numbers and more numbers... Linda A+ Certification 1 12-03-2005 12:43 AM
Re: Numbers and more numbers... Breedo A+ Certification 0 12-02-2005 12:45 AM
Re: Laptop won't type numbers Bill A+ Certification 0 06-10-2005 08:49 PM
Re: Laptop won't type numbers Adam Leinss A+ Certification 2 06-09-2005 04:00 AM
Re: Laptop won't type numbers rainman A+ Certification 0 06-08-2005 03:11 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46