s3c2410 LCD图片显示
- 格式:doc
- 大小:37.50 KB
- 文档页数:7
s3c2410 LCD图片显示
最近研究了s3c2410下LCD控制器的相关知识,主要的参考资料就是 三星s3c2410数据手册(arm920T),英文版,看的不是非常明白,后来参考了WinCE下的部分代码,似有所领悟。于是写了此程序,用以在LCD上显示图片。
本程序可以在LCD上居中显示小于800×480的任意大小的图片。用到的辅助工具就是上篇文章中的RGB分量提取器.
关键模块如下:
0、全局变量的定义:
#define DMA_BUFFER_BASE 0xAC000000
#define DMA_PHYSICAL_BASE 0x35000000 // S3C2410X01 0x30000000
#define FRAMEBUF_BASE (DMA_BUFFER_BASE + 0x00100000)
#define FRAMEBUF_DMA_BASE (DMA_PHYSICAL_BASE +
0x00000000)//0x00100000
#define IOP_BASE 0x56000000 // 0x56000000
typedef struct {
unsigned int GPACON; // 00
unsigned int GPADAT;
unsigned int PAD1[2];
...................
}IOPreg;
// Define LCD type of S3C2400X01
#define TFT24BPP 3
#define LCDTYPE TFT24BPP // define LCD type as upper definition.
//
// Registers : LCD Controller
//
#define LCD_BASE 0x4D000000 // 0x4D000000
typedef struct {
unsigned int LCDCON1; // 00
unsigned int LCDCON2; // 04 unsigned int LCDCON3; // 08
.....................
}LCDreg ;
// LCD register value
#define MODE_TFT_24BIT (224)
#define LCD_XSIZE_TFT (800)
#define LCD_YSIZE_TFT (480)
#define ARRAY_SIZE_TFT_24BIT (SCR_XSIZE*4*SCR_YSIZE)
#define HOZVAL_TFT (LCD_XSIZE_TFT-1)
#define LINEVAL_TFT (LCD_YSIZE_TFT-1)
#define MVAL (13)
#define MVAL_USED (0)
#define VBPD ((32-1)&0xff)
#define VFPD ((11-1)&0xff)
#define VSPW ((2-1) &0x3f)
#define HBPD ((88-1)&0x7f)
#define HFPD ((40-1)&0xff)
#define HSPW ((128-1)&0xff)
#define CLKVAL_TFT (1)
#define M5D(n) ((n) & 0x1fffff)
U32* pLCDBuffer24=(U32*)FRAMEBUF_DMA_BASE;
U32* picData;
volatile LCDreg *s2410LCD = (LCDreg *)LCD_BASE;
volatile IOPreg *s2410IOP= (IOPreg *)IOP_BASE;
int nCol = 800;//象素列数
int nRow = 480;//象素行数
U32* picDataT=NULL;
1、入口函数,其中包括了相应端口、寄存器初始化的入口,aa,bb,cc,dd,ee是可选择的5幅预定义图片的GRB码数组,具体代码如下
void lcd_Main(void)
{ char sel;
Uart_Printf("Lcd_Driver ");
lcd_port_init();
lcd_regs_init();
Uart_Printf("select one Picture to show(1 2 3 4 5 0) ");
while((sel = Uart_Getch()) != 'e')
{
Uart_Printf("%c ",sel);
switch(sel)
{
case '1':
picData = (U32*)aa;break;
case '2':
picData =(U32*)bb;break;
case '3':
picData = (U32*)cc;break;
case '4':
picData = (U32*)dd; break;
case '5':
picData = (U32*)ee;break;
default:
Uart_Printf("Input 1 2 3 4 5 0 ");
}
lcd_display();
Uart_Printf("select one Picture to show(1 2 3 4 5 0) ");
}
Uart_Printf("Exit");
//lcd_close();
}
2、相应端口设置,包括GPC,GPD,GPG的相应位的设置:
void lcd_port_init(void)
{
// LCD port initialize.
s2410IOP->GPCUP = 0xFFFFFFFF;
s2410IOP->GPCCON = 0xAAAAAAAA;
s2410IOP->GPDUP = 0xFFFFFFFF;
s2410IOP->GPDCON = 0xAAAAAAAA;
s2410IOP->GPGCON &= ~(3 << 8); /**//* Set LCD_PWREN as
output */
s2410IOP->GPGCON |= (1 << 8);
s2410IOP->GPGDAT |= (1 << 4); //* Backlight ON,关键,不然lcd不亮
}
3、控制寄存器设置:
void lcd_regs_init(void)
{
#ifdef MODE_TFT_24BIT
s2410LCD->LCDCON1 = (1 << 8) | //* VCLK = HCLK / ((CLKVAL + 1) *
2) -> About 7 Mhz
(MVAL_USED << 7) | //* 0 : Each
Frame
(3 << 5) | // TFT LCD Pannel
(13 << 1) | //Y: // 24bpp Mode
(0 << 0) ; // Disable LCD Output
s2410LCD->LCDCON2 = (VBPD << 24) | //*
VBPD : ((32-1)&0xff)
(LINEVAL_TFT << 14) | //* LINEVAL_TFT : 480 -
1
(VFPD << 6) | //* VFPD :
((11-1)&0xff) (VSPW << 0) ; //* VSPW : ((2-1)
&0x3f)
s2410LCD->LCDCON3 = (HBPD << 19) | //*
HBPD : ((88-1)&0x7f)
(HOZVAL_TFT << 8) | //* HOZVAL_TFT : 800 -
1
(HFPD << 0) ; //* HFPD :