Professional Documents
Culture Documents
)ALU program
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
ENTITY alu8bit IS
port(a, b : in std_logic_vector(7 downto 0); -- a and b are busses
op : in std_logic_vector(2 downto 0);
zero : out std_logic;
f : out std_logic_vector(7 downto 0));
END alu8bit;
2.)UART PROGRAM
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity FIFO is
port(
--input data
d_in:in std_logic_vector(1 downto 0);
--output data
d_out :out std_logic_vector(1 downto 0);
--write operation
wr_clk:in std_logic;
we:in std_logic;
--read operation
rd_clk:in std_logic;
re:in std_logic;
--FIFO status
full:out std_logic:= '0';
empty:out std_logic:='1'
);
end FIFO;
begin
process(wr,rd,wr_clk,rd_clk)
begin
if wr = 0 and rd = 0 then
status <= "11";
elsif wr = 0 then
status <= "10";
elsif rd = 0 then
status <= "01";
else
status <= "00";
end if;
end process;
process(wr_clk,we,rd_clk,re)
begin
if rising_edge(wr_clk) then
if we = '1' then
if (status = "11" and (wp-rp=4)) or (status = "10" and (wr = rd))or (status = "00"
and (wp >4) and (wr = rd))or (status = "01" and (wp - rp = 4)) then
full <= '1';
else
full <= '0';
wp <= wp+1;
wr <= wp rem 4;
fifo(wr) <= d_in;
end if;
end if;
end if;
if rising_edge(rd_clk) then
if re = '1' then
if ((status = "11" or status = "01")and (wp = rp))or (status = "00" and (wp < 4 )
and (rd>=wr)) then
empty <= '1';
else
empty <= '0';
rp <= rp +1;
rd <= rp rem 4;
d_out <= fifo(rd);
end if;
end if;
end if;
end process;
3.)RAM PROGRAM
module i2c_sp_ram(
//Inputs
clk, //clock
wr_en, //write enable
rd_en, //read enable
addr, //address
data_in,//data in
//Output
data_out//data out
);
//Parameter Declaration
parameter DEPTH = 8; //depth of FIFO
parameter ADDR_BUS_WD = 1>>DEPTH; //Address bus width
parameter DATA_BUS_WD = 8; //data bus width
//Inputs Declarations
input clk; //Clock
input wr_en; //Write Enable
input rd_en; //Read Enable
input [ADDR_BUS_WD-1:0] addr; //Address Width
input [DATA_BUS_WD-1:0] data_in; //Data Input
//output Declarations
output [DATA_BUS_WD-1:0] data_out; //Data Output
//reg Declarations
reg [DATA_BUS_WD-1:0] mem [DEPTH-1:0];//Memory
reg [DATA_BUS_WD-1:0] data_out; //Data Output
//Generation of data_out
always @(posedge clk)
begin : READ_GEN
if(rd_en) data_out <= mem[addr];
end
//Generation Writing data into memory
always @(posedge clk)
begin: WRITE_GEN
if(wr_en) mem[addr] <= data_in;
end
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux2t1 is
Port ( A : in std_logic;
B : in std_logic;
S : in std_logic;
Y : out std_logic);
end mux2t1;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.types.all;
library maths;
use maths.maths_class.all;
library matrix;
use matrix.matrix_class.all;
entity FIR_32tap_8_8 is
port (
a : in std_logic_vector(7 downto 0);
b : in logic_8_vector(31 downto 0);
clock : in std_logic;
reset : in std_logic;
y : out std_logic_vector(20 downto 0)
);
end FIR_32tap_8_8;
begin
-- tmp3 := reverse_order(data_table_var);
-- tmp4 := 0;
num_taps_minus_1 := number_of_taps-1;
fir_result := sum_of_products (
lower_limit => 0,
upper_limit => number_of_taps-1,
a_in => reverse_order(data_table_var),
b_in => coefficient_table_var
);
y_result := to_signed(integer(fir_result), y_result'length);
y <= std_logic_vector(y_result);
end if;
end process;
end behavioural;
library ieee;
use ieee.std_logic_1164.all;
entity finitestatemachine is
port
( reset, clk, x : in std_logic;
z : out std_logic );
end finitestatemachine;
library ieee;
use ieee.standard_logic_1164.all;
entity freq_div is
end freq_div;
begin
process(clk, rst)
begin
if (clk'event and clk='1') then
if rst ='1' then
q <= '0';
qbar <= '1';
d <= '0';
else
q <= d;
qbar <= not d;
d <= not q;
end if;
end if;
end process;
end freq_div_a;
LIBRARY ieee,toplevelib;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
use toplevelib.uart_model.all;
ENTITY datacomm_tb1_vhd_tb IS
END datacomm_tb1_vhd_tb;
COMPONENT datacomm
PORT(
clk : IN std_logic;
Din : IN std_logic;
DATABUS : INOUT std_logic_vector(7 downto 0);
LD : OUT std_logic_vector(7 downto 0);
SRAMADDRUpper : OUT std_logic_vector(9 downto 0);
SRAMADDR : OUT std_logic_vector(7 downto 0);
OE : OUT std_logic;
WE : OUT std_logic;
LB : OUT std_logic;
UB : OUT std_logic;
CE1 : OUT std_logic;
CE2 : OUT std_logic;
data_out : OUT std_logic_vector(7 downto 0);
AN : OUT std_logic_vector(3 downto 0);
Seven_seg : OUT std_logic_vector(6 downto 0)
);
END COMPONENT;
tb : PROCESS
constant My_Baud_Rate: integer := 9600;
-- Idle awhile
wait for 1 ms;