問題描述:lcd屏幕上 x方向畫線正常,y方向畫線的話就會出現(xiàn)重復(fù)如圖本文引用地址:http://m.butianyuan.cn/article/201611/319264.htm
分析原因是:
時序不正確,也即lcddrv.h 和 lcddrv.c文件 不正確,需要修改。代碼如下:
lcddrv.h:
#ifndef __LCDDRV_H__
#define __LCDDRV_H__
#include
#define LOWER21BITS(n) ((n) & 0x1fffff)
#define BPPMODE_1BPP 0x8
#define BPPMODE_2BPP 0x9
#define BPPMODE_4BPP 0xA
#define BPPMODE_8BPP 0xB
#define BPPMODE_16BPP 0xC
#define BPPMODE_24BPP 0xD
#define LCDTYPE_TFT 0x3
#define ENVID_DISABLE 0
#define ENVID_ENABLE 1
#define FORMAT8BPP_5551 0
#define FORMAT8BPP_565 1
#define HSYNC_NORM 0
#define HSYNC_INV 1
#define VSYNC_NORM 0
#define VSYNC_INV 1
#define BSWP 1
#define HWSWP 1
//TFT LCD Panel(240*320)
#define MODE_TFT_1BIT_240320 (0x4101)
#define MODE_TFT_8BIT_240320 (0x4102)
#define MODE_TFT_16BIT_240320 (0x4104)
#define MODE_TFT_24BIT_240320 (0x4108)
//TFT 240320
#define LCD_XSIZE_TFT_240320 (240)
#define LCD_YSIZE_TFT_240320 (320)
//TFT 240320
#define HOZVAL_TFT_240320(LCD_XSIZE_TFT_240320-1)
#define LINEVAL_TFT_240320(LCD_YSIZE_TFT_240320-1)
#define CLKVAL_TFT_240320(4)
// 60hz @133Mhz
// (9) 60hz @100Mhz
//Timing parameter for LTS350Q1(SAMSUNG)
#define VBPD_240320((6-1)&0xff)
#define VFPD_240320((4-1)&0xff)
#define VSPW_240320((2-1) &0x3f)
#define HBPD_240320((11-1)&0x7f)
#define HFPD_240320((2-1)&0xff)
#define HSPW_240320((1-1)&0xff)
//TFT LCD Panel(640*480)
#define MODE_TFT_1BIT_640480 (0x4201)
#define MODE_TFT_8BIT_640480 (0x4202)
#define MODE_TFT_16BIT_640480 (0x4204)
#define MODE_TFT_24BIT_640480 (0x4208)
//TFT 640480
#define LCD_XSIZE_TFT_640480 (640)
#define LCD_YSIZE_TFT_640480 (480)
//TFT640480
#define HOZVAL_TFT_640480(LCD_XSIZE_TFT_640480-1)
#define LINEVAL_TFT_640480(LCD_YSIZE_TFT_640480-1)
//Timing parameter for V16C6448AB(PRIME VIEW)
#define VBPD_640480((33-1)&0xff)
#define VFPD_640480((10-1)&0xff)
#define VSPW_640480((2-1) &0x3f)
#define HBPD_640480((48-1)&0x7f)
#define HFPD_640480((16-1)&0xff)
#define HSPW_640480((96-1)&0xff)
#define CLKVAL_TFT_640480 (1)
//53.5hz @90Mhz
//VSYNC,HSYNC should be inverted
//HBPD=47VCLK,HFPD=15VCLK,HSPW=95VCLK
//VBPD=32HSYNC,VFPD=9HSYNC,VSPW=1HSYNC
#define LCDFRAMEBUFFER 0x30400000
void Lcd_Port_Init(void);
void Tft_Lcd_Init(int type);
void Lcd_Palette8Bit_Init(void);
void Lcd_EnvidOnOff(int onoff);
void Lcd_PowerEnable(int invpwren, int pwren);
void ClearScrWithTmpPlt(UINT32 color);
void DisableTmpPlt(void);
void ChangePalette(UINT32 color);
#endif
------------------------------------------------------------------
lcddrv.c文件:
#include
#include "s3c24xx.h"
#include "lcddrv.h"
unsigned int fb_base_addr;
unsigned int bpp;
unsigned int xsize;
unsigned int ysize;
static const unsigned short DEMO256pal[]={
0x0b5e,0xce9a,0xffd9,0x9d99,0xb63a,0xae7c,0xdd71,0x6c57,0xfd4d,0x00ae,0x9c4d,0xb5f8,0xad96,0x0131,0x0176,0xefff,0xcedd,0x9556,0xe4bf,0x00b6,0x22b7,0x002b,0x89de,0x002c,0x57df,0xab5f,0x3031,0x14bf,0x797e,0x5391,0x93ab,0x7239,0x7453,0xafdf,0x71b9,0x8c92,0x014d,0x302e,0x5175,0x0029,0x0969,0x004e,0x2a6d,0x0021,0x3155,0x4b6e,0xd677,0xf6b6,0x9b5f,0x4bb5,0xffd5,0x0027,0xdfdf,0x74d8,0x1256,0x6bcd,0x9b08,0x2ab2,0xbd72,0x84b5,0xfe52,0xd4ad,0x00ad,0xfffc,0x422b,0x73b0,0x0024,0x5246,0x8e5e,0x28b3,0x0050,0x3b52,0x2a4a,0x3a74,0x8559,0x3356,0x1251,0x9abf,0x4034,0x40b1,
0x8cb9,0x00b3,0x5c55,0xdf3d,0x61b7,0x1f5f,0x00d9,0x4c59,0x0926,0xac3f,0x925f,0x85bc,0x29d2,0xc73f,0xef5c,0xcb9f,0x827b,0x5279,0x4af5,0x01b9,0x4290,0xf718,0x126d,0x21a6,0x515e,0xefbd,0xd75e,0x42ab,0x00aa,0x10b3,0x7349,0x63b5,0x61a3,0xaadf,0xcb27,0x87df,0x6359,0xc7df,0x4876,0xb5bc,0x4114,0xfe2e,0xef5e,0x65be,0x43b9,0xe5df,0x21c9,0x7d16,0x6abb,0x5c11,0x49f7,0xbc0b,0x9e1a,0x3b0f,0x202b,0xff12,0x821b,0x842f,0xbccf,0xdefb,0x8a3e,0x68fa,0xa4f1,0x38ae,0x28b7,0x21ad,0x31d7,0x0073,0x182b,0x1831,0x3415,0xbdf6,0x2dbf,0x0a5d,0xc73d,0x182c,0x293e,0x7b3d,0x643d,0x3cbd,
0x92dd,0x09d4,0x1029,0x7cdd,0x6239,0x182e,0x5aea,0x11eb,0x8abc,0x7bfa,0x00a7,0x2153,0x1853,0x1318,0x0109,0x54fa,0x72a7,0x89e3,0x01cf,0x3a07,0x7b17,0x1a14,0x2150,0x23dc,0x4142,0x1b33,0x00a4,0xf6df,0x08fc,0x18ae,0x3a7e,0x18d1,0xa51c,0xff5a,0x1a0f,0x28fa,0xdfbe,0x82de,0x60d7,0x1027,0x48fa,0x5150,0x6213,0x89d6,0x110d,0x9bbb,0xbedd,0x28e1,0x1925,0xf449,0xaa79,0xd5f4,0x693c,0x110a,0x2889,0x08a2,0x923d,0x10a6,0xd9bc,0x5b2e,0x32ec,0xcf7f,0x1025,0x2148,0x74b4,0x6d59,0x9d14,0x0132,0x00f0,0x56bf,0x00f1,0xffff,0x0173,0x0133,0x00b0,0x00b1,0xf7ff,0x08b1,0xfffe,0x08b0,
0x0171,0xf7bf,0x10f3,0xf7fe,0x08ef,0x1192,0xefbe,0x1131,0x2177,0xff9f,0x1116,0xffbc,0x5914,0x22ef,0xb285,0xa6df,
};
void Lcd_Port_Init(void)
{
GPCUP = 0xffffffff; // 禁止內(nèi)部上拉
GPCCON = 0xaaaaaaaa; // GPIO管腳用于VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
GPDUP = 0xffffffff; // 禁止內(nèi)部上拉
GPDCON = 0xaaaaaaaa; // GPIO管腳用于VD[23:8]
}
void Tft_Lcd_Init(int type)
{
switch(type)
{
case MODE_TFT_8BIT_240320:
#if 0
LCDCON1 = (CLKVAL_TFT_240320<<8) | (LCDTYPE_TFT<<5) |
(BPPMODE_8BPP<<1) | (ENVID_DISABLE<<0);
LCDCON2 = (VBPD_240320<<24) | (LINEVAL_TFT_240320<<14) |
(VFPD_240320<<6) | (VSPW_240320);
LCDCON3 = (HBPD_240320<<19) | (HOZVAL_TFT_240320<<8) | (HFPD_240320);
LCDCON4 = HSPW_240320;
LCDCON5 = (FORMAT8BPP_565<<11) | (HSYNC_INV<<9) | (VSYNC_INV<<8) |
(BSWP<<1);
#endif
LCDCON1 = (8<<8) | (3<<5) | (0x0c<<1);
LCDCON2 = (14<<24) | (239<<14) | (11<<6) | (2<<0);
LCDCON3 = (37<<19) | (319<<8) | (19<<0);
LCDCON4 = 29;
LCDCON5 = (1<<11) | (1<<10) | (1<<9) | (0<<6) | (1<<8) | (1<<0);
LCDSADDR1 = ((LCDFRAMEBUFFER>>22)<<21) | LOWER21BITS(LCDFRAMEBUFFER>>1);
LCDSADDR2 = LOWER21BITS((LCDFRAMEBUFFER+
(LINEVAL_TFT_240320+1)*(HOZVAL_TFT_240320+1)*1)>>1);
LCDSADDR3 = (0<<11) | (LCD_XSIZE_TFT_240320/2);
TPAL = 0;
fb_base_addr = LCDFRAMEBUFFER;
bpp = 8;
// xsize = 240;
// ysize = 320;
xsize = 320;
ysize = 240;
break;
case MODE_TFT_16BIT_240320:
#if 0
LCDCON1 = (CLKVAL_TFT_240320<<8) | (LCDTYPE_TFT<<5) |
(BPPMODE_16BPP<<1) | (ENVID_DISABLE<<0);
LCDCON2 = (VBPD_240320<<24) | (LINEVAL_TFT_240320<<14) |
(VFPD_240320<<6) | (VSPW_240320);
LCDCON3 = (HBPD_240320<<19) | (HOZVAL_TFT_240320<<8) | (HFPD_240320);
LCDCON4 = HSPW_240320;
LCDCON5 = (FORMAT8BPP_565<<11) | (HSYNC_INV<<9) | (VSYNC_INV<<8) |
(HWSWP<<1);
#endif
LCDCON1 = (8<<8) | (3<<5) | (0x0c<<1);
LCDCON2 = (14<<24) | (239<<14) | (11<<6) | (2<<0);
LCDCON3 = (37<<19) | (319<<8) | (19<<0);
LCDCON4 = 29;
LCDCON5 = (1<<11) | (1<<10) | (1<<9) | (0<<6) | (1<<8) | (1<<0);
LCDSADDR1 = ((LCDFRAMEBUFFER>>22)<<21) | LOWER21BITS(LCDFRAMEBUFFER>>1);
LCDSADDR2 = LOWER21BITS((LCDFRAMEBUFFER+
(239+1)*(319+1)*2)>>1);
LCDSADDR3 = (0<<11) | (320*2/2);
TPAL = 0;
fb_base_addr = LCDFRAMEBUFFER;
bpp = 16;
// xsize = 240;
// ysize = 320;
xsize = 320;
ysize = 240;
break;
case MODE_TFT_8BIT_640480:
LCDCON1 = (CLKVAL_TFT_640480<<8) | (LCDTYPE_TFT<<5) |
(BPPMODE_8BPP<<1) | (ENVID_DISABLE<<0);
LCDCON2 = (VBPD_640480<<24) | (LINEVAL_TFT_640480<<14) |
(VFPD_640480<<6) | (VSPW_640480);
LCDCON3 = (HBPD_640480<<19) | (HOZVAL_TFT_640480<<8) | (HFPD_640480);
LCDCON4 = HSPW_640480;
LCDCON5 = (FORMAT8BPP_565<<11) | (HSYNC_INV<<9) | (VSYNC_INV<<8) |
(BSWP<<1);
LCDSADDR1 = ((LCDFRAMEBUFFER>>22)<<21) | LOWER21BITS(LCDFRAMEBUFFER>>1);
LCDSADDR2 = LOWER21BITS((LCDFRAMEBUFFER+
(LINEVAL_TFT_640480+1)*(HOZVAL_TFT_640480+1)*1)>>1);
LCDSADDR3 = (0<<11) | (LCD_XSIZE_TFT_640480/2);
TPAL = 0;
fb_base_addr = LCDFRAMEBUFFER;
bpp = 8;
xsize = 640;
ysize = 480;
break;
case MODE_TFT_16BIT_640480:
LCDCON1 = (CLKVAL_TFT_640480<<8) | (LCDTYPE_TFT<<5) |
(BPPMODE_16BPP<<1) | (ENVID_DISABLE<<0);
LCDCON2 = (VBPD_640480<<24) | (LINEVAL_TFT_640480<<14) |
(VFPD_640480<<6) | (VSPW_640480);
LCDCON3 = (HBPD_640480<<19) | (HOZVAL_TFT_640480<<8) | (HFPD_640480);
LCDCON4 = HSPW_640480;
LCDCON5 = (FORMAT8BPP_565<<11) | (HSYNC_INV<<9) | (VSYNC_INV<<8) |
(HWSWP<<1);
LCDSADDR1 = ((LCDFRAMEBUFFER>>22)<<21) | LOWER21BITS(LCDFRAMEBUFFER>>1);
LCDSADDR2 = LOWER21BITS((LCDFRAMEBUFFER+
(LINEVAL_TFT_640480+1)*(HOZVAL_TFT_640480+1)*2)>>1);
LCDSADDR3 = (0<<11) | (LCD_XSIZE_TFT_640480*2/2);
TPAL = 0;
fb_base_addr = LCDFRAMEBUFFER;
bpp = 16;
xsize = 640;
ysize = 480;
break;
default:
break;
}
}
void Lcd_Palette8Bit_Init(void)
{
int i;
volatile unsigned int *palette;
LCDCON1 &= ~0x01;// stop lcd controller
LCDCON5 |= (FORMAT8BPP_565<<11); // 設(shè)置調(diào)色板中數(shù)據(jù)格式為5:6:5
palette = (volatile unsigned int *)PALETTE;
for (i = 0; i < 256; i++)
*palette++ = DEMO256pal[i];
LCDCON1 |= 0x01;// re-enable lcd controller
}
void ChangePalette(UINT32 color)
{
int i;
unsigned char red, green, blue;
UINT32 *palette;
red = (color >> 19) & 0x1f;
green = (color >> 10) & 0x3f;
blue = (color >> 3) & 0x1f;
color = (red << 11) | (green << 5) | blue; // 格式5:6:5
palette=(UINT32 *)PALETTE;
LCDCON1 &= ~0x01;// stop lcd controller
for (i = 0; i < 256; i++)
{
// while (((LCDCON5>>15) & 0x3) == 2); // 等待直到VSTATUS不為”有效”
*palette++ = color;
}
LCDCON1 |= 0x01;// re-enable lcd controller
}
void Lcd_PowerEnable(int invpwren, int pwren)
{
GPGCON = (GPGCON & (~(3<<8))) | (3<<8); // GPG4用作LCD_PWREN
GPGUP = (GPGUP & (~(1<<4))) | (1<<4); // 禁止內(nèi)部上拉
LCDCON5 = (LCDCON5 & (~(1<<5))) | (invpwren<<5); // 設(shè)置LCD_PWREN的極性: 正常/反轉(zhuǎn)
LCDCON5 = (LCDCON5 & (~(1<<3))) | (pwren<<3); // 設(shè)置是否輸出LCD_PWREN
}
void Lcd_EnvidOnOff(int onoff)
{
if (onoff == 1)
{
LCDCON1 |= 1; // ENVID ON
GPBDAT |= (1<<0);// Power on
}
else
{
LCDCON1 &= 0x3fffe; // ENVID Off
GPBDAT &= ~(1<<0); // Power off
}
}
void ClearScrWithTmpPlt(UINT32 color)
{
TPAL = (1<<24)|((color & 0xffffff)<<0);
}
void DisableTmpPlt(void)
{
TPAL = 0;
}
評論