TFT LCD 7寸1024*600 FPGA点亮

http://www.52rd.com/Blog/Detail_RD.Blog_whq0217_66110.html


花了一些时间去点亮7寸TFT,现在只能做自动切换画面的部分,按键切换还正在调试中。如下:

 

`timescale 1ns / 1ps

module CMO_5WVGA(CLK,DCLK,HS,UD,LR,VS,DE,LCDR,LCDG,LCDB);
input  CLK;
output DCLK;
output HS;
output VS;
output DE;
output UD;
output LR;
output [7:0] LCDR;
output [7:0] LCDG;
output [7:0] LCDB;
/*************BOE 7DD HS/VS parameter*********************
// Horizontal Signals:
parameter
thpw = 11'd20,     //HS Pulse Width,1-40 DCLK
thb  = 11'd46,    //HS Blanking 46 DCLK = HS Pulse Width + HS Back Porch
thd  = 11'd800,    //Horizontal Display Area,800 DCLK
thfp = 11'd210,    //HS Front Porch,16-210-354 DCLK
th   = (thb+thd+thfp),  //One Horizontal Line = HS Blanking (thb) + Horizontal Display Area (thd) + HS Front Porch (thfp)

// Vertical Signals:
tvpw = 11'd10,     //Vs Pulse Width 1-20 TH
tvb  = 11'd23,    //Vs Blanking 23 TH = Vs Pulse Width + VS Back Porch
tvd  = 11'd480,    //Vertical Dsiplay Area 480 TH
tvfp = 11'd22,    //Vs Front Porch 7-22-147 TH
tv   = (tvb+tvd+tvfp);  //Vs Blanking (tvb) + Vertical Dsiplay Area (tvd) + Vs Front Porch (tvfp)
*/
/******************CMO 5D WVGA parameter*******************
// Horizontal Signals:
parameter
thpw = 11'd128,     //HS Pulse Width,1-40 DCLK
thb  = 11'd216,    //HS Blanking 46 DCLK = HS Pulse Width + HS Back Porch
thd  = 11'd800,    //Horizontal Display Area,800 DCLK
thfp = 11'd88,    //HS Front Porch,16-210-354 DCLK
th   = (thb+thd+thfp),  //One Horizontal Line = HS Blanking (thb) + Horizontal Display Area (thd) + HS Front Porch (thfp)

// Vertical Signals:
tvpw = 11'd2,     //Vs Pulse Width 1-20 TH
tvb  = 11'd35,    //Vs Blanking 23 TH = Vs Pulse Width + VS Back Porch
tvd  = 11'd480,    //Vertical Dsiplay Area 480 TH
tvfp = 11'd8,    //Vs Front Porch 7-22-147 TH
tv   = (tvb+tvd+tvfp);  //Vs Blanking (tvb) + Vertical Dsiplay Area (tvd) + Vs Front Porch (tvfp)
*/
/******************CPT 7DH WSVGA parameter******************/
// Horizontal Signals:
parameter
thpw = 12'd70,     //HS Pulse Width,1-40 DCLK
thb  = 12'd160,    //HS Blanking 46 DCLK = HS Pulse Width + HS Back Porch
thd  = 12'd1024,    //Horizontal Display Area,800 DCLK
thfp = 12'd160,    //HS Front Porch,16-210-354 DCLK
th   = (thb+thd+thfp),  //One Horizontal Line = HS Blanking (thb) + Horizontal Display Area (thd) + HS Front Porch (thfp)

// Vertical Signals:
tvpw = 12'd10,     //Vs Pulse Width 1-20 TH
tvb  = 12'd23,    //Vs Blanking 23 TH = Vs Pulse Width + VS Back Porch
tvd  = 12'd600,    //Vertical Dsiplay Area 480 TH
tvfp = 12'd12,    //Vs Front Porch 7-22-147 TH
tv   = (tvb+tvd+tvfp);  //Vs Blanking (tvb) + Vertical Dsiplay Area (tvd) + Vs Front Porch (tvfp)

wire HS;
wire VS;
wire DE;
wire UD;
wire LR;
wire [7:0] LCDR;
wire [7:0] LCDG;
wire [7:0] LCDB;

reg HS_R = 1'b1;
reg VS_R = 1'b1;
reg DE_R = 1'b0;
reg UD_R = 1'b0;
reg LR_R = 1'b1;
reg [12:0] hcount = th-1'b1;
reg [12:0] vcount = tv-1'b1;
reg videoh = 1'b0;
reg videov = 1'b0;
wire videon = 1'b0;
reg [12:0] source = 12'b0;
reg [12:0] gate = 12'b0;
reg [23:0] v_data;
reg [23:0] h_data;
reg [23:0] gv_data;
reg [23:0] gh_data;
reg [23:0] red_test_data;
reg [3:0] dismode =4'b0;
reg [23:0] data;
reg [26:0] switchsync;

assign DCLK = CLK;
assign HS = HS_R;
assign VS = VS_R;
assign DE = DE_R;
assign UD = UD_R;
assign LR = LR_R;
assign videon = videoh && videov ;     //videoh逻辑与videov=videon
assign LCDR = data[23:16] ;
assign LCDG = data[15:8] ;
assign LCDB = data[7:0] ;

//TFT hcount, vcount siganl
always @(posedge CLK)         //一直执行横向纵向数据的自加功能
begin
 if(hcount==(th-1'b1))        //当hcount等于Total横向数据时执行下面操作
 begin
  hcount <= 1'b0;         //赋值给hcount为0
  if(vcount==(tv-1'b1))       //如果vcount的值等于纵向Total数据时执行下面操作
   vcount <= 1'b0;        //赋值给vcount为0
  else
   vcount <= vcount+ 1'b1;      //如果vcount的值未到Total数值时,执行vcount自动加1赋值
 end
 else
 hcount <= hcount+1'b1;        //如果hcount的值未到Total横向数据时,执行hcount自动加1赋值
end
//videoh signal
always @(hcount)           //横向数据函数
begin
 if( (hcount>=thb) && (hcount<=(thb+thd) ))   //如果hcount大于等于HBP+HPW同时满足hcount小于等于HBP+HPW+HPD执行下面的操作
 videoh <= 1'b1;          //videoh赋值为1
 else
 videoh <= 1'b0;          //超过这个范围时videoh赋值为0
end
//videov signal
always @(vcount)           //纵向数据显示函数
begin
 if( (vcount>=tvb) && (vcount<=(tvb+tvd)) ) //如果vcount大于等于VBP+VPW同时满足vcount小于等于VBP+VPW+VPD执行下面操作
 videov <= 1'b1;          //videov赋值为1
 else
 videov <= 1'b0;          //videov赋值为0
end

always @(posedge CLK)
begin
 if(videon==1'b1)             //当videoh和videov同时满足为正的时候,也就是在正常显示的区域内执行下面操作。
 begin
  source <= source+12'b1;       //source自动加1
  gate <= gate+12'b1;        //gate自动加1
 end
 else
 begin
  source <= 12'b0;         //否则source=0;gate=0;
  gate <= 12'b0;
 end
end


// hsync , vsync
/*
always @(posedge CLK)
begin          //在开始阶段HS_R=1,VS_R=1
 HS_R <= ( hcount >= thpw);  //将hcount在大于等于thpw的值赋予HS_R
 VS_R <= ( vcount >= tvpw);  //将vconnt在大于等于tvpw的值赋予VS_R
end*/

always @(posedge CLK)
begin
 if((vcount>=tvpw)&&(vcount<=tv))
  VS_R<=1'b1; 
 else
  VS_R<=1'b0;
 if((hcount>=thpw)&&(hcount<=th))
  HS_R<=1'b1;      
 else
  HS_R<=1'b0;
end

/*
always @(posedge CLK)
begin
 if((hcount>=thb)&&(hcount<=thb+thd))
 DE_R<=1'b1;  
 else
 DE_R<=1'b0;
end*/
//**************竖条8色Color Bar******************************
always @(posedge CLK)
begin
 if((hcount>=thb)&&(hcount <=thb+thd/8))     //在hcount<=
 begin
  h_data <={8'd255,8'd0,8'd0} ;
 end
 else if ((hcount >=thb+thd/8)&&(hcount <=thb+2*thd/8))
 begin
  h_data <={8'd0,8'd255,8'd0} ;
 end
 else if ((hcount >=thb+2*thd/8)&&(hcount <=thb+3*thd/8))
 begin
  h_data <={8'd0,8'd0,8'd255} ;
 end
 else if ((hcount >=thb+3*thd/8)&&(hcount <=thb+4*thd/8)) 
 begin
  h_data <={8'd255,8'd255,8'd0} ;
 end
 else if ((hcount >=thb+4*thd/8)&&(hcount <=thb+5*thd/8)) 
 begin
  h_data <={8'd0,8'd255,8'd255} ;
 end
 else if ((hcount >=thb+5*thd/8)&&(hcount <=thb+6*thd/8))
 begin
  h_data <={8'd255,8'd0,8'd255} ;
 end
 else if ((hcount >=thb+6*thd/8)&&(hcount <=thb+7*thd/8))
 begin
  h_data <={8'd255,8'd255,8'd255} ;
 end
 else
 begin
  h_data <={8'd0,8'd0,8'd0} ;
 end  
end
//********************横条8色Color Bar***********************
always @(posedge CLK)
begin
 if((vcount>=tvb)&&(vcount<=tvb+tvd/8))
 begin
  v_data <={8'd0,8'd0,8'd0} ;
 end
 else if((vcount>=tvb+tvd/8)&&(vcount<=tvb+2*tvd/8))
 begin
  v_data <={8'd255,8'd255,8'd255} ;
 end
 else if((vcount>=tvb+2*tvd/8)&&(vcount<=tvb+3*tvd/8))
 begin
  v_data <={8'd255,8'd0,8'd0} ;
 end
 else if((vcount>=tvb+3*tvd/8)&&(vcount<=tvb+4*tvd/8))
 begin
  v_data <={8'd0,8'd255,8'd0} ;
 end
 else if((vcount>=tvb+4*tvd/8)&&(vcount<=tvb+5*tvd/8))
 begin
  v_data <={8'd0,8'd0,8'd255} ;
 end
 else if((vcount>=tvb+5*tvd/8)&&(vcount<=tvb+6*tvd/8))
 begin
  v_data <={8'd255,8'd255,8'd0} ;
 end
 else if((vcount>=tvb+6*tvd/8)&&(vcount<=tvb+7*tvd/8))
 begin
  v_data <={8'd255,8'd0,8'd255} ;
 end
 else
 begin
  v_data <={8'd0,8'd255,8'd255} ;
 end
 end
//*****************横条32灰阶*****************************
always @(posedge CLK)
begin
 if( hcount <=thb+thd/32)     //1
 begin
  gh_data <={8'd0,8'd0,8'd0} ;
 end
 else if ( hcount <=thb+2*thd/32 )   //2
 begin
  gh_data <={8'd7,8'd7,8'd7} ;
 end
 else if (hcount <=thb+3*thd/32)    //3
 begin
  gh_data <={8'd15,8'd15,8'd15} ;
 end
 else if ( hcount <=thb+4*thd/32 )   //4
 begin
  gh_data <={8'd23,8'd23,8'd23} ;
 end
 else if ( hcount <=thb+5*thd/32)  //5
 begin
  gh_data <={8'd31,8'd31,8'd31} ;
 end
 else if (hcount <=thb+6*thd/32 )   //6
 begin
  gh_data <={8'd39,8'd39,8'd39} ;
 end
 else if (hcount <=thb+7*thd/32)   //7
 begin
  gh_data <={8'd47,8'd47,8'd47} ;
 end
 else if (hcount <=thb+8*thd/32)   //8
 begin
  gh_data <={8'd55,8'd55,8'd55} ;
 end
 else if (hcount <=thb+9*thd/32)   //9
 begin
  gh_data <={8'd63,8'd63,8'd63} ;
 end
 else if (hcount <=thb+10*thd/32)   //10
 begin
  gh_data <={8'd71,8'd71,8'd71} ;
 end
 else if (hcount <=thb+11*thd/32)   //11
 begin
  gh_data <={8'd79,8'd79,8'd79} ;
 end
 else if (hcount <=thb+12*thd/32)   //12
 begin
  gh_data <={8'd87,8'd87,8'd87} ;
 end
 else if (hcount <=thb+13*thd/32)   //13
 begin
  gh_data <={8'd95,8'd95,8'd95} ;
 end
 else if (hcount <=thb+14*thd/32)   //14
 begin
  gh_data <={8'd103,8'd103,8'd103} ;
 end
 else if (hcount <=thb+15*thd/32)   //15
 begin
  gh_data <={8'd111,8'd111,8'd111} ;
 end
 else if (hcount <=thb+16*thd/32)   //16
 begin
  gh_data <={8'd119,8'd119,8'd119} ;
 end
 else if (hcount <=thb+17*thd/32)   //17
 begin
  gh_data <={8'd127,8'd127,8'd127} ;
 end
 else if (hcount <=thb+18*thd/32)   //18
 begin
  gh_data <={8'd135,8'd135,8'd135} ;
 end
 else if (hcount <=thb+19*thd/32)   //19
 begin
  gh_data <={8'd143,8'd143,8'd143} ;
 end
 else if (hcount <=thb+20*thd/32)   //20
 begin
  gh_data <={8'd151,8'd151,8'd151} ;
 end
 else if (hcount <=thb+21*thd/32)   //21
 begin
  gh_data <={8'd159,8'd159,8'd159} ;
 end
 else if (hcount <=thb+22*thd/32)   //22
 begin
  gh_data <={8'd167,8'd167,8'd167} ;
 end
 else if (hcount <=thb+23*thd/32)   //23
 begin
  gh_data <={8'd175,8'd175,8'd175} ;
 end
 else if (hcount <=thb+24*thd/32)   //24
 begin
  gh_data <={8'd183,8'd183,8'd183} ;
 end
 else if (hcount <=thb+25*thd/32)   //25
 begin
  gh_data <={8'd191,8'd191,8'd191} ;
 end
 else if (hcount <=thb+26*thd/32)   //26
 begin
  gh_data <={8'd199,8'd199,8'd199} ;
 end
 else if (hcount <=thb+27*thd/32)   //27
 begin
  gh_data <={8'd207,8'd207,8'd207} ;
 end
 else if (hcount <=thb+28*thd/32)   //28
 begin
  gh_data <={8'd215,8'd215,8'd215} ;
 end
 else if (hcount <=thb+29*thd/32)   //29
 begin
  gh_data <={8'd223,8'd223,8'd223} ;
 end
 else if (hcount <=thb+30*thd/32)   //30
 begin
  gh_data <={8'd231,8'd231,8'd231} ;
 end
 else if (hcount <=thb+31*thd/32)   //31
 begin
  gh_data <={8'd239,8'd239,8'd239} ;
 end
 else if (hcount <=thb+32*thd/32)   //32
 begin
  gh_data <={8'd247,8'd247,8'd247} ;
 end  
 else
 begin
  gh_data <={8'd255,8'd255,8'd255} ;
 end  
end
//*****************横条8灰阶********************
always @(posedge CLK)
begin
 if(vcount<=tvb+tvd/8)
 begin
  gv_data <={8'd0,8'd0,8'd0} ;
 end
 else if(vcount<=tvb+2*tvd/8)
 begin
  gv_data <={8'd48,8'd48,8'd48} ;
 end
 else if(vcount<=tvb+3*tvd/8)
 begin
  gv_data <={8'd64,8'd64,8'd64} ;
 end
 else if(vcount<=tvb+4*tvd/8)
 begin
  gv_data <={8'd96,8'd96,8'd96} ;
 end
 else if(vcount<=tvb+5*tvd/8)
 begin
  gv_data <={8'd128,8'd128,8'd128} ;
 end
 else if(vcount<=tvb+6*tvd/8)
 begin
  gv_data <={8'd176,8'd176,8'd176} ;
 end
 else if(vcount<=tvb+7*tvd/8)
 begin
  gv_data <={8'd192,8'd192,8'd192} ;
 end
 else
 begin
  gv_data <={8'd255,8'd255,8'd255} ;
 end
end
//*****************Test UD/LR Programm*************************8
always @(posedge CLK)
begin
 if(((hcount>=thb+10)&&(hcount<=thb+110))&&((vcount>=tvb+10)&&(vcount<=tvb+110)))
  red_test_data<={8'd255,8'd0,8'd0} ;
 else
  red_test_data<={8'd255,8'd255,8'd255};
end
//******************************************************
always @(posedge CLK)
begin
 switchsync <= switchsync + 1'b1;  //按键自动加1
end

always @(posedge switchsync[25])
begin
  dismode <= dismode+4'b1;
end

always @(posedge CLK)
begin
 case(dismode)
 4'd0: data <= {8'd255,8'd0,8'd0};  //红色
 4'd1: data <= {8'd0,8'd255,8'd0};  //蓝色
 4'd2: data <= {8'd0,8'd0,8'd255};  //绿色
 4'd3: data <= {8'd0,8'd255,8'd255};  //G+B
 4'd4: data <= {8'd255,8'd225,8'd0};  //R+G
 4'd5: data <= {8'd255,8'd0,8'd255};  //R+B
 4'd6: data <= gh_data;      //横向Color Bar
 4'd7: data <= gv_data;      //竖向Color Bar
 4'd8: data <= h_data;      //竖向Color Bar 和横向Color Bar 按位与
 4'd9: data <= v_data;      // 
 4'd10: data <= red_test_data ;   //确定默认扫描线扫描正常,防止FPC短路,断路现象
 4'd11:            //测试左右、上下扫描线是否正常,防止FPC短路,断路现象
  begin
   UD_R<= 1'b1;
   LR_R<= 1'b0;
   data <= red_test_data ;
  end
 
 4'd12:
  begin
  UD_R<= 1'b0;
  LR_R<= 1'b1;
  data <= {8'd128,8'd128,8'd128};  //64灰阶
  end
 4'd13: data <= {8'd192,8'd192,8'd192}; //128灰阶
 4'd14: data <= {8'd0,8'd0,8'd0};   //黑色画面
 4'd15: data <= {8'd255,8'd255,8'd255}; //白色画面
 endcase
end
endmodule

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值