好记心不如烂笔头,为方便以后查看代码及代码重复利用,这里贴出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];
GPIO初始化:
void LCD_GPIO_Init(void)
{
rGPCUP = 0xffffffff;
rGPCCON = 0xaaaa02a8;
rGPDUP = 0xffffffff;
rGPDCON = 0xaaaaaaaa;
}
LCD初始化:
#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;
}
开启/关闭LCD:
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);
}
FillRect函数:
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之MMU驱动代码模板(RealView MDK)
下一篇:keil5(MDK5)配置S3C2440裸机开发调试环境
推荐阅读最新更新时间:2024-03-16 16:04