|
本帖最后由 hughqfb 于 2013-5-9 14:15 编辑
本来是个很小的东西,由于学艺不精,耽搁了好久才理出点头绪,在此把其中的小点滴与大家分享。欢迎指导!
/*****************************************************
1602液晶显示格式:
HUMI : 36.8 %
TEMP : 25.5 C
*******************************************************/
module lcd1602_module(clk,reset,rs,rw,en,data,data_in);
input clk,reset;
input [31:0] data_in; // 这个输入信号暂且不用
output rs,rw,en;
output [7:0] data;
reg rs;
reg [7:0] data;
/***************************状态转换时钟********************************/
parameter T1MS=32'd49_999;
reg [31:0] count1;
reg clk_en;
always @(posedge clk or negedge reset)
if(!reset)
begin count1<=1'b0;clk_en<=1'b0;end
else if(count1==T1MS)
begin count1<=1'b0;clk_en<=~clk_en;end
else count1<=count1+1'b1;
/***************************操作液晶********************************/
reg [5:0] i;
reg en_temp;
reg [1:0] count2;
always @(posedge clk_en or negedge reset )
if(!reset)
begin i<=1'b0;en_temp<=1'b0;count2<=1'b0;end
else
begin
case(i)
0: begin rs<=1'b0;data<=8'h38; i<=i+1'b1; end //设置16*2显示,5*7点阵,8位数据接口
1: begin rs<=1'b0;data<=8'h0c; i<=i+1'b1; end //开显示,不显示光标,
2: begin rs<=1'b0;data<=8'h06; i<=i+1'b1; end //写入一个字符后地址指针加一且光标加一
3: begin rs<=1'b0;data<=8'h01; i<=i+1'b1; end //显示清屏
4: begin rs<=1'b0;data<=8'h80; i<=i+1'b1; end //设置第一行地址
5: begin rs<=1'b1;data<="H";i<=i+1'b1;end
6: begin rs<=1'b1;data<="U";i<=i+1'b1;end
7: begin rs<=1'b1;data<="M";i<=i+1'b1;end
8: begin rs<=1'b1;data<="I";i<=i+1'b1;end
9: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
10: begin rs<=1'b1;data<=":";i<=i+1'b1;end
11: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
12: begin rs<=1'b1;data<="3";i<=i+1'b1;end
13: begin rs<=1'b1;data<="6";i<=i+1'b1;end
14: begin rs<=1'b1;data<=".";i<=i+1'b1;end
15: begin rs<=1'b1;data<="8";i<=i+1'b1;end
16: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
17: begin rs<=1'b1;data<="%";i<=i+1'b1;end
18: begin rs<=1'b0;data<=8'hc0; i<=i+1'b1; end // 设置第二行地址
19: begin rs<=1'b1;data<="T";i<=i+1'b1;end
20: begin rs<=1'b1;data<="E";i<=i+1'b1;end
21: begin rs<=1'b1;data<="M";i<=i+1'b1;end
22: begin rs<=1'b1;data<="P";i<=i+1'b1;end
23: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
24: begin rs<=1'b1;data<=":";i<=i+1'b1;end
25: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
26: begin rs<=1'b1;data<="2";i<=i+1'b1;end
27: begin rs<=1'b1;data<="5";i<=i+1'b1;end
28: begin rs<=1'b1;data<=".";i<=i+1'b1;end
29: begin rs<=1'b1;data<="5";i<=i+1'b1;end
30: begin rs<=1'b1;data<=" ";i<=i+1'b1;end
31: begin rs<=1'b1;data<="C";i<=i+1'b1;end
32: begin rs<=1'b0;data<=8'b0000_0000;i<=0;
if(count2==2'd2) // 这个地方我也不咋明白,为什么要限制写入的次数呢?
en_temp<=1'b1;
else
begin en_temp<=1'b0;count2<=count2+1'b1;end
end
default: i<=1'b0;
endcase
end
/*****************************************************************/
assign en=clk_en|en_temp;
assign rw=1'b0;
endmodule
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|