S3C2440 LCD液晶模块驱动设计

最后更新于:2022-04-01 16:11:46

参数配置: 开发板型号TX2440;  一个像素点采用16位表示; LCD屏幕分辨率 480*272; 液晶模块型号:BL43014_SPEC;图像的内容以C语言数组的形式保存在bmp.c文件中。 ~~~ /* *版权所有(C)2015,ZJU * *文件名称:lcd.c *内容摘要:关于lcd的配置 *其它说明:开发板型号: TX2440 * led显示尺寸 480 x 272 液晶模块型号:BL43014_SPEC *当前版本:V1.0 *作 者:Frank *完成日期:2015.12.20 * */ #define GPCCON (*(volatile unsigned long *)0x56000020) #define GPDCON (*(volatile unsigned long *)0x56000030) #define GPGCON (*(volatile unsigned long *)0x56000060) //LCD控制寄存器定义 #define LCDCON1 (*(volatile unsigned long *)0x4D000000) #define LCDCON2 (*(volatile unsigned long *)0x4D000004) #define LCDCON3 (*(volatile unsigned long *)0x4D000008) #define LCDCON4 (*(volatile unsigned long *)0x4D00000C) #define LCDCON5 (*(volatile unsigned long *)0x4D000010) #define LCDSADDR1 (*(volatile unsigned long *)0x4D000014) #define LCDSADDR2 (*(volatile unsigned long *)0x4D000018) #define LCDSADDR3 (*(volatile unsigned long *)0x4D00001C) #define TPAL (*(volatile unsigned long *)0x4D000050) /*以下宏定义的值参考所使用的LCD液晶模块的芯片手册*/ #define VSPW 9 #define VBPD 7 #define LINEVAL 271 #define VFPD 7 #define CLKVAL 4 // 10 = 100 / ((CLKVAL+1)*2) #define HSPW 40 #define HBPD 39 #define HOZVAL 479 #define HFPD 4 unsigned short LCDBUFFER[272][480]; //定义一个LCD图像缓存空间 extern unsigned char bmp[90200]; typedef unsigned char U8; typedef unsigned short int U16; typedef unsigned int U32; /******************************************************************* *函数名称:Lcd_Port_Init() *功能描述:LCD端口初始化 *其他说明:配置LCD用到的GPIO端口 *创建日期:2015.12.20 *******************************************************************/ void Lcd_Port_Init(void) { GPDCON = 0xaaaaaaaa; GPCCON = 0xaaaaaaaa; } /******************************************************************* *函数名称:Lcd_Control_Init() *功能描述:LCD控制寄存器初始化 *其他说明:配置LCD用到的控制寄存器 *创建日期:2015.12.20 *******************************************************************/ void Lcd_Control_Init(void) { LCDCON1 = (CLKVAL << 8) | (0x3 << 5) | (0xC << 1) | (0 << 0); LCDCON2 = (VBPD << 24) | (LINEVAL << 14) | (VFPD << 6) | (VSPW); LCDCON3 = (HBPD << 19) | (HOZVAL << 8) | (HFPD); LCDCON4 = HSPW; // LCDCON5 = (1 << 11) | (1 << 9) | (1 << 8) | (1 << 0); LCDCON5 = (1 << 11) | (1 << 9) | (1 << 8); LCDSADDR1 = (((unsigned int)LCDBUFFER >> 22) << 21) | (((unsigned int)LCDBUFFER >> 1) & 0x1fffff); LCDSADDR2 = (((unsigned int)LCDBUFFER + 272*480*2) >> 1) & 0x1fffff; LCDSADDR3 = (0 << 11) | (480*2 / 2); TPAL = 0; } /******************************************************************* *函数名称:Lcd_Init() *功能描述:LCD初始化 *其他说明: *创建日期:2015.12.20 *******************************************************************/ void Lcd_Init() { Lcd_Port_Init(); Lcd_Control_Init(); /*打开LCD电源*/ GPGCON |= (0x3 << 8); LCDCON5 |= (1 << 3); /*使能LCD控制器*/ LCDCON1 |= 1; } /******************************************************************* *函数名称:point() *功能描述:在lcd上画一个点 *其他说明: *创建日期:2015.12.20 *******************************************************************/ void Point(unsigned int x, unsigned int y, unsigned int color) { unsigned int red, green, blue; red = (color >> 19) & 0x1f; green = (color >> 10) & 0x3f; blue = (color >> 3) & 0x1f; /*采用5:6:5的模式表示一个RGB*/ LCDBUFFER[y][x] = (unsigned short)((red << 11) | (green << 5) | blue); } /******************************************************************* *函数名称:Paint_Bmp(U16,U16,U16,U16,U8) *功能描述:LCD显示一幅图像 *输入参数:(x0,y0)图像显示第一个点的坐标; high图像的高度 wide图像的宽度; bmp存储图像的数组 *其他说明: *创建日期:2015.12.20 *******************************************************************/ void Paint_Bmp(U16 x0, U16 y0, U16 wide, U16 high, const U8 *bmp) { unsigned short x, y; unsigned short c; unsigned int p = 0; for (y=y0; y<y0+high; y++) { for (x=x0; x<x0+wide; x++) { c = bmp[p] | (bmp[p+1]<<8); /*一个像素点由16位表示,bmp[p] 表示低8位,bmp[p+1]表示高8位*/ if ((x<480) && (y<272)) { LCDBUFFER[y][x] = c; } p = p + 2; } } } /******************************************************************* *函数名称:Lcd_Test() *功能描述:LCD测试函数 *其他说明: *创建日期:2015.12.20 *******************************************************************/ void Lcd_Test(void) { int x; /* for (x=0; x<480; ++x) { Point(x++, 150, 0xff0000); } */ Paint_Bmp(0,0,220,220,bmp); } ~~~ 需要注意的几点: 1、宏定义的值需要参考使用的LCD液晶模块的芯片手册(TX2440使用的LCD是BL43014_SPEC) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-07-26_579724f9a7b54.jpg) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-07-26_579724f9c733d.jpg) 图1 BL43014_SPEC Input Time Table 2、液晶模块的Vsync和Hsync的时序与S3C2440芯片手册上的相反,所以LCDCON5中bit8和bit9需要设置为1。 ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-07-26_579724f9e6495.jpg) 图2 BL43014_SPEC Vertical Input Timing ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-07-26_579724fa0cc5e.jpg) 图3 TFT LCD Timing Example( S3C2440 Datasheet)
';