[size=13.3333px]本来是个很小的东西,由于学艺不精,耽搁了好久才理出点头绪,在此把其中的小点滴与大家分享。欢迎指导!
[size=13.3333px]/*****************************************************
[size=13.3333px]1602液晶显示格式:
[size=13.3333px] HUMI : 36.8 %
[size=13.3333px] TEMP : 25.5 C
[size=13.3333px]
[size=13.3333px]*******************************************************/
[size=13.3333px]module lcd1602_module(clk,reset,rs,rw,en,data,data_in);
[size=13.3333px] input clk,reset;
[size=13.3333px] input [31:0] data_in; // 这个输入信号暂且不用
[size=13.3333px]
[size=13.3333px] output rs,rw,en;
[size=13.3333px] output [7:0] data;
[size=13.3333px]
[size=13.3333px] reg rs;
[size=13.3333px] reg [7:0] data;
[size=13.3333px]
[size=13.3333px]
[size=13.3333px] /***************************状态转换时钟********************************/
[size=13.3333px] parameter T1MS=32'd49_999;
[size=13.3333px]
[size=13.3333px] reg [31:0] count1;
[size=13.3333px] reg clk_en;
[size=13.3333px]
[size=13.3333px] always @(posedge clk or negedge reset)
[size=13.3333px] if(!reset)
[size=13.3333px] begin count1<=1'b0;clk_en<=1'b0;end
[size=13.3333px]
[size=13.3333px] else if(count1==T1MS)
[size=13.3333px] begin count1<=1'b0;clk_en<=~clk_en;end
[size=13.3333px] else count1<=count1+1'b1;
[size=13.3333px]
[size=13.3333px]
[size=13.3333px] /***************************操作液晶********************************/
[size=13.3333px]
[size=13.3333px] reg [5:0] i;
[size=13.3333px] reg en_temp;
[size=13.3333px] reg [1:0] count2;
[size=13.3333px]
[size=13.3333px] always @(posedge clk_en or negedge reset )
[size=13.3333px] if(!reset)
[size=13.3333px] begin i<=1'b0;en_temp<=1'b0;count2<=1'b0;end
[size=13.3333px]
[size=13.3333px] else
[size=13.3333px] begin
[size=13.3333px] case(i)
[size=13.3333px] 0: begin rs<=1'b0;data<=8'h38; i<=i+1'b1; end //设置16*2显示,5*7点阵,8位数据接口
[size=13.3333px] 1: begin rs<=1'b0;data<=8'h0c; i<=i+1'b1; end //开显示,不显示光标,
[size=13.3333px] 2: begin rs<=1'b0;data<=8'h06; i<=i+1'b1; end //写入一个字符后地址指针加一且光标加一
[size=13.3333px] 3: begin rs<=1'b0;data<=8'h01; i<=i+1'b1; end //显示清屏
[size=13.3333px] 4: begin rs<=1'b0;data<=8'h80; i<=i+1'b1; end //设置第一行地址
[size=13.3333px] 5: begin rs<=1'b1;data<="H";i<=i+1'b1;end
[size=13.3333px] 6: begin rs<=1'b1;data<="U";i<=i+1'b1;end
[size=13.3333px] 7: begin rs<=1'b1;data<="M";i<=i+1'b1;end
[size=13.3333px] 8: begin rs<=1'b1;data<="I";i<=i+1'b1;end
[size=13.3333px] 9: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
[size=13.3333px] 10: begin rs<=1'b1;data<=":";i<=i+1'b1;end
[size=13.3333px] 11: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
[size=13.3333px] 12: begin rs<=1'b1;data<="3";i<=i+1'b1;end
[size=13.3333px] 13: begin rs<=1'b1;data<="6";i<=i+1'b1;end
[size=13.3333px] 14: begin rs<=1'b1;data<=".";i<=i+1'b1;end
[size=13.3333px] 15: begin rs<=1'b1;data<="8";i<=i+1'b1;end
[size=13.3333px] 16: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
[size=13.3333px] 17: begin rs<=1'b1;data<="%";i<=i+1'b1;end
[size=13.3333px]
[size=13.3333px] 18: begin rs<=1'b0;data<=8'hc0; i<=i+1'b1; end // 设置第二行地址
[size=13.3333px] 19: begin rs<=1'b1;data<="T";i<=i+1'b1;end
[size=13.3333px] 20: begin rs<=1'b1;data<="E";i<=i+1'b1;end
[size=13.3333px] 21: begin rs<=1'b1;data<="M";i<=i+1'b1;end
[size=13.3333px] 22: begin rs<=1'b1;data<="P";i<=i+1'b1;end
[size=13.3333px] 23: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
[size=13.3333px] 24: begin rs<=1'b1;data<=":";i<=i+1'b1;end
[size=13.3333px] 25: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
[size=13.3333px] 26: begin rs<=1'b1;data<="2";i<=i+1'b1;end
[size=13.3333px] 27: begin rs<=1'b1;data<="5";i<=i+1'b1;end
[size=13.3333px] 28: begin rs<=1'b1;data<=".";i<=i+1'b1;end
[size=13.3333px] 29: begin rs<=1'b1;data<="5";i<=i+1'b1;end
[size=13.3333px] 30: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
[size=13.3333px] 31: begin rs<=1'b1;data<="C";i<=i+1'b1;end
[size=13.3333px]
[size=13.3333px] 32: begin rs<=1'b0;data<=8'b0000_0000;i<=0;
[size=13.3333px] if(count2==2'd2) // 这个地方我也不咋明白,为什么要限制写入的次数呢?
[size=13.3333px] en_temp<=1'b1;
[size=13.3333px] else
[size=13.3333px] begin en_temp<=1'b0;count2<=count2+1'b1;end
[size=13.3333px] end
[size=13.3333px] default: i<=1'b0;
[size=13.3333px] endcase
[size=13.3333px] end
[size=13.3333px]
[size=13.3333px] /*****************************************************************/
[size=13.3333px] assign en=clk_en|en_temp;
[size=13.3333px] assign rw=1'b0;
[size=13.3333px]endmodule
|