LCD_16x2_ENGINE.vhd
206 lines
| 4.5 KiB
| text/x-vhdl
|
VhdlLexer
alexis
|
r0 | ---------------------------------------------------------------------------------- | ||
-- Company: | ||||
-- Engineer: | ||||
-- | ||||
-- Create Date: 08:32:21 10/19/2010 | ||||
-- Design Name: | ||||
-- Module Name: LCD_16x2_ENGINE - Behavioral | ||||
-- Project Name: | ||||
-- Target Devices: | ||||
-- Tool versions: | ||||
-- Description: | ||||
-- | ||||
-- Dependencies: | ||||
-- | ||||
-- Revision: | ||||
-- Revision 0.01 - File Created | ||||
-- Additional Comments: | ||||
-- | ||||
---------------------------------------------------------------------------------- | ||||
library IEEE; | ||||
use IEEE.STD_LOGIC_1164.ALL; | ||||
use IEEE.NUMERIC_STD.ALL; | ||||
use work.LCD_16x2_CFG.all; | ||||
entity LCD_16x2_ENGINE is | ||||
generic(OSC_freqKHz : integer := 50000); | ||||
Port ( clk : in STD_LOGIC; | ||||
reset : in STD_LOGIC; | ||||
DATA : in std_logic_vector(16*2*8-1 downto 0); | ||||
CMD : in std_logic_vector(10 downto 0); | ||||
Exec : in std_logic; | ||||
Ready : out std_logic; | ||||
LCD_CTRL : out LCD_DRVR_CTRL_BUSS | ||||
); | ||||
end LCD_16x2_ENGINE; | ||||
architecture ar_LCD_16x2_ENGINE of LCD_16x2_ENGINE is | ||||
constant ConfigTbl : LCD_CFG_Tbl :=(ClearDSPLY,FunctionSet,DSPL_CTRL,SetEntryMode,RetHome); | ||||
signal SYNCH : LCD_DRVR_SYNCH_BUSS; | ||||
signal DRIVER_CMD : LCD_DRVR_CMD_BUSS; | ||||
signal FRAME_CLK : std_logic; | ||||
signal FRAME_CLK_reg : std_logic; | ||||
signal RefreshFlag : std_logic; | ||||
signal CMD_Flag : std_logic; | ||||
signal Exec_Reg : std_logic; | ||||
type state_t is (INIT0,INIT1,INIT2,IDLE,Refresh,Refresh0,Refresh1,ReturnHome,GoLine2,GoLine2_0,ExecCMD0,ExecCMD1); | ||||
signal state : state_t; | ||||
signal i : integer range 0 to 32 := 0; | ||||
begin | ||||
Driver0 : entity work.LCD_16x2_DRIVER | ||||
generic map(OSC_freqKHz) | ||||
Port map(reset,clk,LCD_CTRL,SYNCH,DRIVER_CMD); | ||||
FRAME_CLK_GEN0 : entity work.FRAME_CLK_GEN | ||||
generic map(OSC_freqKHz) | ||||
Port map( clk,reset,FRAME_CLK); | ||||
process(reset,clk) | ||||
begin | ||||
if reset = '0' then | ||||
state <= INIT0; | ||||
Ready <= '0'; | ||||
RefreshFlag <= '0'; | ||||
i <= 0; | ||||
elsif clk'event and clk ='1' then | ||||
FRAME_CLK_reg <= FRAME_CLK; | ||||
Exec_Reg <= Exec; | ||||
if FRAME_CLK_reg = '0' and FRAME_CLK = '1' then | ||||
RefreshFlag <= '1'; | ||||
elsif state = Refresh or state = Refresh0 or state = Refresh1 then | ||||
RefreshFlag <= '0'; | ||||
end if; | ||||
if Exec_Reg = '0' and Exec = '1' then | ||||
CMD_Flag <= '1'; | ||||
elsif state = ExecCMD0 or state = ExecCMD1 then | ||||
CMD_Flag <= '0'; | ||||
end if; | ||||
case state is | ||||
when INIT0 => | ||||
if SYNCH.DRVR_READY = '1' then | ||||
DRIVER_CMD.Exec <= '1'; | ||||
DRIVER_CMD.Duration <= Duration_20ms; | ||||
DRIVER_CMD.CMD_Data <= '0'; | ||||
DRIVER_CMD.Word <= ConfigTbl(i); | ||||
i <= i + 1; | ||||
state <= INIT1; | ||||
else | ||||
DRIVER_CMD.Exec <= '0'; | ||||
end if; | ||||
when INIT1 => | ||||
state <= INIT2; | ||||
DRIVER_CMD.Exec <= '0'; | ||||
when INIT2 => | ||||
if SYNCH.DRVR_READY = '1' then | ||||
if i = 5 then | ||||
state <= Idle; | ||||
else | ||||
state <= INIT0; | ||||
end if; | ||||
end if; | ||||
when Idle=> | ||||
DRIVER_CMD.Exec <= '0'; | ||||
if RefreshFlag = '1' then | ||||
Ready <= '0'; | ||||
state <= Refresh; | ||||
elsif CMD_Flag = '1' then | ||||
Ready <= '0'; | ||||
state <= ExecCMD0; | ||||
else | ||||
Ready <= '1'; | ||||
end if; | ||||
i <= 0; | ||||
when Refresh=> | ||||
if SYNCH.DRVR_READY = '1' then | ||||
DRIVER_CMD.Exec <= '1'; | ||||
DRIVER_CMD.Duration <= Duration_100us; | ||||
DRIVER_CMD.CMD_Data <= '1'; | ||||
DRIVER_CMD.Word <= DATA(i*8+7 downto i*8); | ||||
i <= i + 1; | ||||
state <= Refresh0; | ||||
else | ||||
DRIVER_CMD.Exec <= '0'; | ||||
end if; | ||||
when Refresh0=> | ||||
state <= Refresh1; | ||||
DRIVER_CMD.Exec <= '0'; | ||||
when Refresh1=> | ||||
if SYNCH.DRVR_READY = '1' then | ||||
if i = 32 then | ||||
state <= ReturnHome; | ||||
elsif i = 16 then | ||||
state <= GoLine2; | ||||
else | ||||
state <= Refresh; | ||||
end if; | ||||
end if; | ||||
when ExecCMD0=> | ||||
if SYNCH.DRVR_READY = '1' then | ||||
DRIVER_CMD.Exec <= '1'; | ||||
DRIVER_CMD.Duration <= CMD(9 downto 8); | ||||
DRIVER_CMD.CMD_Data <= '0'; | ||||
DRIVER_CMD.Word <= CMD(7 downto 0); | ||||
state <= ExecCMD1; | ||||
else | ||||
DRIVER_CMD.Exec <= '0'; | ||||
end if; | ||||
when ExecCMD1=> | ||||
state <= Idle; | ||||
DRIVER_CMD.Exec <= '0'; | ||||
when GoLine2=> | ||||
if SYNCH.DRVR_READY = '1' then | ||||
DRIVER_CMD.Exec <= '1'; | ||||
DRIVER_CMD.Duration <= Duration_100us; | ||||
DRIVER_CMD.CMD_Data <= '0'; | ||||
DRIVER_CMD.Word <= X"C0"; | ||||
state <= GoLine2_0; | ||||
else | ||||
DRIVER_CMD.Exec <= '0'; | ||||
end if; | ||||
when GoLine2_0=> | ||||
state <= Refresh; | ||||
DRIVER_CMD.Exec <= '0'; | ||||
when ReturnHome=> | ||||
if SYNCH.DRVR_READY = '1' then | ||||
DRIVER_CMD.Exec <= '1'; | ||||
DRIVER_CMD.Duration <= Duration_4ms; | ||||
DRIVER_CMD.CMD_Data <= '0'; | ||||
DRIVER_CMD.Word <= X"02"; | ||||
state <= Idle; | ||||
else | ||||
DRIVER_CMD.Exec <= '0'; | ||||
end if; | ||||
end case; | ||||
end if; | ||||
end process; | ||||
end ar_LCD_16x2_ENGINE; | ||||