Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- entity LCD_Driver is
- Port ( Clock : in STD_LOGIC;
- New_Line : in STD_LOGIC;
- Reset : in STD_LOGIC;
- Home_Line : in STD_LOGIC;
- Write_Now : in STD_LOGIC;
- Data : in STD_LOGIC_VECTOR (7 downto 0);
- Busy : out std_logic;
- LCD_DB : out STD_LOGIC_VECTOR (7 downto 0);
- LCD_E : out STD_LOGIC;
- LCD_RS : out STD_LOGIC;
- LCD_RW : out STD_LOGIC);
- end LCD_Driver;
- architecture Behavioral of LCD_Driver is
- constant FunctionSet : std_logic_vector(7 downto 0) := "00111100";
- constant EntryModeSet : std_logic_vector(7 downto 0) := x"06";
- constant DisplayOnOff : std_logic_vector(7 downto 0) := x"0C";
- constant ClearDisplay : std_logic_vector(7 downto 0) := x"01";
- constant DDRAMAddress : std_logic_vector(7 downto 0) := x"80";
- type State_type is (Boot, SetFunction, SetFunctionb, SetEntryMode, SetEntryModeb, SetDisplay, SetDisplayb, Clear, Clearb, SetAddress, SetAddressb, Idle, WriteLCD, WriteLCDb);
- signal State : State_type := Boot;
- constant BootDelay : integer := 1500000;
- constant Delay : integer := 2000;
- constant ClearDelay : integer := 100000;
- constant E_Delay : integer := 12;
- signal e_count : integer := 0;
- signal counter : integer := 0;
- signal DataIn : std_logic_vector(7 downto 0);
- begin
- LCD_RW <= '0'; -- Always Write, No Read
- DataIn <= Data;
- process(Clock, Reset) begin
- if Reset = '1' then
- elsif rising_edge(Clock) then
- case State is
- when Boot =>
- Busy <= '1';
- if counter = BootDelay then
- State <= SetFunction;
- counter <= 0;
- --Busy <= '1';
- else
- counter <= counter + 1;
- end if;
- when SetFunction =>
- LCD_DB <= FunctionSet;
- LCD_RS <= '0';
- LCD_E <= '1';
- State <= SetFunctionb;
- when SetFunctionb =>
- if e_count = E_Delay then
- LCD_E <= '0';
- else
- e_count <= e_count + 1;
- end if;
- if counter = Delay then
- State <= SetEntryMode;
- counter <= 0;
- e_count <= 0;
- else
- counter <= counter + 1;
- end if;
- when SetEntryMode =>
- LCD_DB <= EntryModeSet;
- LCD_RS <= '0';
- LCD_E <= '1';
- State <= SetEntryModeb;
- when SetEntryModeb =>
- if e_count = E_Delay then
- LCD_E <= '0';
- else
- e_count <= e_count + 1;
- end if;
- --LCD_E <= '0';
- if counter = Delay then
- State <= SetDisplay;
- counter <= 0;
- e_count <= 0;
- else
- counter <= counter + 1;
- end if;
- when SetDisplay =>
- LCD_DB <= DisplayOnOff;
- LCD_RS <= '0';
- LCD_E <= '1';
- State <= SetDisplayb;
- when SetDisplayb =>
- if e_count = E_Delay then
- LCD_E <= '0';
- else
- e_count <= e_count + 1;
- end if;
- --LCD_E <= '0';
- if counter = Delay then
- State <= Clear;
- counter <= 0;
- e_count <= 0;
- else
- counter <= counter + 1;
- end if;
- when Clear =>
- LCD_DB <= ClearDisplay;
- LCD_RS <= '0';
- LCD_E <= '1';
- State <= Clearb;
- when Clearb =>
- if e_count = E_Delay then
- LCD_E <= '0';
- else
- e_count <= e_count + 1;
- end if;
- --LCD_E <= '0';
- if counter = ClearDelay then
- State <= SetAddress;
- counter <= 0;
- e_count <= 0;
- else
- counter <= counter + 1;
- end if;
- when SetAddress =>
- LCD_DB <= DDRAMAddress;
- LCD_RS <= '0';
- LCD_E <= '1';
- State <= SetAddressb;
- when SetAddressb =>
- if e_count = E_Delay then
- LCD_E <= '0';
- else
- e_count <= e_count + 1;
- end if;
- --LCD_E <= '0';
- if counter = Delay then
- State <= Idle;
- counter <= 0;
- e_count <= 0;
- else
- counter <= counter + 1;
- end if;
- when Idle =>
- Busy <= '0';
- if Write_Now = '1' then
- State <= WriteLCD;
- end if;
- when WriteLCD =>
- Busy <= '1';
- LCD_DB <= DataIn;
- LCD_RS <= '1';
- LCD_E <= '1';
- State <= WriteLCDb;
- when WriteLCDb =>
- if e_count = E_Delay then
- LCD_E <= '0';
- else
- e_count <= e_count + 1;
- end if;
- LCD_E <= '0';
- if counter = Delay then
- State <= Idle;
- counter <= 0;
- e_count <= 0;
- else
- counter <= counter + 1;
- end if;
- end case;
- end if;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement