?? 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 + -