always @(posedge clk)
if(!reset)
clk_reg<=0;
else
if(clk_reg<500000)
clk_reg<=clk_reg+1;
else
begin
clk_reg<=0;
fclk<=~fclk;
end
always @(posedge fclk or negedge reset)
begin
if(!reset)
begin
state<=8'h00;
flag<=0;
counter<=0;
counter1<=0;
sum<=0;
sum1<=0;
end
else
begin
case(state)
8'h00:
begin
if(!flag)
begin
flag<=1;
///counter<=0;
sum<=0;
state<=8'h01;
end
else
state<=8'h00;
/* if(sum<'d9999)
begin
sum<=sum+1;
state<=8'h00;
end
else
begin
sum<=0;
state<=8'h00;
end */
end
8'h01:
begin
rs<=0;
rw<=0;
data<=8'h30;
state<=8'h02;
end
8'h02:
begin
rs<=0;
rw<=0;
data<=8'h30;
state<=8'h03;
end
8'h03:
begin
rs<=0;
rw<=0;
data<=8'h0c;
state<=8'h04;
end
8'h04:
begin
rs<=0;
rw<=0;
data<=8'h01;
state<=8'h05;
end
8'h05:
begin
rs<=0;
rw<=0;
data<=8'h06;
state<=8'h07;
end
8'h06:
begin
rs<=0;
rw<=0;
state<=8'h07;
if(counter==7)
begin
counter<=counter+1;
data<=8'h90;
end
else
if(counter==15)
begin
counter<=counter+1;
data<=8'h88;
end
else
if(counter==23)
begin
counter<=counter+1;
data<=8'h98;
end
end
8'h07:
begin
rs<=1;
rw<=0;
// counter1<=counter1+1;
data<=data1;
counter1<=counter1+1;
// data<=8'hC0;
state<=8'h08;
end
8'h08:
begin
rs<=1;
rw<=0;
//data<="吕";
//data<=8'hC0+counter;
// counter1<=counter1+1;
data<=data1;
counter1<=counter1+1;
if(counter<7)
begin
counter<=counter+1;
state<=8'h07;
end
else
if(counter==7)
begin
state<=8'h06;
end
else
if(counter<15)
begin
state<=8'h07;
counter<=counter+1;
end
else
if(counter==15)
begin
state<=8'h06;
end
else
if(counter<23)
begin
state<=8'h07;
counter<=counter+1;
end
else
if(counter==23)
begin
state<=8'h06;
end
else
if(counter<31)
begin
state<=8'h07;
counter<=counter+1;
end
else
state<=8'h09;
end
/* 8'h09: begin
rs<=0;
rw<=1;
if(sum1<'d9999)
begin
sum1<=sum1+1;
state<=8'h09;
end
else
begin
sum1<=0;
state<=8'h09;
end
end
*/
8'h09: begin
rs<=0;
rw<=1;
if(key1==0)
begin
rs<=0;
rw<=0;
data<=8'h02;
counter<=0;
counter1<=0;
// counter1<=(counter1-64)>=0?(counter-64):0;
state<=8'h07;
end
else
if(key2==0)
begin
rs<=0;
rw<=0;
data<=8'h02;
counter<=0;
counter1<='d64;
state<=8'h07;
end
else
if(sum1<'d9999)
begin
sum1<=sum1+1;
state<=8'h09;
end
else
begin
sum1<=0;
state<=8'h09;
end
end
default: state<=8'h00;
endcase
end
end
assign en=fclk;
assign psb=1;
assign counter2=counter1;