本帖最后由 dadjun 于 2010-10-19 18:25 编辑
module frequency(clk,rs,rw,en,data,fre_in);
input clk,fre_in;
output rs,rw,en;
output[7:0] data;
reg[25:0]cnt,fre_cnt,fre_data;
always @(posedge clk)
begin
cnt[25:0]=cnt[25:0]+1'b1;
if(cnt[25:0]==26'd50000000)
cnt=0;
end
always@(posedge fre_in)
begin
fre_cnt[25:0]=fre_cnt[25:0]+1'b1;
if(cnt[25:0]==26'd49999999)
fre_data=fre_cnt;
end
lcd display(
.clk(clk),
.rs(rs),
.rw(rw),
.en(en),
.data(data),
.cnt_fre(fre_data)
);
/*
function[25:0] fre;
input fre_dta;
case(fre_dta)
10000000:fre=1334545;
20000000:fre=4343545;
30000000:fre=86376545;
40000000:fre=51431545;
50000000:fre=78787845;
endcase
endfunction
*/
endmodule
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
液晶子模块
module lcd(clk,rs,rw,en,data,cnt_fre);
input clk;
output rs,rw,en;
output[7:0] data;
reg[7:0] data;
reg[7:0] current,next;
reg[15:0] count;
reg clkr;
reg rs,e;
reg[4:0] lcd_data,lcd_M,lcd_Mg,lcd_K,lcd_Kh,lcd_Kt,lcd_H,lcd_T,lcd_G;
input[25:0] cnt_fre;
parameter set0=8'h0; //定义了很多状态机
parameter set1=8'h1;
parameter set2=8'h2;
parameter set3=8'h3;
parameter set4=8'h4;
parameter set5=8'h5;
parameter set6=8'h6;
parameter data0=8'h7;
parameter data1=8'h8;
parameter data2=8'h9;
parameter data3=8'hA;
parameter data16=8'h18;
parameter data17=8'h19;
parameter data18=8'h1A;
parameter data19=8'h1B;
parameter data20=8'h1C;
parameter data21=8'h1D;
parameter data22=8'h1E;
parameter data23=8'h1F;
parameter data24=8'h20;
parameter data25=8'h21;
parameter data26=8'h22;
parameter nul=8'hf0;
always @(posedge clk)
begin
count[15:0]=count[15:0]+16'b1;
if(count==16'h000f)
clkr=~clkr;
end
/*******************************Remove the data every **************************************/
always @(cnt_fre)
begin
lcd_M=cnt_fre/10000000;
lcd_Mg=cnt_fre%10000000/1000000;
lcd_K=cnt_fre%1000000/100000;
lcd_Kh=cnt_fre%100000/10000;
lcd_Kt=cnt_fre%10000/1000;
lcd_H=cnt_fre%1000/100;
lcd_T=cnt_fre%100/10;
lcd_G=cnt_fre%10;
end
always @(posedge clkr)
begin
current=next;
case(current)
set0: begin e=1;rs=0;data=8'h30;next=set1; end//初始化液晶
set1: begin rs=0;data=8'h0c;next=set2; end
set2: begin rs=0;data=8'h6;next=set3; end
set3: begin rs=0;data=8'h1;next=set4;end
set4: begin rs=0;data=8'h80;next=data0;end
data0: begin rs=1;data="f";next=data1;end
data1: begin rs=1;data="r";next=data2;end
data2: begin rs=1;data="e";next=data3;end
data3: begin rs=1;data=":";next=set5;end
set5: begin rs=0;data=8'h90;next=data16;end
data16:begin rs=1;data=lcd_out(lcd_M);next=data17;end
data17:begin rs=1;data=lcd_out(lcd_Mg);next=data18;end
data18:begin rs=1;data=lcd_out(lcd_K);next=data19;end
data19:begin rs=1;data=lcd_out(lcd_Kh);next=data20;end
data20:begin rs=1;data=lcd_out(lcd_Kt);next=data21;end
data21:begin rs=1;data=lcd_out(lcd_H);next=data22;end
data22:begin rs=1;data=lcd_out(lcd_T);next=data23;end
data23:begin rs=1;data=lcd_out(lcd_G);next=data24;end
data24:begin rs=1;data="H";next=data26;end
data26:begin rs=1;data="Z";next=nul;end
nul: begin e=0;end
default: next=set0;
endcase
end
assign en=clkr&e;
assign rw=0;
function[7:0] lcd_out;
input[4:0] lcd_in;
begin
case(lcd_in)
0: lcd_out="0";
1: lcd_out="1";
2: lcd_out="2";
3: lcd_out="3";
4: lcd_out="4";
5: lcd_out="5";
6: lcd_out="6";
7: lcd_out="7";
8: lcd_out="8";
9: lcd_out="9";
endcase
end
endfunction
endmodule
这是为什么啊液晶只能响应一次啊,液晶子模块要怎么改啊,烦啊,哪位高手帮我看看阿,感激不尽 |