完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
module dd(clk,RS,RW,E,Data);
input clk;//50MHZ时钟的输入 output RS,RW,E;//1602的控制信号使能,数据/命令,读/写 output [7:0]Data;//数据端 reg RS; reg [7:0]Data; parameter address=8'h80;//第一行 parameter address2=8'hc0;//第二行 assign RW=1'b0;//只用显示时,一直是写的状态 reg clk_e; reg [15:0]count; always @(posedge clk) begin count=count+1'b1; if(count==16'd50000) begin clk_e=~clk_e;//作为使能端 count=16'd0; end end reg[27:0]cnt2; reg[3:0]cnt1; always @(posedge clk_e) if(cnt2==25000000)begin cnt1<=cnt1+1'b1;cnt2<=28'd0;end else if(cnt1>=9)cnt1<=4'd1; else cnt2<=cnt2+1'b1; reg [1:0]jishu; reg [4:0]zhuangtai;//状态机状态 reg temp; always @(posedge clk_e) begin case(zhuangtai) 5'b00000:begin temp<=1'b0; RS<=1'b0; Data<=8'h38;//显示模式设置 zhuangtai<=zhuangtai+1'b1; end 5'b00001:begin RS<=1'b0; Data<=8'h0c;//显示开及光标设置 zhuangtai<=zhuangtai+1'b1; end 5'b00010:begin RS<=1'b0; Data<=8'h06;//显示光标移动设置 zhuangtai<=zhuangtai+1'b1; end 5'b00011:begin RS<=1'b0; Data<=8'h01;//显示清屏 zhuangtai<=zhuangtai+1'b1;//前面几个状态是初始化的状态 end 5'b00100:begin RS<=1'b0; Data<=address;//设置显示起始地址,第一行起始位置开始显示 zhuangtai<=zhuangtai+1'b1; end 5'b00101:begin RS<=1'b1; Data<={4'b0011,cnt1[3:0]}; zhuangtai<=zhuangtai+1'b1; end 5'b00110:begin RS<=1'b1; Data<="a"; zhuangtai<=zhuangtai+1'b1; end 5'b00111:begin RS<=1'b1; Data<="x"; zhuangtai<=zhuangtai+1'b1; end 5'b01000:begin RS<=1'b1; Data<="i"; zhuangtai<=zhuangtai+1'b1; end 5'b01001:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b01010:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b01011:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b01100:begin RS<=1'b1; Data<="!"; zhuangtai<=zhuangtai+1'b1; end 5'b01101:begin RS<=1'b0; Data<=address2;//切换到第二行显示 zhuangtai<=zhuangtai+1'b1; end 5'b01110:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b01111:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b10000:begin RS<=1'b1; Data<=":"; zhuangtai<=zhuangtai+1'b1; end 5'b10001:begin RS<=1'b1; Data<="2"; zhuangtai<=zhuangtai+1'b1; end 5'b10010:begin RS<=1'b1; Data<="0"; zhuangtai<=zhuangtai+1'b1; end 5'b10011:begin RS<=1'b1; Data<="3"; zhuangtai<=zhuangtai+1'b1; end 5'b10100:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b10101:begin RS<=1'b1; Data<="6"; zhuangtai<=zhuangtai+1'b1; end 5'b10110:begin RS<=1'b1; Data<="9"; zhuangtai<=zhuangtai+1'b1; end 5'b10111:begin RS<=1'b1; Data<="7"; zhuangtai<=zhuangtai+1'b1; end 5'b11000:begin RS<=1'b1; Data<="8"; zhuangtai<=zhuangtai+1'b1; end 5'b11001:begin RS<=1'b1; Data<="8"; zhuangtai<=zhuangtai+1'b1; end 5'b11010:begin temp<=1'b1;//最后使能端一直拉高 zhuangtai<= 5'b00100; Data<=8'bz; end default zhuangtai<=4'b0000; endcase end reg D1,D2,D3,D4,D5; always @(posedge clk) begin D1<=clk_e; D2<=D1; D3<=D2; D4<=D3; D5<=D4; end assign E=D5|temp; endmodule 大家看看 5'b00101:begin RS<=1'b1; Data<={4'b0011,cnt1[3:0]}; zhuangtai<=zhuangtai+1'b1; end 为什么cnt1显示的数一直为0,而不是1,2,3,4.。。。呢? |
|
相关推荐
2个回答
|
|
我最近也写了一个lcd1602的驱动,但是每次下载运行的结果不一样,您知道可能的原因吗?
|
|
|
|
检查位数显示是不是漏写或多写
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1213 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1025 浏览 0 评论
2279 浏览 1 评论
1996 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2249 浏览 0 评论
1771 浏览 46 评论
6000 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-18 12:35 , Processed in 0.793861 second(s), Total 74, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号