⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 复件 lcd_init(带TPrd05).v

📁 液晶显示驱动源程序代码
💻 V
📖 第 1 页 / 共 3 页
字号:
		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'd46;
				green[5:0]<=6'd46;
				blue[5:0]<=6'd46;
				end
			end	
			
		8://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	
		
		9://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
		10://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
		11://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
												oe=1;
												ce=1;
												
												
							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
												    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]};
													
													red=r_temp;
													green=g_temp;
													blue=b_temp;
											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<=20000)//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<=20000)
															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<=20000)
															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<=20000)
															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
															oe=1;
															ce=1;
															red[5:0]<=6'h00;
															green[5:0]<=6'h00;
															blue[5:0]<=6'h3f;
															
											end
										else
											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;
												
											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<=20000)
															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<=20000)
															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<=20000)
															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<=20000)
															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
															oe=1;
															ce=1;
															red[5:0]<=6'h00;
															green[5:0]<=6'h00;
															blue[5:0]<=6'h3f;
											end
										else
											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;
												
											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<=20000)
															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<=20000)
															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<=20000)
															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<=20000)
															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<135  && x3>105 && y3<175 && y3>145)
													begin 
															oe=1;
															ce=1;
															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<=60000)
																			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
															oe=1;
															ce=1;
															red[5:0]<=6'h3f;
															green[5:0]<=6'h00;
															blue[5:0]<=6'h00;
															
																if(!penirq_out && !test) test<=1;
																if(test==1)
																begin
																		if(delay_measure_count<=60000)
																			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
													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;
									
								end		
								end
								4:
								begin
										if((v_counter>=2)&&(v_counter<=321) 
											&&(h_counter>=5) && (h_counter<=244))
											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;
						
											end
									end
							default: 
							begin
							touch_time<=0;
							measure_time<=0;
							test<=0;
							end
							endcase
					
				end
					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
	if(penirq==1'b0) 
		count0_p<=count0_p+1;
		else
		count0_p<=17'h00000;
end
end

always@(posedge clock or negedge reset)
begin
if(!reset) count1_p<=17'h000000;//对低电平计数
else 
begin
	if(penirq==1'b1) 
		count1_p<=count1_p+1;
		else
		count1_p<=21'h00000;
end
end

//输出
always@(posedge clock or negedge reset)
begin
if(!reset) penirq_out<=1'b1;
else if(count0_p==17'h1e848) //判断低电平信号是否符合输出条件
penirq_out<=1'b0; //如果符合条件,则输出低电平

else if(count1_p==17'h1e848) //判断低电平信号是否符合输出条件

penirq_out<=1'b1; //如果符合条件,则输出高电平
else penirq_out<=penirq_out;
end


reg [5:0]pic_num;	
wire sw1_out;
reg [20:0] count0;
reg [20:0] count1;
reg sw1_out1_reg;


assign sw1_out=sw1_out1_reg;
//对输入进行采样,计数

always@(posedge clock or negedge reset)
begin
if(!reset) count1<=21'h000000;
else if(sw1==1'b1) count1<=count1+1;//对高电平计数
else count1<=21'h000000;
end 


always@(posedge clock or negedge reset)
begin
if(!reset) count0<=21'h000000;
else if(sw1==1'b0) count0<=count0+1;//对低电平计数
else count0<=21'h000000;
end
//输出
always@(posedge clock or negedge reset)
begin
if(!reset) sw1_out1_reg<=1'b1;
else if(count0==21'h1312D0) //判断低电平信号是否符合输出条件//1250000 50ms
sw1_out1_reg<=1'b0; //如果符合条件,则输出低电平
else if(count1==21'h1312D0) //判断低电平信号是否符合输出条件
sw1_out1_reg<=1'b1; //如果符合条件,则输出高电平h1312D0
else sw1_out1_reg<=sw1_out1_reg;
end


wire sw4_out;
reg [3:0] pic_num2;
reg [3:0] pic_num3;
reg [20:0] count0_4;
reg [20:0] count1_4;
reg sw4_out1_reg;

assign sw4_out=sw4_out1_reg;
//对输入进行采样,计数


always@(posedge clock or negedge reset)
begin
if(!reset) count1_4<=21'h000000;
else if(sw2==1'b1) count1_4<=count1_4+1;//对高电平计数
else count1_4<=21'h000000;
end 


always@(posedge clock or negedge reset)
begin
if(!reset) count0_4<=21'h000000;//对低电平计数
else 
begin
	if(sw2==1'b0) 
		count0_4<=count0_4+1;
		else
		count0_4<=21'h00000;
end
end

//输出
always@(posedge clock or negedge reset)
begin
if(!reset) sw4_out1_reg<=1'b1;
else if(count0_4==21'h1312D0) //判断低电平信号是否符合输出条件

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -