基础知识:
G. 使能图形输出(b’11)
④ 设置时钟极性(VIDCON1),(b’1,b’1)
⑤ 配置时序
A. 设置 VBPD,VFPD,VSPW(VIDTCON0)
B. 设置 HBPD,HFPD,HSPW(VIDTCON1)
这里给出参考值:
#define HSPW (0)
#define HBPD (40- 1)
#define HFPD (5 - 1)
#define VSPW (0)
#define VBPD (8 - 1)
#define VFPD (8 - 1)
⑥ 设置长宽(VIDTCON2)
Vertical :列数设置 272 - 1
Horizontal :行数设置为 480 - 1
⑦ 配置 WINDOW0 的数据格式(打开 window0,设置数据格式为 24bpp,b’1011)
⑧ 配置 WINDOW0 的坐标系(即设置 WINDOW0 大小)
如果设置满屏,则 OSD_LeftTopX_F = 0, OSD_LeftTopX_F = 0;
OSD_RightBotX_F = 479, OSD_RightBotY_F = 271
⑨ 设置 FRAMEBUF 起始地址,结束地址,buf 大小
VIDW00ADD0B0 设置起始地址
VIDW00ADD1B0 设置结束地址
VIDW00ADD2B0 设置 BUF 大小
下面贴上源代码:
#define VIDCON0 (*(volatile unsigned *)0x4c800000)
#define VIDCON1 (*(volatile unsigned *)0x4c800004)
#define VIDTCON0 (*(volatile unsigned *)0x4c800008)
#define VIDTCON1 (*(volatile unsigned *)0x4c80000C)
#define VIDTCON2 (*(volatile unsigned *)0x4c800010)
#define WINCON0 (*(volatile unsigned *)0x4c800014)
#define WINCON1 (*(volatile unsigned *)0x4c800018)
#define VIDOSD0A (*(volatile unsigned *)0x4c800028)
#define VIDOSD0B (*(volatile unsigned *)0x4c80002C)
#define VIDOSD1A (*(volatile unsigned *)0x4c800034)
#define VIDOSD1B (*(volatile unsigned *)0x4c800038)
#define VIDOSD1C (*(volatile unsigned *)0x4c80003C)
#define VIDW00ADD0B0 (*(volatile unsigned *)0x4c800064)
#define VIDW00ADD0B1 (*(volatile unsigned *)0x4c800068)
#define VIDW01ADD0 (*(volatile unsigned *)0x4c80006C)
#define VIDW00ADD1B0 (*(volatile unsigned *)0x4c80007C)
#define VIDW00ADD1B1 (*(volatile unsigned *)0x4c800080)
#define VIDW01ADD1 (*(volatile unsigned *)0x4c800084)
#define VIDW00ADD2B0 (*(volatile unsigned *)0x4c800094)
#define VIDW00ADD2B1 (*(volatile unsigned *)0x4c800098)
#define VIDW01ADD2 (*(volatile unsigned *)0x4c80009C)
#define VIDINTCON (*(volatile unsigned *)0x4c8000AC)
#define W1KEYCON0 (*(volatile unsigned *)0x4c8000B0)
#define W1KEYCON1 (*(volatile unsigned *)0x4c8000B4)
#define W2KEYCON0 (*(volatile unsigned *)0x4c8000B8)
#define W2KEYCON1 (*(volatile unsigned *)0x4c8000BC)
#define W3KEYCON0 (*(volatile unsigned *)0x4c8000C0)
#define W3KEYCON1 (*(volatile unsigned *)0x4c8000C4)
#define W4KEYCON0 (*(volatile unsigned *)0x4c8000C8)
#define W4KEYCON1 (*(volatile unsigned *)0x4c8000CC)
#define WIN0MAP (*(volatile unsigned *)0x4c8000D0)
#define WIN1MAP (*(volatile unsigned *)0x4c8000D4)
#define WPALCON (*(volatile unsigned *)0x4c8000E4)
#define SYSIFCON0 (*(volatile unsigned *)0x4c800130)
#define SYSIFCON1 (*(volatile unsigned *)0x4c800134)
#define DITHMODE1 (*(volatile unsigned *)0x4c800138)
#define SIFCCON0 (*(volatile unsigned *)0x4c80013C)
#define SIFCCON1 (*(volatile unsigned *)0x4c800140)
#define SIFCCON2 (*(volatile unsigned *)0x4c800144)
#define CPUTRIGCON1 (*(volatile unsigned *)0x4c80015C)
#define CPUTRIGCON2 (*(volatile unsigned *)0x4c800160)
#define VIDW00ADD0B1 (*(volatile unsigned *)0x4c800068)
#define VIDW01ADD0 (*(volatile unsigned *)0x4c80006C)
#define GPCCON (*(volatile unsigned *)(0x56000020))
#define GPCDAT (*(volatile unsigned *)(0x56000024))
#define GPCUDP (*(volatile unsigned *)(0x56000028))
#define GPDCON (*(volatile unsigned *)(0x56000030))
#define GPDDAT (*(volatile unsigned *)(0x56000034))
#define GPDUDP (*(volatile unsigned *)(0x56000038))
#define MISCCR (*(volatile unsigned *)(0x56000080))
#define GPLCON (*(volatile unsigned *)(0x560000f0))
#define GPLDAT (*(volatile unsigned *)(0x560000f4))
#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)
#define GPGCON (*(volatile unsigned long *)0x56000060)
#define GPGDAT (*(volatile unsigned long *)0x56000064)
#define HSPW (0)
#define HBPD (40- 1)
#define HFPD (5 - 1)
#define VSPW (0)
#define VBPD (8 - 1)
#define VFPD (8 - 1)
unsigned long FRAME_BUFFER[272][480];
void lcd_init(void) //lcd初始化
{
GPCCON = 0xaaaaaaaa; //配置GPC,GPD特殊功能口
GPDCON = 0xaaaaaaaa;
GPBCON &= ~(0x3<<2); //对要操作的位清零
GPBCON |= (0x1<<2); //配置GPB1
GPBDAT |= (0x1<<1); //打开背光
VIDCON0 = 0; //清零
VIDCON0 = (0x0<<22)|(0x0<<13)|(9<<6)|(1<<5)|(1<<4)|(0x3<<0); //设置接口类型,时钟,极性和 LCD 控制器
VIDCON1 = 0; //清零
VIDCON1 |= (1<<6)|(1<<5); //设置时钟极性
VIDTCON0 = 0;
VIDTCON1 = 0;
VIDTCON0 |= (VBPD<<16)|(VFPD<<8)|(VSPW<<0); //配置时序
VIDTCON1 |= (HBPD<<16)|(HFPD<<8)|(HSPW<<0);
VIDTCON2 = 0;
VIDTCON2 |= (271<<11)|(479<<0); //设置长宽
WINCON0 = 0;
WINCON0 |= (0xb<<2)|(1<<0); // 配置 WINDOW0 的数据格式
VIDOSD0A = 0;
VIDOSD0A |= (0<<11)|(0<<0); //配置 WINDOW0 的坐标系(左上角)
VIDOSD0B = 0;
VIDOSD0B |= (479<<11)|(271<<0); //配置 WINDOW0 的坐标系(右下角)
VIDW00ADD0B0 = (unsigned long)FRAME_BUFFER; //设置 FRAMEBUF 起始地址,结束地址
VIDW00ADD1B0 = (unsigned long)FRAME_BUFFER+sizeof(FRAME_BUFFER);
}
void chear_test(void) //检测,全屏红色
{
unsigned int x,y;
for(y=0; y<272; y++)
{
for(x=0; x<480; x++)
{
FRAME_BUFFER[y][x] = 0x00ff0000; //红色
}
}
}