always @ (posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
lcd_rs <= 0;
lcd_data <= 8'hXX;
end
else if(cmd_flag)
begin
// write statement
case(next_state)
IDLE : lcd_rs <= 0,lcd_data <= 8'hxx; //statement
//lcd init
DISP_SET : lcd_rs <= 0,lcd_data <= 8'h38; //statement
DISP_OFF : lcd_rs <= 0,lcd_data <= 8'h08; //statement
CLR_SCR : lcd_rs <= 0,lcd_data <= 8'h01; //statement
CURSOR_SET1 : lcd_rs <= 0,lcd_data <= 8'h06; //statement
CURSOR_SET2 : lcd_rs <= 0,lcd_data <= 8'h0C; //statement
// display 1th line
ROW1_ADDR : lcd_rs <= 0,lcd_data <= 8'h80; //statement
ROW1_0 : lcd_rs <= 1,lcd_data <= line_rom1[127:120]; //record
ROW1_1 : lcd_rs <= 1,lcd_data <= line_rom1[127:120]; //record
ROW1_2 : lcd_rs <= 1,lcd_data <= line_rom1[119:112]; //record
ROW1_3 : lcd_rs <= 1,lcd_data <= line_rom1[103:96]; //record
ROW1_4 : lcd_rs <= 1,lcd_data <= line_rom1[95:88]; //record
ROW1_5 : lcd_rs <= 1,lcd_data <= line_rom1[87:80]; //record
ROW1_6 : lcd_rs <= 1,lcd_data <= line_rom1[79:72]; //record
ROW1_7 : lcd_rs <= 1,lcd_data <= line_rom1[71:64]; //record
ROW1_8 : lcd_rs <= 1,lcd_data <= line_rom1[63:56]; //record
ROW1_9 : lcd_rs <= 1,lcd_data <= line_rom1[55:48]; //record
ROW1_A : lcd_rs <= 1,lcd_data <= line_rom1[47:40]; //record
ROW1_B : lcd_rs <= 1,lcd_data <= line_rom1[39:32]; //record
ROW1_C : lcd_rs <= 1,lcd_data <= line_rom1[31:24]; //record
ROW1_D : lcd_rs <= 1,lcd_data <= line_rom1[23:16]; //record
ROW1_E : lcd_rs <= 1,lcd_data <= line_rom1[15:8]; //record
ROW1_F : lcd_rs <= 1,lcd_data <= line_rom1[7:0]; //record
endcase
FPGA驱动LCD1602基本上就是这样的一个思想吧,关键都是要搞好时序图这一块,*****不是有首歌是这样唱的吗?“跟着感觉走,NoNoNo”写时序图也是这样,跟着节拍走,yeyeye。哈哈
更新点:(2014.03. 15 11:00)
应网友“飞言走笔”的提议,应该加上一个状态的转移图更能够让大伙了解时序图用状态机写的重要性。
状态图大致如下:
1:初始化开始
2:显示模式设置
3:显示关闭
4:显示清屏
5:显示光标移动设置
6:显示开及光标设置
7:第一行的地址
8:第一行的数据
用户443437 2014-3-14 21:16
飞言走笔 2014-3-14 14:56
用户443437 2014-3-12 21:17
用户377235 2014-3-12 16:05