TFT LCD控制顯示總結(硬體概念、初始化相關配置)
阿新 • • 發佈:2019-02-18
01 void lcd_init(unsigned char pic_mode)
02 {
03 //配置LCD相關引腳
04 GPCUP = 0x00000000;
05 GPCCON = 0xaaaa02a9;
06 GPDUP = 0x00000000;
07 GPDCON = 0xaaaaaaaa;
08 //配置暫存器確定相關時序
09 LCDCON1 = (CLKVAL << 8) | (MVAL_USED << 7) | (PNRMODE_TFT << 5) \
10 | (BPPMODE_TFT(pic_mode) << 1 ) | 0;
11 LCDCON2 = (VBPD << 24) | (LINEVAL << 14) | (VFPD << 6) | VSPW;
12 LCDCON3 = (HBPD << 19) | (HOZVAL << 8) | HFPD;
13 LCDCON4 = HSPW;
14 LCDCON5 = (BPP24BL << 12) | (FRM565 << 11) | \
15 (INVVCLK << 10) | (INVVLINE << 9 ) | \
16 (INVVFRAME << 8) | (0 << 7) | (INVVDEN << 6) | \
17 (PWREN << 3) | (BSWP << 1) | HWSWP;
18 //配置暫存器指明影象資料的記憶體地址
19 LCDSADDR1 = ((LCD_BUFFER >> 22) << 21) | \
20 M5D(LCD_BUFFER >> 1);
21 switch (pic_mode)
22 {
23 case BPP24:
24 LCDSADDR2 = M5D((LCD_BUFFER + \
25 (LCD_WIDTH * LCD_HEIGHT * 4)) >> 1);
26 LCDSADDR3 = LCD_WIDTH * 32 / 16;//two half words
27 break;
28 case BPP16:
29 LCDSADDR2 = M5D((LCD_BUFFER + (LCD_WIDTH * \
30 LCD_HEIGHT * 2)) >> 1);
31 LCDSADDR3 = LCD_WIDTH * 32 / 32;//one half words
32 break;
33 default:
34 break;
35 }
36 LCDINTMSK |= 3;//遮蔽LCD中斷
37 TCONSEL = 0;//無效LPC3480
38
39 GPGUP = (GPGUP & (~(1 << 4))) | (1 << 4);//GPG4上拉電阻無效
40 GPGCON = (GPGCON & (~(3 << 8))) | (3 << 8);//設定GPG4LCD_PWREN
41 GPGDAT = GPGDAT | (1 << 4);//GPG4置1開啟電源訊號
42
43 LCDCON5 = (LCDCON5 & (~(1 << 3))) | (1 << 3);//有效PWREN訊號
44 LCDCON5 = (LCDCON5 & (~(1 << 5))) | (0 << 5);//PWREN訊號極性不翻轉
45
46 LCDCON1 |= 1;//LCD開啟(LCD訊號輸出使能位)
47 }
02 {
03 //配置LCD相關引腳
04 GPCUP = 0x00000000;
05 GPCCON = 0xaaaa02a9;
06 GPDUP = 0x00000000;
07 GPDCON = 0xaaaaaaaa;
08 //配置暫存器確定相關時序
09 LCDCON1 = (CLKVAL << 8) | (MVAL_USED << 7) | (PNRMODE_TFT << 5) \
10 | (BPPMODE_TFT(pic_mode) << 1
11 LCDCON2 = (VBPD << 24) | (LINEVAL << 14) | (VFPD << 6) | VSPW;
12 LCDCON3 = (HBPD << 19) | (HOZVAL << 8) | HFPD;
13 LCDCON4 = HSPW;
14 LCDCON5 = (BPP24BL << 12) | (FRM565 << 11) | \
15 (INVVCLK << 10) | (INVVLINE << 9
16 (INVVFRAME << 8) | (0 << 7) | (INVVDEN << 6) | \
17 (PWREN << 3) | (BSWP << 1) | HWSWP;
18 //配置暫存器指明影象資料的記憶體地址
19 LCDSADDR1 = ((LCD_BUFFER >> 22) << 21) | \
20 M5D(LCD_BUFFER >> 1);
21 switch
22 {
23 case BPP24:
24 LCDSADDR2 = M5D((LCD_BUFFER + \
25 (LCD_WIDTH * LCD_HEIGHT * 4)) >> 1);
26 LCDSADDR3 = LCD_WIDTH * 32 / 16;//two half words
27 break;
28 case BPP16:
29 LCDSADDR2 = M5D((LCD_BUFFER + (LCD_WIDTH * \
30 LCD_HEIGHT * 2)) >> 1);
31 LCDSADDR3 = LCD_WIDTH * 32 / 32;//one half words
32 break;
33 default:
34 break;
35 }
36 LCDINTMSK |= 3;//遮蔽LCD中斷
37 TCONSEL = 0;//無效LPC3480
38
39 GPGUP = (GPGUP & (~(1 << 4))) | (1 << 4);//GPG4上拉電阻無效
40 GPGCON = (GPGCON & (~(3 << 8))) | (3 << 8);//設定GPG4LCD_PWREN
41 GPGDAT = GPGDAT | (1 << 4);//GPG4置1開啟電源訊號
42
43 LCDCON5 = (LCDCON5 & (~(1 << 3))) | (1 << 3);//有效PWREN訊號
44 LCDCON5 = (LCDCON5 & (~(1 << 5))) | (0 << 5);//PWREN訊號極性不翻轉
45
46 LCDCON1 |= 1;//LCD開啟(LCD訊號輸出使能位)
47 }