【正文】
tSETMODE : std_logic_vector(10 downto 0) :=00000000100。//輸入方式 //0x06//顯示光 標移動設置,當讀或寫一個字符后地址指針加 1,且光標加 1 constantSWITCHMODE:std_logic_vector(10downto0) :=00000001000。/顯示開關 //0x0c//開顯示 。不顯示光標 。光標不閃爍 constant SHIFT : std_logic_vector(10 downto 0) :=00000011000。 //移位調(diào)整 //0x81//顯示位移 。左移 constantSETFUNCTION:std_logic_vector(10downto0) :=00000100000。//功能設置 //0x3C//8 位 。兩行顯示 16*2 。 constantSETCGRAM:std_logic_vector(10downto 0) :=00001000000。//字符發(fā)生存儲器地址 ACG constantSETDDRAM:std_logic_vector(10downto 0) :=00010000000。//設置 DDRAM( 顯示數(shù)據(jù) RAM) 的地址//0x80 顯 示 數(shù) 據(jù) 儲 存 器 地 址 ADD //0xc0 顯示數(shù)據(jù)儲存器地址 ADD 第 8 二行開頭 constant READFLAG : std_logic_vector(10 downto 0) :=00100000000。//忙標志 constant WRITERAM: std_logic_vector(10 downto 0) :=01000000000。 寫數(shù)據(jù)到 CGRAM 或者 DDRAM constantREADRAM: std_logic_vector(10 downto 0) :=10000000000。//從CGRAM 或者 DDRAM 讀數(shù) signal state : std_logic_vector(10 downto 0)。 signal counter : integer range 0 to 127。 signal div_counter : integer range 0 to 15。 signal flag : std_logic。 constant DIVSS : integer :=15。 signal char_addr: std_logic_vector(6 downto 0)。 signal data_in : std_logic_vector(7 downto 0)。 ponent char_ram2 port( address : in std_logic_vector(6 downto 0) 。 data : out std_logic_vector(7 downto 0) )。 end ponent。元件例化語句 signal clk_int: std_logic。 signal clkt: std_logic_vector(18 downto 0)。 constant divt: std_logic_vector(18 downto 0):=1111001110001000000。 //498752 signal a:integer。 signal clkdiv: std_logic。 signal tc_clkt: std_logic。 signal k: integer。 顯示步進 signal yi: std_logic。 顯示左移還是右移 signal zanting: std_logic。顯示暫停還是流動 begin process(key)該部分控制分頻步進是 1 還是 5,即是控制字符流動速度 begin case key is when 39。039。=k=1。 when 39。139。=k=5。 when others=null。 end case。 end process。 process(key1)—該部分控制液晶 整屏左移還是右移 1 是左移, 0 右移 9 begin case key1 is when 39。139。=yi=39。139。 when 39。039。=yi=39。039。 when others=null。 end case。 end process。 process(key2)—該部分控制整屏暫停還是流動 1 暫停, 0 流動 begin case key2 is when 39。139。=zanting=39。139。 when 39。039。=zanting=39。039。 when others=null。 end case。 end process。 process(clk,reset) begin if(reset=39。039。)then clkt=0000000000000000000。 elsif(clk39。event and clk=39。139。)then if(clkt=divt)then // t=498752*25ns= clkt=0000000000000000000。 else clkt=clkt+k。 end if。 end if。 end process。 tc_clkt=39。139。 when clkt=divt else // 產(chǎn)生計數(shù)溢出脈沖 39。039。 process(tc_clkt,reset) begin if(reset=39。039。)then clkdiv=39。039。 elsif(tc_clkt39。event and tc_clkt=39。139。)then clkdiv=not clkdiv。 //翻轉時鐘 t=25ms f=40hz end if。 end process。 process(clkdiv,reset) begin if(reset=39。039。)then 10 clk_int=39。039。 elsif(clkdiv39。event and clkdiv=39。139。)then clk_int= not clk_int。 //分頻 t=50ms f=20hz end if。 end process。 process(clkdiv,reset) begin if(reset=39。039。)then lcd_e=39。039。 elsif(clkdiv39。event and clkdiv=39。039。)then lcd_e= not lcd_e。 //使能信號翻轉 t=100ms f=10hz end if。 end process。 aa:char_ram2—例化程序 port map( address=char_addr,data=data_in)。 lcd_rs = 39。139。 when state =WRITERAM or state = READRAM else 39。039。 //當 lcd_rs=1 時,為數(shù)據(jù); =0 時,為命令 lcd_rw = 39。039。 when state =CLEAR or state = RETURNCURSOR or state=SETMODE or state=SWITCHMODE or state=SHIFT or state= SETFUNCTION or state=SETCGRAM or state =SETDDRAM or state =WRITERAM else 39。139。 //=0,寫; =1,讀 data =000