📄 lcd1.v
字号:
module lcd1(clk,data,rst,rs,rw,en,cs1,cs2);
input clk,rst;
output [7:0] data;
output rs,rw,en,cs1,cs2;
reg [7:0] data,xaddr,yaddr,xpage;
reg [7:0] rom1[31:0],rom2[31:0],rom3[31:0],rom4[31:0];
reg en,rs,rw,cs1,cs2;
reg [3:0]cur_state,next_state;
parameter init=4'b0001, idle =4'b0010, write=4'b0100, read=4'b1000;
parameter writedata=4'b0001, writecmd=4'b0010;
reg [6:0] addr;
reg ison;
reg [2:0] count;
always @(negedge rst)
begin
if(!rst)
begin
rom1[0]=8'h08;rom1[1]=8'h08;rom1[2]=8'h08;rom1[3]=8'h88; //"东",
rom1[4]=8'h68;rom1[5]=8'h18;rom1[6]=8'h0f;rom1[7]=8'he8;
rom1[8]=8'h08;rom1[9]=8'h08;rom1[10]=8'h08;rom1[11]=8'h88;
rom1[12]=8'h08;rom1[13]=8'h0c;rom1[14]=8'h08;rom1[15]=8'h00;
rom1[16]=8'h00;rom1[17]=8'h40;rom1[18]=8'h21;rom1[19]=8'h11;
rom1[20]=8'h0d;rom1[21]=8'h41;rom1[22]=8'h81;rom1[23]=8'h7f;
rom1[24]=8'h01;rom1[25]=8'h05;rom1[26]=8'h09;rom1[27]=8'h31;
rom1[28]=8'h61;rom1[29]=8'h00;rom1[30]=8'h00;rom1[31]=8'h00;
rom2[0]=8'h02;rom2[1]=8'hf2;rom2[2]=8'h12;rom2[3]=8'h12; //"疆",
rom2[4]=8'h12;rom2[5]=8'h3e;rom2[6]=8'h82;rom2[7]=8'hfa;
rom2[8]=8'haa;rom2[9]=8'haa;rom2[10]=8'hfa;rom2[11]=8'haa;
rom2[12]=8'haa;rom2[13]=8'hfb;rom2[14]=8'h82;rom2[15]=8'h00;
rom2[16]=8'h20;rom2[17]=8'h25;rom2[18]=8'h1f;rom2[19]=8'h55;
rom2[20]=8'h81;rom2[21]=8'h7f;rom2[22]=8'h80;rom2[23]=8'hbe;
rom2[24]=8'haa;rom2[25]=8'haa;rom2[26]=8'hbe;rom2[27]=8'haa;
rom2[28]=8'haa;rom2[29]=8'hbe;rom2[30]=8'h80;rom2[31]=8'h00;
rom3[0]=8'h20;rom3[1]=8'h24;rom3[2]=8'h24;rom3[3]=8'ha4; //"教",
rom3[4]=8'hff;rom3[5]=8'ha4;rom3[6]=8'hb4;rom3[7]=8'hac;
rom3[8]=8'h20;rom3[9]=8'h9f;rom3[10]=8'h10;rom3[11]=8'h10;
rom3[12]=8'hf0;rom3[13]=8'h18;rom3[14]=8'h10;rom3[15]=8'h00;
rom3[16]=8'h02;rom3[17]=8'h12;rom3[18]=8'h51;rom3[19]=8'h90;
rom3[20]=8'h7e;rom3[21]=8'h0a;rom3[22]=8'h89;rom3[23]=8'h40;
rom3[24]=8'h20;rom3[25]=8'h1b;rom3[26]=8'h04;rom3[27]=8'h1b;
rom3[28]=8'h60;rom3[29]=8'hc0;rom3[30]=8'h40;rom3[31]=8'h00;
rom4[0]=8'h80;rom4[1]=8'h40;rom4[2]=8'h20;rom4[3]=8'hf8; //"仪",
rom4[4]=8'h07;rom4[5]=8'h00;rom4[6]=8'h38;rom4[7]=8'hc0;
rom4[8]=8'h02;rom4[9]=8'h04;rom4[10]=8'h0c;rom4[11]=8'h80;
rom4[12]=8'h60;rom4[13]=8'h1c;rom4[14]=8'h00;rom4[15]=8'h00;
rom4[16]=8'h00;rom4[17]=8'h00;rom4[18]=8'h00;rom4[19]=8'hff;
rom4[20]=8'h80;rom4[21]=8'h40;rom4[22]=8'h20;rom4[23]=8'h10;
rom4[24]=8'h0b;rom4[25]=8'h04;rom4[26]=8'h0a;rom4[27]=8'h11;
rom4[28]=8'h60;rom4[29]=8'hc0;rom4[30]=8'h40;rom4[31]=8'h00;
end
end
always @(negedge en)
cur_state=next_state;
always @(posedge clk)
begin
count=count+1;
if(count<4)
en=0;
else
en=1;
end
always @(negedge en)
if(!rst)
begin
next_state=s1;
rs=0;
rw=0;
if(!ison)
begin
cs1=0;
cs2=1;
data=8'h3f;
ison=1;
end
else
begin
cs1=1;
cs2=0;
data=8'h3f;
ison=0;
end
xaddr=8'hb8;
yaddr=8'h40;
xpage=8'hb8;
end
else
begin
case(cur_state)
init: begin
cs1<=1;
cs2<=0;
rs<=0;
rw<=0;
data<=8'hc0;
xpage<=8'hb8;
next_state<=s2;
end
s2: begin
rs<=0;
data<=xpage;
next_state<=s3;
end
s3: begin
rs<=0;
data<=8'h40;
next_state<=s4;
addr<=0;
end
s4:begin
cs1<=1; //左半屏清零
cs2<=0;
rs<=1;
data<=8'h00;
if(xpage>=8'hbf)
begin
if(addr>63)
begin addr<=0; next_state<=s5; end
else
begin addr<=addr+1; next_state<=s4; end
end
else
begin
if(addr>63)
begin xpage<=xpage+1; next_state<=s2; end
else
begin addr<=addr+1; next_state<=s4; end
end
end
s5: begin
cs1<=0;
cs2<=1;
rs<=0;
data<=8'hc0;
xpage<=8'hb8;
next_state<=s6;
end
s6: begin
rs<=0;
data<=xpage;
next_state<=s7;
end
s7: begin
rs<=0;
data<=8'h40;
next_state<=s8;
addr<=0;
end
s8: begin
cs1<=0;
cs2<=1;
rs=1;//右半屏清零
data<=8'h00;
if(xpage>=8'hbf)
begin
if(addr>63)
begin addr<=0; next_state<=s9; end
else
begin addr<=addr+1; next_state<=s8; end
end
else
begin
if(addr>63)
begin xpage<=xpage+1; next_state<=s6; end
else
begin addr<=addr+1; next_state<=s8; end
end
end
endmodule
/*
--"东",
x"08",x"08",x"08",x"88",x"68",x"18",x"0F",x"E8",
x"08",x"08",x"08",x"88",x"08",x"0C",x"08",x"00",
x"00",x"40",x"21",x"11",x"0D",x"41",x"81",x"7F",
x"01",x"05",x"09",x"31",x"61",x"00",x"00",x"00");
--"疆",
constant rom2:rom:=(
x"02",x"F2",x"12",x"12",x"12",x"3E",x"82",x"FA",
x"AA",x"AA",x"FA",x"AA",x"AA",x"FB",x"82",x"00",
x"20",x"25",x"1F",x"55",x"81",x"7F",x"80",x"BE",
x"AA",x"AA",x"BE",x"AA",x"AA",x"BE",x"80",x"00");
--"教",
constant rom3:rom:=(
x"20",x"24",x"24",x"A4",x"FF",x"A4",x"B4",x"AC",
x"20",x"9F",x"10",x"10",x"F0",x"18",x"10",x"00",
x"02",x"12",x"51",x"90",x"7E",x"0A",x"89",x"40",
x"20",x"1B",x"04",x"1B",x"60",x"C0",x"40",x"00");
--"仪",
constant rom4:rom:=(
x"80",x"40",x"20",x"F8",x"07",x"00",x"38",x"C0",
x"02",x"04",x"0C",x"80",x"60",x"1C",x"00",x"00",
x"00",x"00",x"00",x"FF",x"80",x"40",x"20",x"10",
x"0B",x"04",x"0A",x"11",x"60",x"C0",x"40",x"00");
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -