好记心不如烂笔头,为方便以后查看代码及代码重复利用,这里贴出S3C2440 LCD控制初始化代码。使用友善MINI2440开发板,LCD为320*240,开发环境为RealView MDK 4.22。
该源码结构简单明了,原始工程下载地址:点击打开链接
寄存器宏定义:
#define rGPCCON (*(volatile unsigned long *)0x56000020) #define rGPCUP (*(volatile unsigned long *)0x56000028) #define rGPDCON (*(volatile unsigned long *)0x56000030) #define rGPDUP (*(volatile unsigned long *)0x56000038) #define rLCDCON1 (*(volatile unsigned long *)0x4D000000) #define rLCDCON2 (*(volatile unsigned long *)0x4D000004) #define rLCDCON3 (*(volatile unsigned long *)0x4D000008) #define rLCDCON4 (*(volatile unsigned long *)0x4D00000C) #define rLCDCON5 (*(volatile unsigned long *)0x4D000010) #define rLCDSADDR1 (*(volatile unsigned long *)0x4D000014) #define rLCDSADDR2 (*(volatile unsigned long *)0x4D000018) #define rLCDSADDR3 (*(volatile unsigned long *)0x4D00001C) #define rTPAL (*(volatile unsigned long *)0x4D000050)
#define LCD_XSIZE 320 #define LCD_YSIZE 240 unsigned int LCD_BUFFER[LCD_YSIZE][LCD_XSIZE];
void LCD_GPIO_Init(void) { rGPCUP = 0xffffffff; rGPCCON = 0xaaaa02a8; rGPDUP = 0xffffffff; rGPDCON = 0xaaaaaaaa; }
#define CLKVAL 6 #define TFT_MODE 3 #define BPP_MODE_16BIT 0x0c #define BPP_MODE_24BIT 0x0D #define VBPD 9 #define LINEVAL (LCD_YSIZE - 1) #define VFPD 1 #define VSPW 2 #define HBPD 6//0x0C #define HOZVAL (LCD_XSIZE - 1) #define HFPD 5 #define HSPW 0//1 #define BPP24BL 0 #define FRM565 1 #define INVVCLK 1 #define INVHSYNC 1 #define INVVSYNC 1 #define BSWP 0 #define HWSWP 0 void LCD_Init(void) { LCD_GPIO_Init(); rLCDCON1 = (CLKVAL << 8) | (TFT_MODE << 5) | (BPP_MODE_24BIT << 1); rLCDCON2 = (VBPD << 24) | (LINEVAL << 14) | (VFPD << 6) | (VSPW << 0); rLCDCON3 = (HBPD << 19) | (HOZVAL << 8) | (HFPD << 0); rLCDCON4 = HSPW; rLCDCON5 = (BPP24BL << 12) | (INVVCLK << 10) | (INVHSYNC << 9) | (INVVSYNC << 8) | (BSWP << 1) | (HWSWP << 0); rLCDSADDR1 = ((unsigned int)LCD_BUFFER) >> 1; rLCDSADDR2 = ((unsigned int)LCD_BUFFER + LCD_YSIZE * LCD_XSIZE * sizeof(LCD_BUFFER[0][0])) >> 1; rLCDSADDR3 = LCD_XSIZE*2; }
void LCD_ON(void) { rLCDCON1 |= 1; } void LCD_OFF(void) { rLCDCON1 &= ~1; }
void LCD_ClrScr(unsigned int color) { int i, j; for(j = 0; j < LCD_YSIZE; j++) for(i = 0; i < LCD_XSIZE; i++) LCD_BUFFER[j][i] = color; }
void LCD_ClrScrUseTPAL(unsigned int color24) { rTPAL = (1 << 24) | color24; }
禁止TPAL:
void LCD_DisableTPAL(void) { rTPAL &= ~(1 << 24); }
void LCD_FillRect(int x0, int y0, int x1, int y1, unsigned int color) { int i, j; if((x0 > x1) || (y0 > y1)) return; for(j = y0; j <= y1; j++) for(i = x0; i <= x1; i++) LCD_BUFFER[j][i] = color; }
S3C2440之LCD驱动代码模板(RealView MDK)
原文地址:http://blog.csdn.net/hexiaolong2009/article/details/44038645