裸机控制器详解原理程序LCD(裸机控制器引脚寄存器详解)

来源:韦东山嵌入式专栏_ARM裸机加强版维基教程作者:韦东山本文字数:3840,阅读时长:2.5分钟继续上一节的代码,修改s3c2440_lcd_controller.c:struct lcd_controller s3c2440_lcd_controller = { .init = s3c2440_lcd_controller_init, .enalbe = s3c2440_lcd_controller_enalbe, .disable = xs3c2440_lcd_controller_disable,};然后对每个函数进行功能实现,首先是s3c2440_lcd_controller_init,依次设置LCD控制器寄存器,先是LCD寄存器1:[27:18]为只读数据位,不需要设置;[17:8]用于设置CLKVAL(像素时钟频率),我们使用的是TFT屏,因此采用的公式是VCLK = HCLK / [(CLKVAL+1) x 2],其中HCLK为100M
LCD手册里面Clock cycle的要求范围为5-12MHz即可,即假设VCLK=9,根据公式9=100/[(CLKVAL+1)x2],算出CLKVAL≈4.5=5
VCLK为plcdparams->time_seq.vclk,则clkval = HCLK/plcdparams->time_seq.vclk/2-1+0.5;[7]不用管,默认即可;[6:5]TFT lcd配置为0b11;[4:1]设置bpp模式,根据传入的plcdparams->bpp配置为相应的数值;[0]LCD输出使能,先暂时关闭不输出;寄存器2:对比2440LCD部分时序图和LCD时序图,得出两者之间关系,以后就可通过plcdparams传参数进来设置相关寄存器
[31:24] : VBPD = tvb - 1[23:14] : LINEVAL = line - 1[13:6] : VFPD = tvf - 1[5:0] : VSPW = tvp - 1寄存器3:[25:19] : HBPD = thb - 1[18:8] : HOZVAL = 列 - 1[7:0] : HFPD = thf - 1寄存器4:[7:0] : HSPW = thp - 1寄存器5:用来设置引脚极性, 设置16bpp, 设置内存中象素存放的格式[12] : BPP24BL[11] : FRM565, 1-565[10] : INVVCLK, 0 = The video data is fetched at VCLK falling edge[9] : HSYNC是否反转[8] : VSYNC是否反转[7] : INVVD, rgb是否反转[6] : INVVDEN[5] : INVPWREN[4] : INVLEND[3] : PWREN, LCD_PWREN output signal enable/disable[2] : ENLEND[1] : BSWP[0] : HWSWP然后再设置framebuffer地址,先是LCDSADDR1:[29:21] : LCDBANK, A[30:22] of fb[20:0] : LCDBASEU, A[21:1] of fb即用[29:0]表示起始地址的[30:1]
LCDSADDR2:[20:0] : LCDBASEL, A[21:1] of end addr即framebuffer的结束地址
最后还要设置相关引脚,包括背光控制引脚、LCD专用引脚、电源控制引脚:void jz2440_lcd_pin_init(void){ / 初始化引脚 : 背光引脚 / GPBCON &= ~0x3; GPBCON |= 0x01; / LCD专用引脚 / GPCCON = 0xaaaaaaaa; GPDCON = 0xaaaaaaaa; / PWREN / GPGCON |= (3<<8);}LCD所有寄存器的具体设置如下:#define HCLK 100void jz2440_lcd_pin_init(void){ / 初始化引脚 : 背光引脚 / GPBCON &= ~0x3; GPBCON |= 0x01; / LCD专用引脚 / GPCCON = 0xaaaaaaaa; GPDCON = 0xaaaaaaaa; / PWREN / GPGCON |= (3<<8);}/ 根据传入的LCD参数设置LCD控制器 /void s3c2440_lcd_controller_init(p_lcd_params plcdparams){ int pixelplace; unsigned int addr; jz2440_lcd_pin_init(); / [17:8]: clkval, vclk = HCLK / [(CLKVAL+1) x 2] 9 = 100M /[(CLKVAL+1) x 2], clkval = 4.5 = 5 CLKVAL = 100/vclk/2-1 [6:5]: 0b11, tft lcd [4:1]: bpp mode [0] : LCD video output and the logic enable/disable / int clkval = (double)HCLK/plcdparams->time_seq.vclk/2-1+0.5; int bppmode = plcdparams->bpp == 8 ? 0xb :\ plcdparams->bpp == 16 ? 0xc :\ 0xd; / 0xd: 24bpp / LCDCON1 = (clkval<<8) | (3<<5) | (bppmode<<1) ; / [31:24] : VBPD = tvb - 1 [23:14] : LINEVAL = line - 1 [13:6] : VFPD = tvf - 1 [5:0] : VSPW = tvp - 1 / LCDCON2 = ((plcdparams->time_seq.tvb - 1)<<24) | \ ((plcdparams->yres - 1)<<14) | \ ((plcdparams->time_seq.tvf - 1)<<6) | \ ((plcdparams->time_seq.tvp - 1)<<0); / [25:19] : HBPD = thb - 1 [18:8] : HOZVAL = 列 - 1 [7:0] : HFPD = thf - 1 / LCDCON3 = ((plcdparams->time_seq.thb - 1)<<19) | \ ((plcdparams->xres - 1)<<8) | \ ((plcdparams->time_seq.thf - 1)<<0); / [7:0] : HSPW = thp - 1 / LCDCON4 = ((plcdparams->time_seq.thp - 1)<<0); / 用来设置引脚极性, 设置16bpp, 设置内存中象素存放的格式 [12] : BPP24BL [11] : FRM565, 1-565 [10] : INVVCLK, 0 = The video data is fetched at VCLK falling edge [9] : HSYNC是否反转 [8] : VSYNC是否反转 [7] : INVVD, rgb是否反转 [6] : INVVDEN [5] : INVPWREN [4] : INVLEND [3] : PWREN, LCD_PWREN output signal enable/disable [2] : ENLEND [1] : BSWP [0] : HWSWP / pixelplace = plcdparams->bpp == 24 ? (0) : |\ plcdparams->bpp == 16 ? (1) : |\ (1<<1); / 8bpp / LCDCON5 = (plcdparams->pins_pol.vclk<<10) |\ (plcdparams->pins_pol.rgb<<7) |\ (plcdparams->pins_pol.hsync<<9) |\ (plcdparams->pins_pol.vsync<<8) |\ (plcdparams->pins_pol.de<<6) |\ (plcdparams->pins_pol.pwren<<5) |\ (1<<11) | pixelplace; / framebuffer地址 / / [29:21] : LCDBANK, A[30:22] of fb [20:0] : LCDBASEU, A[21:1] of fb / addr = plcdparams->fb_base & ~(1<<31); LCDSADDR1 = (addr >> 1); / [20:0] : LCDBASEL, A[21:1] of end addr / addr = plcdparams->fb_base + plcdparams->xresplcdparams->yresplcdparams->bpp/8; addr >>=1; addr &= 0x1fffff; LCDSADDR2 = addr;// }void s3c2440_lcd_controller_enalbe(void){ / 背光引脚 : GPB0 / GPBDAT |= (1<<0); / pwren : 给LCD提供AVDD / LCDCON5 |= (1<<3); / LCDCON1'BIT 0 : 设置LCD控制器是否输出信号 / LCDCON1 |= (1<<0);}void s3c2440_lcd_controller_disable(void){ / 背光引脚 : GPB0 / GPBDAT &= ~(1<<0); / pwren : 给LCD提供AVDD / LCDCON5 &= ~(1<<3); / LCDCON1'BIT 0 : 设置LCD控制器是否输出信号 / LCDCON1 &= ~(1<<0);}这就完成了s3c2440_lcd_controller.c的编写,后面只需要向s3c2440_lcd_controller_init()传入构造好的参数即可
上一篇:LCD原理详解及裸机程序分析——第004节_编程抽象出重要结构体下一篇:LCD原理详解及裸机程序分析——第006节_LCD设置编程 点击“了解更多”阅读更多相关文章
裸机控制器详解原理程序LCD(裸机控制器引脚寄存器详解)
(图片来源网络,侵删)

联系我们

在线咨询:点击这里给我发消息