library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity decoder is
Port ( sel : in STD_LOGIC_VECTOR (2 downto 0); -- selector switch used to toggle LED
y : out STD_LOGIC_VECTOR (7 downto 0); -- output to 8 LEDs
LCD_DB : inout std_logic_vector (7 downto 0):="00000000";
LCD_RWS : inout std_logic_vector (1 downto 0):="00";
LCD_E : out STD_LOGIC:= '0');
end decoder;
---------------------------------------------------------------------------------------------------
architecture Behavioral of decoder is
signal lcd_clr_s, lcd_e_disable_s: std_logic:='0';
begin
decoder: process (sel)
begin
case sel is
when "000" => y <= "00000001";
when "001" => y <= "00000010";
when "010" => y <= "00000100";
when "011" => y <= "00001000";
when "100" => y <= "00010000";
when "101" => y <= "00100000";
when "110" => y <= "01000000";
when others => y <= "10000000";
end case;
lcd_clr_s <= not lcd_clr_s;
end process decoder;
--------------------------------------------
lcd_clr: process (lcd_clr_s)
begin
lcd_rws <= "00"; --Clear LCD Display
lcd_e <= '1';
lcd_db <= "00000001";
lcd_e_disable_s <= not lcd_e_disable_s;
end process lcd_clr;
--------------------------------------------------
lcd_e_disable: process (lcd_e_disable_s)
begin
lcd_e <= '0';
lcd_db <="00000000";
end process lcd_e_disable;
end architecture behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_TEXTIO.ALL;
USE STD.TEXTIO.ALL;
ENTITY decoder_tb2 IS
END decoder_tb2;
ARCHITECTURE testbench_arch OF decoder_tb2 IS
FILE RESULTS: TEXT OPEN WRITE_MODE IS "results.txt";
COMPONENT decoder
PORT (
sel : In std_logic_vector (2 DownTo 0);
y : Out std_logic_vector (7 DownTo 0);
LCD_DB : InOut std_logic_vector (7 DownTo 0);
LCD_RWS : InOut std_logic_vector (1 DownTo 0);
LCD_E : Out std_logic
);
END COMPONENT;
SIGNAL sel : std_logic_vector (2 DownTo 0) := "000";
SIGNAL y : std_logic_vector (7 DownTo 0) := "00000000";
SIGNAL LCD_DB : std_logic_vector (7 DownTo 0) := "ZZZZZZZZ";
SIGNAL LCD_RWS : std_logic_vector (1 DownTo 0) := "ZZ";
SIGNAL LCD_E : std_logic := '0';
BEGIN
UUT : decoder
PORT MAP (
sel => sel,
y => y,
LCD_DB => LCD_DB,
LCD_RWS => LCD_RWS,
LCD_E => LCD_E
);
PROCESS
BEGIN
-- ------------- Current Time: 600ns
WAIT FOR 600 ns;
sel <= "001";
-- -------------------------------------
-- ------------- Current Time: 1200ns
WAIT FOR 600 ns;
sel <= "011";
-- -------------------------------------
-- ------------- Current Time: 1300ns
WAIT FOR 100 ns;
sel <= "010";
-- -------------------------------------
WAIT FOR 1700 ns;
END PROCESS;
END testbench_arch;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--------------------------------------
entity LED_LCD_Display is
--------------------------------------
port
(
clk : in std_logic; -- 50 Mhz clock signal
-- LCD_Display process used ports
--------------------------------------
LCD_RWS : inout std_logic_vector (1 downto 0); -- LCD RWS in/out
LCD_DB : inout std_logic_vector (7 downto 0); -- LCD output DB (0 - 7)
LCD_E : inout std_logic); -- LCD Enable
end entity LED_LCD_Display;
-----------------------------------------
architecture rtl of LED_LCD_Display is
-----------------------------------------
-- Beginning of "LCD_DISPLAY" Process constants
-----------------------------------------------
constant delay_40ms: integer:= 8000000; -- 40ms delay assuming 50Mhz clokc (> 2000000 for 50Mhz clk)
constant delay_37us: integer:= 2000000; -- Wait time of minimum 37us (>1850) assuming 50Mhz Clock
constant delay_1d52ms: integer:= 2000000; -- Minimum waith time of 1.52ms (>76000) assuming 50Mhz clock
constant delay_4d1ms: integer:= 2000000; -- Wait for more than 4.1ms (> 205000) (after first function set)
constant delay_tr: integer:= 10; -- rise time delay for "LCD_E" max of 20ns (> 1 for 50Mhz clk) (OV 2)
constant delay_tpw: integer:= 100; -- hold time for "E" to be high min of 230ns (> 12 for 50Mhz clk) (OV 7)
constant delay_tf: integer:=10; -- fall time delay for signal "LCD_E" max of 20ns (> 1 for 50Mhz clk)(OV 2)
constant delay_th: integer:= 2; -- Data hold time for signal "LCD_db" min of 10ns (= 1 for 50Mhz clk) (OV 1)
--Beginning of "LCD_DISPLAY" Process used variables and Signals
--------------------------------------------------------------
type State_type is (Boot, FunctionSet, FunctionSetTwo, FunctionSetThree, Display, DisplayClr, EntryModeSet, WriteChar, HomeCursor, EndState);
signal State : State_type:= Boot;
signal count_LCD: integer range 0 to delay_40ms:= 0;
signal count_Char: integer:= 0; -- counter for displaying characters
-- LCD instructions used in "LCD_DISPLAY" process
--------------------------------------------------------------
constant off_DB: std_logic_vector (7 downto 0):= "00000000";
constant off_RWs: std_logic_vector (1 downto 0):= "00";
constant functionset_DB: std_logic_vector (7 downto 0):= "00111100";
constant functionset_RWS: std_logic_vector (1 downto 0):= "00";
constant Display_DB: std_logic_vector (7 downto 0):= "00001111";
constant Display_RWS: std_logic_vector (1 downto 0):= "00";
constant DisplayClr_DB: std_logic_vector (7 downto 0):= "00000001";
constant DisplayClr_RWS: std_logic_vector (1 downto 0):= "00";
constant EntryModeSet_DB: std_logic_vector (7 downto 0):= "00000111";
constant EntryModeSet_RWS: std_logic_vector (1 downto 0):= "00";
constant HomeCursor_DB: std_logic_vector (7 downto 0):= "00000010";
constant HomeCursor_RWS: std_logic_vector (1 downto 0):= "00";
constant WriteChar_RWS: std_logic_vector (1 downto 0):= "10";
signal WriteChar_DB: std_logic_vector (7 downto 0):= "00000000";
begin
LCD_display: process (clk)
begin
if rising_edge(clk) then
case state is
when Boot => -- wait 40ms
if count_LCD < delay_40ms then
count_LCD <= count_LCD + 1;
elsif count_LCD >= delay_40ms then
State <= FunctionSet;
count_LCD <= 0;
end if;
when FunctionSet => -- Set function
lcd_rws <= functionset_rws;
lcd_db <= functionset_db;
if count_LCD < delay_37us then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_37us then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_37us + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_37us + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= FunctionSetTwo;
else
count_LCD <= count_LCD + 1;
end if;
when FunctionSetTwo => -- Sets Function again
lcd_rws <= functionset_rws;
lcd_db <= functionset_db;
if count_LCD < delay_4d1ms then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_4d1ms then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_4d1ms + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_4d1ms + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= FunctionSetThree;
else
count_LCD <= count_LCD + 1;
end if;
when FunctionSetThree => -- Sets Function again
lcd_rws <= functionset_rws;
lcd_db <= functionset_db;
if count_LCD < delay_4d1ms then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_4d1ms then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_4d1ms + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_4d1ms + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= Display;
else
count_LCD <= count_LCD + 1;
end if;
when display =>
lcd_rws <= display_rws;
lcd_db <= display_db;
if count_LCD < delay_4d1ms then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_4d1ms then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_4d1ms + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_4d1ms + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= DisplayClr;
else
count_LCD <= count_LCD + 1;
end if;
when DisplayClr =>
lcd_rws <= DisplayClr_RWS;
lcd_db <= DisplayClr_DB;
if count_LCD < delay_37us then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_37us then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_37us + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_37us + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= EntryModeSet;
else
count_LCD <= count_LCD + 1;
end if;
when EntryModeSet =>
lcd_rws <= EntryModeSet_RWS;
lcd_db <= EntryModeSet_DB;
if count_LCD < delay_1d52ms then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_1d52ms then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_1d52ms + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_1d52ms + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= HomeCursor;
else
count_LCD <= count_LCD + 1;
end if;
when HomeCursor =>
lcd_rws <= HomeCursor_RWS;
lcd_db <= HomeCursor_DB;
if count_LCD < delay_1d52ms then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_1d52ms then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_1d52ms + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_1d52ms + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
State <= WriteChar;
else
count_LCD <= count_LCD + 1;
end if;
when WriteChar =>
case count_Char is -- Chooses which ASCII character to write to the LCD
when 0 =>
writeChar_DB <= "01001000"; -- ASCII for "H"
when 1 =>
WriteChar_DB <= "01100101"; -- ASCII for "e"
when 2 =>
WriteChar_DB <= "01101100"; -- ASCII for "l"
when 3 =>
WriteChar_DB <= "01101100"; -- ASCII for "l"
when 4 =>
WriteChar_DB <= "01101111"; -- ASCII for "o"
when 5 =>
WriteChar_DB <= "01001110"; -- ASCII for "N"
when 6 =>
WriteChar_DB <= "01111001"; -- ASCII for "y"
When 7 =>
WriteChar_DB <= "01110100"; -- ASCII for "t"
when 8 =>
WriteChar_DB <= "01110010"; -- ASCII for "r"
when 9 =>
WriteChar_DB <= "01101001"; -- ASCII for "i"
when others =>
WriteChar_DB <= "01100011"; -- ASCII for "c"
end case count_Char;
lcd_rws <= WriteChar_RWS;
lcd_db <= WriteChar_DB;
if count_LCD < delay_1d52ms then
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_1d52ms then
lcd_e <= '1';
count_LCD <= count_LCD + 1;
elsif count_LCD = delay_1d52ms + delay_tr + delay_tpw then
lcd_e <= '0';
count_LCD <= count_LCD + 1;
elsif count_LCD > delay_1d52ms + delay_tr + delay_tpw + delay_tf + delay_th then
count_LCD <= 0;
count_Char <= count_Char + 1;
State <= WriteChar;
if count_Char >= 10 then
State <= EndState;
end if;
else
count_LCD <= count_LCD + 1;
end if;
when EndState =>
end case state;
end if;
end process lcd_display;
end rtl;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?