资源描述:
《FPGA verilog实现的1602时钟计数器.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、FPGAverilog实现的1602时钟计数器 原文链接:熬夜到了1点了,终于写出了1602的时钟计数器代码。为什么是时钟计数器呢?因为我还没来得及做校准时间,所以只能称之为时钟计数器,不能成为电子钟。网上很少用人公开这一类代码,一搜FPGA1602,都是写一个静态的显示,在实际应用中,是没有用的,因此这个简单的例子,给大家抛砖引玉了!上代码:Qii9.0编译过,21EDA开发板测试OKmoduleLCD(rst,key1,clk,rw,rs,en,data);inputclk,rst,key1;outp
2、utrs,en,rw;output[7:0]data;regrs,en_sel;reg[7:0]data;reg[7:0]shi,fen,miao;reg[31:0]count,count1;//LCDCLK分频计数器reglcd_clk;reg[7:0]one_1,one_2,one_3,one_4,one_5,one_6,one_7,one_8,one_9,one_10,one_11,one_12,one_13,one_14,one_15,one_16;reg[7:0]two_1,two_2,two_3
3、,two_4,two_5,two_6,two_7,two_8,two_9,two_10,two_11,two_12,two_13,two_14,two_15,two_16;reg[7:0]next,xianshi,two;parameterstate0=8’h00,//设置8位格式,2行,5*78’h38;state1=8’h01,//整体显示,关光标,不闪烁8’h0C闪烁8’h0estate2=8’h02,//设定输入方式,增量不移位8’h06state3=8’h03,//清除显示8’h01state4=
4、8’h04,//显示第一行的指令80Hstate5=8’h05,//显示第二行的指令80H+40Hscan=8’h06,nul=8’h07;parameterdata0=8’h10,//2行,共32个数据data1=8’h11,data2=8’h12,data3=8’h13,data4=8’h14,data5=8’h15,data6=8’h16,data7=8’h17,data8=8’h18,data9=8’h19,data10=8’h20,data11=8’h21,data12=8’h22,data13=
5、8’h23,data14=8’h24,data15=8’h25,data16=8’h26,data17=8’h27,data18=8’h28,data19=8’h29,data20=8’h30,data21=8’h31,data22=8’h32,data23=8’h33,data24=8’h34,data25=8’h35,data26=8’h36,data27=8’h37,data28=8’h38,data29=8’h39,data30=8’h40,data31=8’h41;iniTIal//初始值begi
6、n//第一行显示TEL:13868160569one_1<=“T”;one_2<=“E”;one_3<=“L”;one_4<=“:”;one_5<=“1”;one_6<=“3”;one_7<=“8”;one_8<=“6”;one_9<=“8”;one_10<=“1”;one_11<=“6”;one_12<=“0”;one_13<=“5”;one_14<=“6”;one_15<=“9”;one_16<=““;//第二行显示Clock:00-00-00two_1<=“C”;two_2<=“l”;two_3<=“
7、o”;two_4<=“c”;two_5<=“k”;two_6<=“:”;two_7<=““;two_8<=““;two_9<=“-”;two_10<=““;two_11<=““;two_12<=“-”;two_13<=““;two_14<=““;two_15<=““;two_16<=““;shi<=0;fen<=0;miao<=0;endalways@(posedgeclk)//获得LCD时钟begincount<=count+1;if(count==250000)begincount<=0;lcd_clk
8、<=~lcd_clk;endendalways@(posedgeclkornegedgerst)//时钟计数器beginif(!rst)beginshi<=0;fen<=0;miao<=0;count1<=0;endelsebeginen_sel<=1;two_7<=(shi/10)+8’b00110000;two_8<=(shi%10)+8’b00110000;two_10<=(fen/10)+8’b00110