新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > S3C2440開(kāi)發(fā)板-LCD基礎(chǔ)(源代碼)

S3C2440開(kāi)發(fā)板-LCD基礎(chǔ)(源代碼)

作者: 時(shí)間:2011-05-09 來(lái)源:網(wǎng)絡(luò) 收藏

首先了解TFT LCD的時(shí)序,每個(gè)VSYNC信號(hào)表示一幀數(shù)據(jù)的開(kāi)始,每個(gè)HSYNC表示一行數(shù)據(jù)的開(kāi)始,無(wú)論這些數(shù)據(jù)是否有效,每個(gè)VCLK表示正在傳輸一個(gè)像素的數(shù)據(jù),無(wú)論它是否有效。VSPW稱(chēng)為垂直同步信號(hào)的脈寬,VBPD稱(chēng)為垂直同步信號(hào)的后肩,VFPD稱(chēng)為垂直同步信號(hào)的前肩。HSPW稱(chēng)為水平同步信號(hào)的脈寬,HBPD稱(chēng)為水平同步信號(hào)的后肩,HFPD稱(chēng)為水平同步信號(hào)的前肩。查看時(shí)序圖,VSYNC信號(hào)有效時(shí),表示一幀數(shù)據(jù)的開(kāi)始,VSPW表示VSYNC信號(hào)的脈沖寬度為(VSPW+1)個(gè)HSYNC信號(hào)周期,即(VSYNC+1)行,這(VSPW+1)行的數(shù)據(jù)無(wú)效。VSYNC信號(hào)脈沖之后,還要經(jīng)過(guò)(VBPD+1)個(gè)HSYNC信號(hào)周期,有效的行數(shù)據(jù)才出現(xiàn)。所以,在VSYNC信號(hào)之后,總共還要經(jīng)過(guò)(VSPW+1+VBPD+1)個(gè)無(wú)效行,第一個(gè)有效的行才會(huì)出現(xiàn)。隨后即發(fā)出(LINEVAL+1)行的有效數(shù)據(jù),隨后是(VFPD+1)個(gè)無(wú)效行。HSYNC的類(lèi)似。不過(guò)是以VCLK信號(hào)周期為單位。然后主要就是配置5個(gè)LCD控制寄存器,3個(gè)幀緩沖區(qū)起始地址寄存器。注意HSYNC和VSYNC信號(hào),CPU發(fā)出的是正脈沖,LCD需要的是負(fù)的,所以極性取反,INVVLINE和INVVFRAME置1。M5D宏是用來(lái)取低21位。有一些右移一位的操作,主要是進(jìn)行字節(jié)和半字地址的轉(zhuǎn)換。LCD中需要的半字地址,幀緩沖區(qū)最低位是A[1]。BSWP和HWSWP是字節(jié)和半字交換,主要是處理大小端問(wèn)題,如果輸出的漢字反了,置這個(gè)位為1。volatile U32 LCD_BUFFER[240][320];這個(gè)是設(shè)的幀緩沖區(qū),即視口,是幀內(nèi)存的一部分,這個(gè)程序中,幀內(nèi)存和幀緩沖區(qū)一樣大。幀內(nèi)存在SDRAM中,相當(dāng)于顯存。只要向幀緩沖區(qū)中寫(xiě)入數(shù)據(jù),LCD的DMA控制器會(huì)自動(dòng)將數(shù)據(jù)從總線發(fā)到LCD驅(qū)動(dòng)器。在VCLK的上升沿發(fā)送數(shù)據(jù),在VCLK的下降沿,LCD驅(qū)動(dòng)器接受數(shù)據(jù)。BPP24BL是設(shè)置LCD的顯示模式為24BPP時(shí),一個(gè)4字節(jié)中哪3個(gè)字節(jié)有效。PAGESIZE是幀緩沖區(qū)的水平寬度,OFFSET是一行剩下的長(zhǎng)度。VD[23]VD[0],是24根數(shù)據(jù)線,即RGB信號(hào)線。

下面的程序?qū)CD涂成紅色,然后畫(huà)一個(gè)藍(lán)色的矩形。

#define rGPCCON (*(volatile unsigned *)0x56000020)
#define rGPCUP (*(volatile unsigned *)0x56000028)
#define rGPDCON (*(volatile unsigned *)0x56000030)
#define rGPDUP (*(volatile unsigned *)0x56000038)
#define rLCDCON1 (*(volatile unsigned *)0x4d000000)
#define rLCDCON2 (*(volatile unsigned *)0x4d000004)
#define rLCDCON3 (*(volatile unsigned *)0x4d000008)
#define rLCDCON4 (*(volatile unsigned *)0x4d00000c)
#define rLCDCON5 (*(volatile unsigned *)0x4d000010)
#define rLCDSADDR1(*(volatile unsigned *)0x4d000014)
#define rLCDSADDR2(*(volatile unsigned *)0x4d000018)
#define rLCDSADDR3(*(volatile unsigned *)0x4d00001c)
#define rLCDINTMSK(*(volatile unsigned *)0x4d00005c)
#define rTPAL (*(volatile unsigned *)0x4d000050)
#define rGPGCON (*(volatile unsigned *)0x56000060) //Port G control
#define rGPGDAT (*(volatile unsigned *)0x56000064) //Port G data
#define rGPGUP (*(volatile unsigned *)0x56000068) //Pull-up control G
#define rLCDINTMSK(*(volatile unsigned *)0x4d00005c)
#define rTPAL (*(volatile unsigned *)0x4d000050)
#define rTCONSEL (*(volatile unsigned *)0x4d000060) //LPC3600 Control --- edited by junon
//垂直同步信號(hào)的脈寬、后肩和前肩
#define VSPW 15
#define VBPD 3
#define VFPD 5
//水平同步信號(hào)的脈寬、后肩和前肩
#define HSPW 8
#define HBPD 58
#define HFPD 15
#define CLKVAL 10
#define HOZVAL 319
#define LINEVAL 239
#define PWREN 1
#define MMODE 0
#define PNRMODE 3
#define BPPMODE 13
#define INVVCLK 0
#define INVVD 0
#define INVVDEN 0
#define U32 unsigned int
#define M5D(n) ((n) 0x1fffff)
#define PAGEWIDTH 320
#define OFFSIZE 0
#define LCD_XSIZE 320
#define LCD_YSIZE 240
#define SCR_XSIZE 320
#define SCR_YSIZE 240
#define INVVLINE1
#define INVVFRAME 1
#define BPP24BL 0
#define BSWP 0
#define HWSWP 0
volatile U32 LCD_BUFFER[240][320];
void Init_LCD(){
rLCDCON1=(CLKVAL<<8)|(MMODE<<7)|(PNRMODE<<5)|(BPPMODE<<1)|0; //設(shè)置CLKVAL,VCLK=HCLK/[(CLKVAL+1)*2],決定VM的觸發(fā)方式,選擇顯示模式和BPP模式,暫時(shí)不要開(kāi)啟LCD,因?yàn)檫€沒(méi)有設(shè)置好
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW); //rLCDCON2,rLCDCON3和rLCDCON4主要設(shè)置時(shí)序
rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD);
rLCDCON4=(HSPW);
rLCDCON5 = (BPP24BL<<12) | (INVVCLK<<10) | (INVVLINE<<9) | (INVVFRAME<<8) | (0<<7) | (INVVDEN<<6) | (PWREN<<3)|(BSWP<<1) | (HWSWP);

本文引用地址:http://butianyuan.cn/article/150788.htm

//INVVLINE和INVVFRAME需要進(jìn)行翻轉(zhuǎn),因?yàn)镃PU發(fā)出的是正脈沖,LCD使用的是負(fù)脈沖,所以要改變極性,PWREN使能電源信號(hào)
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
rLCDSADDR2=M5D(((U32)LCD_BUFFER+(SCR_XSIZE*SCR_YSIZE*4))>>1 );
rLCDSADDR3=PAGEWIDTH*32/16;
rLCDINTMSK|=(3);
rTCONSEL = 0;
rGPCUP = 0x0;
rGPDCON = 0xaaaaaaaa;
rGPCCON = 0xaaaa02a9;
rGPDUP = 0x0;
rGPGUP=rGPGUP((1<<4))|(1<<4);
rGPGCON=rGPGCON((3<<8))|(3<<8);
rLCDCON1 |= 1; //使能數(shù)據(jù)輸出和LCD控制信號(hào)
}
void Paint_background(U32 c){
unsigned int i, j;
for(j = 0; j < LCD_YSIZE; j++)
for(i = 0; i < LCD_XSIZE; i++)
LCD_BUFFER[j][ i] = c;
}
void Paint_rectangle(U32 c){
int i, j;
for(i = 100; i < 200; i++)
for(j = 100; j < 200; j++)
LCD_BUFFER[ i][j] = c;
}
int LcdMain(){
Init_LCD();
Paint_background(0xCD5C5C);
Paint_rectangle(0x000080);
while(1);
}

t.gif



評(píng)論


相關(guān)推薦

技術(shù)專(zhuān)區(qū)

關(guān)閉