|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2014-9-2 19:48:53
|
显示全部楼层
本帖最后由 zhourdev 于 2014-9-2 19:51 编辑
以下是代码:void LCD_init(int xSize, int ySize)
{
uint32_t i;
uint32_t *pPal;
g_lcdHSize = xSize;
g_lcdVSize = ySize;
#if defined(LCD_MODEL_AT070) // 注意.此处的初始化的值
// 设置,将主频分频给LCD_CLK. C_GLCD_CLK_DIV = 4;
LPC_CGU->IDIVE_CTRL = ((0x0009 << 24) | (0x0001 << 11)) | (C_GLCD_CLK_DIV<< 2); // 设置时钟产生单元.设置LCD的CLK分频
// 重点在这里,0x10,采用DIVE分频后的频率
LPC_CGU->BASE_LCD_CLK = ((0x10 << 24) | (0x0001 << 11));
#elif defined(LCD_MODEL_320_240) //
LPC_CGU->IDIVE_CTRL = ((0x0009 << 24) | (0x0001 << 11)) | (C_GLCD_CLK_DIV<< 2);
LPC_CGU->BASE_LCD_CLK = ((0x10 << 24) | (0x0001 << 11));
#endif
scu_pinmux(0X01, 4, MD_PUP, FUNC0); /* LCD_PWR @ P1.4 */ //PWR 一定要给一个稳态
GPIO_SetDir(1, 1<<4, 1);
GPIO_SetValue(0X01, 1<<4);
// GPIO_ClearValue(0X01, 1<<4);
// Assign pins
// scu_pinmux(0x07, 7, MD_PUP, FUNC3); /* LCD_PWR @ P7.7 */ //PWR
scu_pinmux(0x04, 7, MD_PUP, FUNC0); /* LCD_DCLK @ P4.7 */ //CP
scu_pinmux(0x04, 5, MD_PUP, FUNC2); /* LCD_FP @ P4.5 */ //FP
scu_pinmux(0x04, 6, MD_PUP, FUNC2); /* LCD_ENAB_M @ P4.6 */ //AC
scu_pinmux(0x07, 6, MD_PUP, FUNC3); /* LCD_LP @ P7.6 */ //LP
scu_pinmux(0x04, 2, MD_PUP, FUNC2); // LCD_VD_3 @ P4.2 // // 16位
scu_pinmux(0x08, 7, MD_PUP, FUNC3); // LCD_VD_4 @ P8.7 //
scu_pinmux(0x08, 6, MD_PUP, FUNC3); // LCD_VD_5 @ P8.6 //
scu_pinmux(0x08, 5, MD_PUP, FUNC3); // LCD_VD_6 @ P8.5 //
scu_pinmux(0x08, 4, MD_PUP, FUNC3); // LCD_VD_7 @ P8.4 //
scu_pinmux(0x04, 10, MD_PUP, FUNC2); // LCD_VD_10 @ P4.10 //
scu_pinmux(0x04, 9, MD_PUP, FUNC2); // LCD_VD_11 @ P4.9 //
scu_pinmux(0x08, 3, MD_PUP, FUNC3); // LCD_VD_12 @ P8.3 //
scu_pinmux(0x0B, 6, MD_PUP, FUNC2); // LCD_VD_13 @ PB.6 //
scu_pinmux(0x0B, 5, MD_PUP, FUNC2); // LCD_VD_14 @ PB.5 //
scu_pinmux(0x0B, 4, MD_PUP, FUNC2); // LCD_VD_15 @ PB.4 //
scu_pinmux(0x07, 1, MD_PUP, FUNC3); // LCD_VD_19 @ P7.1 //
scu_pinmux(0x0B, 3, MD_PUP, FUNC2); // LCD_VD_20 @ PB.3 //
scu_pinmux(0x0B, 2, MD_PUP, FUNC2); // LCD_VD_21 @ PB.2 //
scu_pinmux(0x0B, 1, MD_PUP, FUNC2); // LCD_VD_22 @ PB.1 //
scu_pinmux(0x0B, 0, MD_PUP, FUNC2); // LCD_VD_23 @ PB.0 //
// scu_pinmux(0x07, 0, MD_PUP, FUNC0); /* LCD_LE @ P7.0 */ //LE & CLKIN not used
scu_pinmux(0x0f,8, MD_PUP, FUNC4); //Pf_8 GPIO7[22]]LCDPowC1 func0 gpio
scu_pinmux(0x0f,9, MD_PUP, FUNC4); //Pf_9 GPIO7[23]LCDPowC2
GPIO_SetDir(7,1<<22, 1); //Pf_8 GPIO7[22]LCDPowC1
GPIO_SetDir(7,1<<23, 1); //Pf_9 GPIO7[23]LCDPowC2
GPIO_ClearValue(7, 1<<22);
GPIO_ClearValue(7, 1<<23);
LPC_RGU->RESET_CTRL0 = (1UL << 16); //do lcd reset;
LPC_LCD->CTRL &= ~(1<<0);
LPC_LCD->CRSR_CTRL &=~(1<<0); //disable curser;
LPC_LCD->CTRL |= (6<<1); //565
LPC_LCD->CTRL |= (1<<5); // TFT panel
LPC_LCD->CTRL &= ~(1<<7); // single panel
LPC_LCD->CTRL &= ~(1<<8); // notmal output rgb
// LPC_LCD->CTRL |= (1<<8); // 红色与蓝交换
LPC_LCD->CTRL &= ~(1<<9); // little endian byte order
// LPC_LCD->CTRL |= (1<<9);
LPC_LCD->CTRL &= ~(1<<10); // little endian pix order
// disable power
LPC_LCD->CTRL &= ~(1<<11);
// init Horizontal Timing
LPC_LCD->TIMH = 0; //reset TIMH before set value
LPC_LCD->TIMH |= (C_GLCD_H_BACK_PORCH - 1)<<24;
LPC_LCD->TIMH |= (C_GLCD_H_FRONT_PORCH - 1)<<16;
LPC_LCD->TIMH |= (C_GLCD_H_PULSE - 1)<<8;
LPC_LCD->TIMH |= ((g_lcdHSize/16) - 1)<<2;
// init Vertical Timing
LPC_LCD->TIMV = 0; //reset TIMV value before setting
LPC_LCD->TIMV |= (C_GLCD_V_BACK_PORCH)<<24;
LPC_LCD->TIMV |= (C_GLCD_V_FRONT_PORCH)<<16;
LPC_LCD->TIMV |= (C_GLCD_V_PULSE - 1)<<10;
LPC_LCD->TIMV |= g_lcdVSize-1;
LPC_LCD->LE = 0;
LPC_LCD->INTMSK = 0;
LPC_LCD->POL = 0;
LPC_LCD->POL |= 0x01 << 26;
LPC_LCD->POL |= (g_lcdHSize-1)<< 16;
// #if defined(LCD_MODEL_AT070)
// LPC_LCD->POL |= 0x01 << 12; //invert H sync
// LPC_LCD->POL |= 0x01 << 11; //invert v sync
// #endif
/* clear palette */
pPal = (uint32_t*) (&(LPC_LCD->PAL));
for(i = 0; i < 128; i++)
{
*pPal = 0;
pPal++;
}
LPC_LCD->UPBASE = (uint32_t)g_lcdFrame;
// 使用LCD控制器
LPC_LCD->CTRL |= (1<<0);
for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
LPC_LCD->CTRL |= (1<<11);
g_lcdPenColor = LCD_COLOR_BLACK;
g_lcdPenSize = 1;
} |
|