📄 lcd_driver.vhd
字号:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity LCD_Driver is port( clock : IN std_logic; RS : OUT std_logic; RW : OUT std_logic; EN : OUT std_logic; Exceed_Speed : in std_logic; New_Data : in std_logic; Write_complete : OUT std_logic; Speed_digit1 : IN std_logic_vector(7 downto 0); Speed_digit2 : IN std_logic_vector(7 downto 0); Speed_digit3 : IN std_logic_vector(7 downto 0); Range_digit1 : IN std_logic_vector(7 downto 0); Range_digit2 : IN std_logic_vector(7 downto 0); Range_digit3 : IN std_logic_vector(7 downto 0); DATA : OUT std_logic_vector(3 downto 0) ); end LCD_Driver; architecture Behavioral of LCD_Driver is signal substate,counter,Cursor: integer:=0; signal state: integer:=0; signal nhdata_Int :std_logic_vector(3 downto 0) :="0000" ; signal nldata_Int :std_logic_vector(3 downto 0) :="0000" ; signal Write_TO_LCD :std_logic :='0'; signal LCD_Init_done :std_logic :='0'; signal instruct_to_lcd :std_logic :='0'; signal New_Data_Previous:std_logic :='0'; signal Clear_LCD :std_logic :='0'; begin process(Clock) begin if(rising_edge(Clock)) then counter<=counter+1; --WAIT FOR 750000 counter ---<POWER ON>--<Wait at least 15ms> if(state=0 and counter=750000) then state<=1; counter<=0; --WRITE DATA=0X3 FOR INIATION elsif(state=1) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0000"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="0011"; counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=2; counter<=0; end if; --WAIT FOR 2050000 counter --<Wait at least 4.1ms> elsif(state=2 and counter=205000) then state<=3; counter<=0; --WRITE DATA=0X3 FOR INIATION elsif(state=3) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0000"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="0011"; counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=4; counter<=0; end if; --WAIT 5000 counter --<Wait at least 100us> elsif(state=4 and counter=5000) then state<=5; counter<=0; --WRITE 0X3 FOR INITIATION elsif(state=5) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0000"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="0011"; counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=6; counter<=0; end if; --WAIT FOR 2050000 counter --<Wait at least 4.1ms> elsif(state=6 and counter=205000) then --2050000 state<=7; counter<=0; --WRITE DATA=0X2 FOR INITIATION elsif(state=7) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0000"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="0010"; counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=8; counter<=0; end if; --WAIT 2000 counter <Wait 40us> elsif(state=8 and counter=2000) then state<=9; counter<=0; --WRITE FUNCTION SET SD_F = 0X28 ;Function Set Command elsif(state=9) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0010"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="1000"; --for 5x8 dot matrix--1/16 duty cycle -- 2 `lines' counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=10; --10 counter<=0; end if; --WAIT 2000 counter <Wait 40us>-- this must go to state 17 elsif(state=10 and counter=2000) then state<=11; counter<=0; --WRITE ENTRY SET DATA = 0X06 elsif(state=11) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0000"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="0110"; --;;Inc cursor to the right when writing ; and don?t shift screen counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=12; counter<=0; end if; --WAIT 2000 counter elsif(state=12 and counter=2000) then state<=13; counter<=0; --WRITE DISPLAY ON /OFF SD_F=0X0C elsif(state=13) then if(substate=0 and counter=0) then RS<='0'; RW<='0'; DATA<="0000"; counter<=0; substate<=1; elsif(substate=1 and counter=2) then EN<='1'; counter<=0; substate<=2; elsif(substate=2 and counter=12) then EN<='0'; substate<=3; counter<=0; elsif(substate=3 and counter=48) then DATA<="1100"; ---care in this case Display on, Cursor off, Blink off counter<=0; substate<=4; elsif(substate=4 and counter=2) then EN<='1'; counter<=0; substate<=5; elsif(substate=5 and counter=12) then EN<='0'; substate<=0; state<=14; counter<=0; end if; --WAIT 2000 counter elsif(state=14 and counter=2000) then LCD_Init_done<='1';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -