下面看看2440test里面的lcd.c文件
static void PutPixel(U32 x,U32 y,U16 c) { if(x } |
很容易发现TFT LCD上显示单个像素的函数实际上很简洁
看来似乎只需要LCD_BUFFER[(y)][(x)] = c这一句话
下面就来分析下,是如何通过这一句话来实现在LCD上显示单个像素的
先分析下LCD_Init()即LCD初始化函数
rLCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); |
LCDCON1 0x4d000000
#define LCD_WIDTH 240
#define LCD_HEIGHT 320
#define LCD_PIXCLOCK 4
#define LCD_RIGHT_MARGIN 36
#define LCD_LEFT_MARGIN 19
#define LCD_HSYNC_LEN 5
#define LCD_UPPER_MARGIN 1
#define LCD_LOWER_MARGIN 5
#define LCD_VSYNC_LEN 1
CLKVAL[17:8] = 4
TFT: VCLK = HCLK / [(CLKVAL+1) * 2] ( CLKVAL>=0 )
MMODE[7] = 0
PNRMODE[6:5] = 11 TFT LCD panel
BPPMODE[4:1] = 1100 16bpp for TFT
ENVID[0] = 0 Disable
rLCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); |
LCDCON2 0x4d000004
VBPD = 1
VBPD(vertical back porch):表示在一帧图像开始时,垂直同步信号以后的无效的行数,对应驱动中的upper_margin
LINVAL = 240 – 1
LINVAL:LCD屏的垂直大小
VFPD = 5
VFPD(vertical front porch):表示在一帧图像结束后,垂直同步信号以前的无效的行数,对应驱动中的lower_margin
VSPW = 1
VSPW(vertical sync pulse width):表示垂直同步脉冲的宽度,用行数计算,对应驱动中的vsync_len
rLCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); |
LCDCON3 0x4d000008
HBPD = 36
HBPD(horizontal back porch):表示从水平同步信号开始到一行的有效数据开始之间的VCLK的个数,对应驱动中的left_margin
HOZVAL = 320 – 1
HOZVAL:LCD屏的水平大小
HFPD = 19
HFPD(horizontal front porth):表示一行的有效数据结束到下一个水平同步信号开始之间的VCLK的个数,对应驱动中的right_margin
rLCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); |
LCDCON4 0x4d00000c
MVAL = 13
HSPW = 5
HSPW(horizontal sync pulse width):表示水平同步信号的宽度,用VCLK计算,对应驱动中的hsync_len
# define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0)) |
LCDCON5 0x4d000010
HWSWP = 1 Swap Enable
PWREN = 1 Enable PWREN signal
INVVFRAME = 1 VFRAME/VSYNC pulse polarity Inverted 选择负极性脉冲
INVVLINE = 1 VLINE/HSYNC pulse polarity Inverted 选择负极性脉冲
FRM565 = 1 5:6:5 Format
rLCDINTMSK |= 3; |
INT_FrSyn = 1 LCD frame synchronized interrupt Masked
INT_FiCnt = 1 LCD FIFO interrupt Masked
rTCONSEL &= (~7); rTCONSEL &= ~((1<<4) | 1); |
MODE_SEL = 0 Sync mode
RES_SEL = 0 320 x 240
LPC_EN = 0 LPC3600 Disable
rTPAL = 0x0; |
Temporary palette register enable bit Disable
volatile static unsigned short LCD_BUFFER[SCR_YSIZE][SCR_XSIZE]; #define LCD_ADDR ((U32)LCD_BUFFER) #define M5D(n) ((n)&0x1fffff) rLCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0); rLCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); rLCDSADDR3 = LCD_WIDTH; |
LCDSADDR1 0x4d000014 帧缓冲起始寄存器1
LCDBANK[29:21] = (U32)LCD_BUFFER >> 22
These bits indicate A[30:22] of the bank location for the video buffer in the system memory. LCDBANK value cannot be changed even when moving the view port. LCD frame buffer should be within aligned 4MB region, which ensures that LCDBANK value will not be changed when moving the view port. So, care should be taken to use the malloc() Function
系统内存地址A[30:22]处的Bank位置为图像缓冲。LCDBANK的值在视图移动的值在视图移动时不能改变,LCD帧缓冲应该在4MB区域对齐,保证LCDBANK的值在移动视图时不会改变。
LCDBASEU[20:0] = ((U32)LCD_BUFFER >> 1)&0x1fffff
For dual-scan LCD : These bits indicate A[21:1] of the start address of the upper address counter, which is for the upper frame memory of dual scan LCD or the frame memory of single scan LCD.
For single-scan LCD : These bits indicate A[21:1] of the start address of the LCD frame buffer.
双扫描:表明高地址计数器的起始地址A[21:1],用于LCD双扫描的上部帧内存或者单扫描的帧内存
单扫描:表明LCD帧缓冲的起始地址A[21:1]
LCDSADDR2 0x4d000018帧缓冲起始寄存器2
LCDBASEL[20:0] = ((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1)& 0x1fffff
= (LCD_ADDR >> 1 + LCD_WIDTH * LCD_HEIGHT)& 0x1fffff
For dual-scan LCD: These bits indicate A[21:1] of the start address of the lower address counter, which is used for the lower frame memory of dual scan LCD.
For single scan LCD: These bits indicate A[21:1] of the end address of the LCD frame buffer.
LCDBASEL = ((the frame end address) >>1) + 1
= LCDBASEU + (PAGEWIDTH+OFFSIZE) x (LINEVAL+1)
双扫描:表明低地址计数器的起始地址A[21:1],用于LCD双扫描的下部帧内存或者单扫描的帧内存
单扫描:表明LCD帧缓冲的结束地址A[21:1]
LCDSADDR3 0x4d00001c帧缓冲起始寄存器3
OFFSIZE = 0
PAGEWIDTH = 320 虚拟屏页宽(半字数量) 定义了帧中的视图域宽度
程序分析至此,大概已经清楚是如何通过LCD_BUFFER[(y)][(x)] = c来实现在LCD上显示单个像素了。
就是在设置好各个LCD寄存器之后,通过将LCD_BUFFER地址与LCDBANK以及LCDBASEU、LCDBASEL对应之后,通过改变LCD_BUFFER里不同单元存储的值(即像素的颜色),即可在LCD相应位置上做出显示。
那么在应用不同LCD的时候,只需对LCDCONx以及LCDSADDRx做出相应的配置,在创建一个数组,做出上述的地址映射即可。
关于VCLK计算,由于配置的是TFT,可用到公式VCLK = HCLK / [(CLKVAL+1) * 2] ( CLKVAL>=0 )
设置的FLK为400MHz,HCLK为100MHz,CLKVAL = 4,因此VLCK = 10MHz
上一篇:S3C2440裸机学习[2] - LCD驱动原理及代码分析[一]
下一篇:Mini2440裸机液晶屏TD35驱动
推荐阅读最新更新时间:2024-11-02 13:42
设计资源 培训 开发板 精华推荐
- LTC1261LIMS8-4.5 低输出电压发生器的典型应用电路
- 3.13 至 3.46V、4.75 至 5.25V DC 至 DC 多路输出电源
- LTC1625,峰值功率跟踪降压充电器最大限度地提高效率
- 使用 Analog Devices 的 LT1317BCMS8 的参考设计
- DC1924A,使用 LT8705、80V VIN 和 VOUT 同步 4 开关降压-升压型 DC-DC 控制器的演示板
- 用于IoT节点的STM32 Nucleo包,具有连接到Microsoft Azure IoT的Wi-Fi,传感器和NFC
- 基于STGIB30M60TS-L SLLIMM 2nd系列IPM的2500 W电机控制电源板
- 【广西师大校赛】任意波形发生器
- LTC6258IDC 1.3MHz、20uA 高功率高效轨至轨 I/O 运算放大器的典型应用
- 用于仪表的 5V 模拟放大器