2# philoman
我刚刚开始学,这是我的程序,麻烦您帮我看一下吧。我是想在xilinx sparten 3e板的lcd上显示字符,就麻烦您帮我找一找错误了
module lcd(clk,reset,lcd_rs,lcd_rw,lcd_en,data);
input clk,reset;
output lcd_rs,lcd_rw,lcd_en;
output[3:0] data;
reg [3:0] data;
reg lcd_rs,lcd_rw,lcd_en;
reg[3:0] state;
parameter write_instr='h1,write_dataup4_1='h2,write_datadown4_1='h3,set_ddramaddup='h4,set_ddramadddown='h5,write_dataup4_2='h6,write_datadown4_2='h7;
reg [7:0]myramup[39:0];
reg [7:0]myramdown[39:0];
reg lcd_clk;
reg[39:0]datacnt;
reg [32:0] n;
initial begin
lcd_clk<=0;
datacnt<=0;
lcd_rw<=0;
lcd_en<=lcd_clk;
n=0;
end
initial begin
{myramup[0],myramup[1],myramup[2],myramup[3],myramup[4],myramup[5],myramup[6],myramup[7],myramup[8],myramup[9],myramup[10],myramup[11],myramup[12],myramup[13],myramup[14],myramup[15],myramup[16],myramup[17],myramup[18],myramup[19],myramup[20],myramup[21],myramup[22],myramup[23],myramup[24],myramup[25],myramup[26],myramup[27],myramup[28],myramup[29],myramup[30],myramup[31],myramup[32],myramup[33],myramup[34],myramup[35],myramup[36],myramup[37],myramup[38],myramup[39]}="320'h4c6174792049204c6f766520596f7520466f72657665722021202032303037b039b03230202020";
{myramdown[0],myramdown[1],myramdown[2],myramdown[3],myramdown[4],myramdown[5],myramdown[6],myramdown[7],myramdown[8],myramdown[9],myramdown[10],myramdown[11],myramdown[12],myramdown[13],myramdown[14],myramdown[15],myramdown[16],myramdown[17],myramdown[18],myramdown[19],myramdown[20],myramdown[21],myramdown[22],myramdown[23],myramdown[24],myramdown[25],myramdown[26],myramdown[27],myramdown[28],myramdown[29],myramdown[30],myramdown[31],myramdown[32],myramdown[33],myramdown[34],myramdown[35],myramdown[36],myramdown[37],myramdown[38],myramdown[39]}=320'h4d6572727920546865204d6964b0617574756d6e2044617920212020546875727364617920202020;
end
always @(posedge clk)
begin
if(n<7999999)
n=n+1;
else
begin
n=0;
lcd_clk=~lcd_clk;
end
end
always @(posedge lcd_clk or negedge reset)
begin
if(reset==0)
begin
state=write_instr;
lcd_rs=0;
end
else
begin
case (state)
write_instr:
begin
lcd_rs=0;
case (datacnt)
0:
begin
data=0011;
datacnt=datacnt+1;
end
1:
begin
data=0011;
datacnt=datacnt+1;
end
2:
begin
data=0011;
datacnt=datacnt+1;
end
3:
begin
data=0010;
datacnt=datacnt+1;
end
4:
begin
data=0010;
datacnt=datacnt+1;
end
5:
begin
data=1000;
datacnt=datacnt+1;
end
6:
begin
data=0000;
datacnt=datacnt+1;
end
7:
begin
data=0111;
datacnt=datacnt+1;
end
8:
begin
data=0000;
datacnt=datacnt+1;
end
9:
begin
data=1100;
datacnt=datacnt+1;
end
10:
begin
data=1000;
datacnt=datacnt+1;
end
default:
begin
datacnt=0;
state=write_dataup4_1;
end
endcase
end
write_dataup4_1:
begin
lcd_rs=1;
data={myramup[datacnt][7],myramup[datacnt][6],myramup[datacnt][5],myramup[datacnt][4]};
state=write_datadown4_1;
end
write_datadown4_1:
begin
if(datacnt==39)
begin
data=myramup[datacnt][3:0];
datacnt=0;
state=set_ddramaddup;
end
else
begin
data=myramup[datacnt][3:0];
datacnt=datacnt+1;
state=write_dataup4_1;
end
end
set_ddramaddup:
begin
lcd_rs=0;
data=1100;
state=set_ddramadddown;
end
set_ddramadddown:
begin
data=0000;
state=write_dataup4_2;
end
write_dataup4_2:
begin
lcd_rs=1;
data={myramdown[datacnt][7],myramdown[datacnt][6],myramdown[datacnt][5],myramdown[datacnt][4]};
state=write_datadown4_2;
end
write_datadown4_2:
begin
if(datacnt==39)
begin
data=myramdown[datacnt][3:0];
datacnt=0;
state=write_dataup4_1;
end
else
begin
data=myramdown[datacnt][3:0];
datacnt=datacnt+1;
state=write_dataup4_2;
end
end
default:
state=write_instr;
endcase
end
end
endmodule |