📄 lcddriver.vhd
字号:
-- EE552 Sign Language Glove Project--References:--www.ee.ualberta.ca/~elliott/ee552/studentAppNotes/2000_w/interfacing/lcd_driver/lcddriver.vhd--and--www.ee.ualberta.ca/~elliott/ee552/studentAppNotes/1997f/lcd/lcd.htmllibrary ieee;use ieee.std_logic_1164.all;library work;use work.LCD_pkg.all;entity LCDdriver is generic( big_delay: integer := 2000; -- delay needed for slow instructions small_delay: integer :=100; -- delay needed for fasttructions setup_delay: integer := 50 -- initial delay); port( clock: in std_logic; reset: in std_logic; message: in std_logic_vector( LCDdatasize - 1 downto 0 ); enable: in std_logic; lcd_data: out std_logic_vector( LCDdatasize - 1 downto 0 ); lcd_rs: out std_logic; lcd_rw: out std_logic; lcd_enable: out std_logic; LED1: out std_logic_vector( LEDseg - 1 downto 0 ); LED2: out std_logic_vector( LEDseg - 1 downto 0 ) ); end entity LCDdriver; -- Architecture Description architecture Display of LCDdriver is type state_type is (initial, display, entrymode, clear, waiting, verify, putchar, homecursor);signal state: state_type;signal prev_state: state_type;begin process (clock,reset) variable position: integer range 0 to lastposition; variable count: integer range 0 to big_delay; variable initcount: integer range 0 to big_delay; begin if reset = '0' then --active low reset state <=initial; position:=0; count:=0; initcount:=0; LED1 <= "1000000"; LED2 <= "1000000"; elsif clock'event and clock = '1' then case state is when initial => -- set SET (initalization step) if initcount < big_delay then --create delay at beginning initcount :=initcount + 1; else if count < setup_delay then lcd_enable <= '1'; -- enable LCD else lcd_enable <= '0'; end if; LED1 <= "1111001";--1 lcd_data <=SET; -- send SET instruction lcd_rs<='0'; -- instruction mode lcd_rw<='0'; -- when count = small delay, go onto the next state if count = small_delay then prev_state <= initial; state<=display; count:=0; else-- else increment the count count:=count+1; end if; end if; when display => -- to set DISPLAY (initalization step) if count < setup_delay then lcd_enable <= '1'; -- enable LCD else lcd_enable <= '0'; end if; LED1 <= "0100100";--2 lcd_data<=DON; lcd_rs<='0'; lcd_rw<='0'; if count=small_delay then prev_state <= display; state<=clear; count:=0; else count:=count+1; end if; when clear => -- clear the screen (initalization step) if count < setup_delay then lcd_enable <= '1'; -- enable LCD else lcd_enable <= '0'; end if; LED1 <= "0110000"; --3 lcd_data<=CLR; lcd_rs<='0'; lcd_rw<='0'; if count = big_delay then if prev_state = homecursor then state<=putchar; elsif prev_state = display then state<=entrymode; end if; prev_state <= clear; count:=0; else count:=count+1; end if; when entrymode => -- to set ENTRY MODE (initalization step) LED1 <= "0011001";--4 if count < setup_delay then lcd_enable <= '1'; -- enable LCD else lcd_enable <= '0'; end if; lcd_data<=SEM; lcd_rs<='0'; lcd_rw<='0'; if count=small_delay then prev_state <= entrymode; state<=waiting; count:=0; else count:=count+1; end if; when waiting => -- wait enable to go low (i.e. current input done) LED1 <= "0010010";--5 if enable='1' then state<=verify; end if; when verify => -- wait enable to go high (i.e. next input coming) -- if recieved an enable (incoming data) LED1 <= "0000010"; --6 if enable='0' then -- if end of display is reached, goto state homecursor if position=lastposition then prev_state <= verify; state<=homecursor; position:=0; else -- else goto putchar state<=putchar; end if; end if; when putchar=> -- display the character on the LCD LED1 <= "0000000";--8 if count < setup_delay then lcd_enable <= '1'; -- enable LCD else lcd_enable <= '0'; end if; lcd_data <= message; --send msg to LCD lcd_rs<='1'; -- set to data mode lcd_rw<= '0'; if count=big_delay then prev_state <= putchar; state<=waiting; -- go back to waiting when done position:=position+1; --increment the position for next char count:=0; else count:=count+1; end if; when homecursor=> --resets the cursor back to beginning of line LED1 <= "1111000";--7 if count < setup_delay then lcd_enable <= '1'; -- enable LCD else lcd_enable <= '0'; end if; lcd_data<= HOME; --sets cursor to beginning lcd_rs<='0'; lcd_rw<='0'; if count = big_delay then prev_state <= homecursor; state<=clear; count:=0; else count:=count+1; end if; end case; end if; end process;end architecture Display;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -