📄 lcd_init_0707.v
字号:
3://blue
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) && (h_counter<=244))
begin
red[5:0]<=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h3f;
end
end
4://white
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) &&( h_counter<=244))
begin
red[5:0]<=6'h3f;
green[5:0]<=6'h3f;
blue[5:0]<=6'h3f;
end
end
5://black
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) && (h_counter<=244))
begin
red[5:0]<=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h00;
end
end
6://frame
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) && (h_counter<=244))
begin
if(h_counter==5)
begin
red[5:0]=6'h3f;
green[5:0]<=6'h00;
blue[5:0]<=6'h00;
end
else if(h_counter==244)
begin
red[5:0]=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h3f;
end
else if(v_counter==2 | v_counter==321)
begin
red[5:0]=6'h3f;
green[5:0]<=6'h3f;
blue[5:0]<=6'h3f;
end
else
begin
red[5:0]=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h00;
end
end
end
7://crosstalk
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) &&( h_counter<=244))
begin
if((v_counter>=109)&&(v_counter<=215)
&&(h_counter>=85) && (h_counter<=164))
begin
red[5:0]=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h00;
end
else
begin
red[5:0]=6'd46;
green[5:0]<=6'd46;
blue[5:0]<=6'd46;
end
end
end
8://v_gray
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5 )&& (h_counter<=244))
begin
red[5:0]=((v_counter-2)/20)<<2;
green[5:0]=((v_counter-2)/20)<<2;
blue[5:0]=((v_counter-2)/20)<<2;
end
end
9://h_gray
if(!dotclk && state_dclk==S00)
begin
if(v_counter==1)
begin
oe<=1;
we<=1;
ce<=1;
touch_time<=0;
measure_time<=0;
test<=0;
end
else if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) &&( h_counter<=244))
begin
touch_time<=0;
red[5:0]=((h_counter-5)/15)<<2;
green[5:0]=((h_counter-5)/15)<<2;
blue[5:0]=((h_counter-5)/15)<<2;
end
end
10://face if(!penirq)
begin
if(v_counter<=1)
begin
A<=PIC06;
oe<=1;
we<=1;
ce<=1;
red[5:0]<=6'bz;
green[5:0]<=6'bz;
blue[5:0]<=6'bz;
state_wq<=0;
end
else if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) && (h_counter<=244))
begin
if (dotclk && state_dclk==S03)
begin
if(v_counter==2 && h_counter==5) A=PIC06;
else
A<=A+1;
oe<=0;
we<=1;
ce<=0;
red[5:0]<=6'bz;
green[5:0]<=6'bz;
blue[5:0]<=6'bz;
db21<=1'bz;
db20<=1'bz;
db19<=1'bz;
db18<=1'bz;
end
else if(!dotclk && state_dclk==S02)
begin
r_temp[5:0]={db23,db22,db21,db20,db19,db18};
g_temp[5:0]={red[3:0],green[5:4]};
b_temp[5:0]={green[1:0],blue[5:2]};
oe=1;
ce=1;
red=r_temp;
green=g_temp;
blue=b_temp;
//state_wq<=2;
end
end
else
begin
oe<=1;
ce<=1;
red[5:0]<=6'bz;
green[5:0]<=6'bz;
blue[5:0]<=6'bz;
state_wq<=0;
end
end
11:
if(!dotclk && state_dclk==S00)
begin
if( able
&& (v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) && (h_counter<=244))
begin
case(touch_time)
0://
begin
if((v_counter>=2)&&(v_counter<=22)
&&(h_counter>=5) && (h_counter<=25))
begin
red[5:0]<=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h3f;
end
else
begin
red[5:0]<=6'b0;
green[5:0]<=6'b0;
blue[5:0]<=6'b0;
end
if(!penirq_out && !test) test<=1;
if(test==1)
begin
case( measure_time)
0:
begin
AddressByte<=8'h96;//----setup command
DataByte1<=8'hc0;
measure_time<=1;
end
1:
begin
if(delay_measure_count<=26666)//10000
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=2;
end
end
2:
begin
AddressByte<=8'h97;//----setup command
measure_time<=3;
end
3:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=4;
tpx1={DataByte1_rd[7:0],DataByte2_rd[7:4]};
end
end
4:
begin
touch_time<=0;
AddressByte<=8'h96;//----setup command
DataByte1<=8'hd0;
measure_time<=5;
end
5:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=6;
end
end
6:
begin
AddressByte<=8'h97;//----setup command
measure_time<=7;
end
7:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=0;
test<=2;
end
end
endcase
end
else if(test==2 && penirq_out )
begin
touch_time<=1;
test<=0;
tpy1={DataByte1_rd[7:0],DataByte2_rd[7:4]};
end
end
1:
begin
if((v_counter>=301)&&(v_counter<=321)
&&(h_counter>=224) && (h_counter<=244))
begin
red[5:0]<=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h3f;
end
else
begin
red[5:0]<=6'b0;
green[5:0]<=6'b0;
blue[5:0]<=6'b0;
end
if(!penirq_out && !test) test<=1;
if (test==1)
begin
case( measure_time)
0:
begin
AddressByte<=8'h96;//----setup command
DataByte1<=8'hc0;
measure_time<=1;
end
1:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=2;
end
end
2:
begin
AddressByte<=8'h97;//----setup command
measure_time<=3;
end
3:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=4;
// test<=1;
tpx2={DataByte1_rd[7:0],DataByte2_rd[7:4]};
end
end
4:
begin
//touch_time<=0;
//test<=1;
AddressByte<=8'h96;//----setup command
DataByte1<=8'hd0;
measure_time<=5;
end
5:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=6;
end
end
6:
begin
AddressByte<=8'h97;//----setup command
measure_time<=7;
end
7:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=0;
test<=2;
end
end
endcase
end
else if(test==2 && penirq_out )
begin
touch_time<=2;
test<=0;
tpy2={DataByte1_rd[7:0],DataByte2_rd[7:4]};
end
end
2://
begin
if((v_counter>=155)&&(v_counter<=175)
&&(h_counter>=112) && (h_counter<=131))
begin
red[5:0]<=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h3f;
end
else
begin
red[5:0]<=6'b0;
green[5:0]<=6'b0;
blue[5:0]<=6'b0;
end
if(!penirq_out && !test) test<=1;
if(test==1)
begin
case( measure_time)
0:
begin
//touch_time<=0;
//test<=1;
AddressByte<=8'h96;//----setup command
DataByte1<=8'hc0;
measure_time<=1;
end
1:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=2;
end
end
2:
begin
AddressByte<=8'h97;//----setup command
measure_time<=3;
end
3:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=4;
// test<=1;
tpx3={DataByte1_rd[7:0],DataByte2_rd[7:4]};
end
end
4:
begin
//touch_time<=0;
//test<=1;
AddressByte<=8'h96;//----setup command
DataByte1<=8'hd0;
measure_time<=5;
end
5:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=6;
end
end
6:
begin
AddressByte<=8'h97;//----setup command
measure_time<=7;
end
7:
begin
if(delay_measure_count<=26666)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
measure_time<=0;
test<=2;
end
end
endcase
end
else if(test==2 && penirq_out )
begin
touch_time<=3;
test<=0;
tpy3={DataByte1_rd[7:0],DataByte2_rd[7:4]};
if (tpx3>tpx1) x3=220*(tpx3-tpx1)/(tpx2-tpx1)+10;
else x3=220*(tpx1-tpx3)/(tpx1-tpx2)+10;
y3=300*(tpy3-tpy1)/(tpy2-tpy1)+10;
end
end
3:
begin
if((v_counter>=135)&&(v_counter<=195)
&&(h_counter>=92) && (h_counter<=151))
begin
if(x3<130 && x3>110 && y3<170 && y3>150)
begin
red[5:0]<=6'h00;
green[5:0]<=6'h00;
blue[5:0]<=6'h3f;
if(!penirq_out && !test) test<=1;
if(test==1)
begin
if(delay_measure_count<=53333)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
test<=2;
end
end
else if(test==2 && penirq_out )
begin
test<=0;
touch_time<=4;
end
end
else
begin
red[5:0]<=6'h3f;
green[5:0]<=6'h00;
blue[5:0]<=6'h00;
if(!penirq && !test) test<=1;
if(test==1)
begin
if(delay_measure_count<=53333)
delay_measure_count<=delay_measure_count+1;
else
begin
delay_measure_count<=0;
test<=2;
end
end
else if(test==2 && penirq_out )
begin
test<=0;
touch_time<=0;
end
end
end
else
begin
red[5:0]<=6'b0;
green[5:0]<=6'b0;
blue[5:0]<=6'b0;
end
end
4:
begin
if((v_counter>=2)&&(v_counter<=321)
&&(h_counter>=5) && (h_counter<=244))
begin
red[5:0]<=6'b0;
green[5:0]<=6'b0;
blue[5:0]<=6'b0;
end
end
default:
begin
touch_time<=0;
measure_time<=0;
test<=0;
end
endcase
end
end
endcase
end
reg penirq_out;
reg [16:0] count0_p;
reg [16:0] count1_p;
always@(posedge clock or negedge reset)
begin
if(!reset) count0_p<=21'h000000;//对低电平计数
else
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -