library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
en
tity LCD1602_1 is
Port ( CLK : in std_logic;
Reset : in std_logic;
LCD_RS : out std_logic; --寄存器选择信号
LCD_RW : out std_logic; --液晶读写信号
LCD_EN : out std_logic; --液晶时钟信号
LCD_Data : out std_logic_vector(7 downto 0)); --液晶数据信号
end LCD1602_1;
architecture Behavioral of LCD1602_1 is
type state is (set_dlnf,set_cursor,set_dcb,set_cgram,write_cgram,set_ddram,write_LCD_Data);
signal Current_State:state;
signal Clk_Out : std_logic;
signal LCD_Clk : std_logic;
begin
process(CLK)--分频进程,CLK输入,CLK_Out输出,50MHz输入,125Hz输出,8ms
variable n1:integer range 0 to 19999;
begin
if rising_edge(CLK) then
if n1<19999 then n1:=n1+1;
else n1:=0;
Clk_Out<=not Clk_Out;
end if;
end if;
end process;
LCD_RW <= '0' ; --RW='0';写入设置
LCD_EN <= Clk_Out ; --用125Hz作为LCD的使能,也作为LCD的时钟
LCD_Clk <= Clk_Out; --用125Hz作为LCD的时钟
process(LCD_Clk,Reset,Current_State) --状态机控制显示
variable cnt1: std_logic_vector(4 downto 0):="00000";
begin
if Reset='0'then Current_State<=set_dlnf; -- Reset就清屏,Reset接出用一个按钮作为复位按键即可,按下就为'0'复位。
cnt1:="11110";
-- LCD_RS<='0';
elsif rising_edge(LCD_Clk) then Current_State <= Current_State ; --LCD_RS <= '0';
case Current_State is
when set_dlnf=> LCD_RS<='0';cnt1:="00000";
LCD_Data<="00000001"; -- /*清除显示*/ 清屏指令
Current_State<=set_cursor;
when set_cursor=> LCD_RS<='0';LCD_Data<="00111000";--/*设置8位格式,2行,5*7*/
Current_State<=set_dcb;
when set_dcb=> LCD_RS<='0';LCD_Data<="00001100"; --/*整体显示,关光标,不闪烁*/
Current_State<=set_cgram;
when set_cgram=> LCD_RS<='0';LCD_Data<="00000110"; --/*显示移动格式,看最后两位,10表示光标右移
Current_State<=set_ddram;
when set_ddram=> LCD_RS<='0';
IF CNT1<"01111" THEN CNT1:=CNT1+1; --主体显示,写显示地址DDRam(RS='0')
ELSE CNT1:="00000";
END IF;
IF CNT1<="01111" THEN LCD_Data <="10111111"+cnt1;
END IF;
Current_State<=write_cgram;
when write_cgram=> LCD_RS<='1'; --主体显示,写显示内容
LCD_Data<="01010000" +cnt1;
Current_State<=write_LCD_Data;
when write_LCD_Data=> LCD_RS<='0';LCD_Data<="00000000";
Current_State<=set_cursor;
when others => null;
end case;
end if;
end process;
end Behavioral;
一周热门 更多>