📄 lcd_display.vhd
字号:
library IEEE; ----利用DP-FPGA与精电蓬远液晶MDLS16265B测试
use IEEE.STD_LOGIC_1164.ALL; --显示magic!
use IEEE.STD_LOGIC_ARITH.ALL; --与上面程序功能相同,但显示速度很快,基本看不清光标的闪烁移位
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity lcd_display is
generic(N:integer:=25000;
delay:integer:=1); --改了此延时,造成该情况发生!
Port ( clk : in std_logic;
reset:in std_logic; --定义一个拔盘
lcdda : out std_logic;
lcdrw : out std_logic;
lcden : out std_logic;
test : out std_logic_vector(7 downto 0)
);
end lcd_display;
architecture Behavioral of lcd_display is
type state is (set_dlnf,clear_lcd,set_cursor,set_dcb,set_location,write_data);
signal current_state:state;
type rom is array(0 to 5) of std_logic_vector(7 downto 0);
constant datarom:rom:=(("01001101"),("01000001"),("01000111"),("01001001"),("01000011"),("00100001"));
signal clkk:std_logic;
signal data : std_logic_vector(7 downto 0);
begin
divider:process(clk,reset) --分频为1000HZ为1ms
variable cnt:integer range 0 to 100000;
begin
if reset='1'then cnt:=0;clkk<='0';
elsif rising_edge(clk) then
cnt:=cnt+1;
if cnt=N then clkk<='1'; --N=25000
elsif cnt=2*N then cnt:=0;clkk<='0';
end if;
end if;
end process divider;
control:process(clkk,reset,current_state)
variable cntt,cnt2:integer;
begin
if reset='1'then --复位信号初始化
current_state<=set_dlnf;
cntt:=0;
cnt2:=0;
elsif rising_edge(clkk)then
test<=data; --显示
case current_state is
when set_dlnf=> --功能设置
lcden<='0';
lcdda<='0';
lcdrw<='0';
data<="00111100";
if cntt=delay and cntt<delay*2 then --delay=100 延时100ms
lcden<='1';cntt:=cntt+1;
else
lcden<='0';cntt:=cntt+1;
end if;
if cntt=delay*2 then
current_state<=clear_lcd;
cntt:=0;
end if;
when clear_lcd=> --清屏幕
lcden<='0';
lcdda<='0';
lcdrw<='0';
data<="00000011";
if cntt=delay and cntt<delay*2 then --delay=100 延时100ms
lcden<='1';cntt:=cntt+1;
else
lcden<='0';cntt:=cntt+1;
end if;
if cntt=delay*2 then
current_state<=set_cursor;
cntt:=0;
end if;
when set_cursor=> --显示开关设置
lcden<='0';
lcdda<='0';
lcdrw<='0';
data<="00000010";
if cntt=delay and cntt<delay*2 then --delay=100 延时100ms
lcden<='1';cntt:=cntt+1;
else
lcden<='0';cntt:=cntt+1;
end if;
if cntt=delay*2 then
current_state<=set_dcb;
cntt:=0;
end if;
when set_dcb=> --输入方式设置
lcden<='0';
lcdda<='0';
lcdrw<='0';
data<="00001101";
if cntt=delay and cntt<delay*2 then --delay=100 延时100ms
lcden<='1';cntt:=cntt+1;
else
lcden<='0';cntt:=cntt+1;
end if;
if cntt=delay*2 then
current_state<=set_location;
cntt:=0;
end if;
when set_location=> --ddram设置
lcden<='0';
lcdda<='0';
lcdrw<='0';
data<="10000000";
if cntt=delay and cntt<delay*2 then --delay=100 延时100ms
lcden<='1';cntt:=cntt+1;
else
lcden<='0';cntt:=cntt+1;
end if;
if cntt=delay*2 then
current_state<=write_data;
cntt:=0;
end if;
when write_data=> --写数据
lcden<='0';
lcdda<='1';
lcdrw<='0';
if cnt2<=5 then
data<=datarom(cnt2);
if cntt=delay and cntt<delay*2 then --delay=100 延时100ms
lcden<='1';cntt:=cntt+1;
else
lcden<='0';cntt:=cntt+1;
end if;
if cntt=delay*2 then
current_state<=write_data;
cntt:=0;
cnt2:=cnt2+1;
end if;
else
cnt2:=0;
current_state<=set_dlnf;
end if;
end case;
end if;
end process;
end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -