|
发表于 2014-10-28 16:32:38
|
显示全部楼层
//-----------------------------------------------------------------------------
//函数:void LCD_GPIOInit(void)
//输入:void
//输出:void
//描述:LCD GPIO初始化
//-----------------------------------------------------------------------------
void LCD_GPIOInit(void)
{ unsigned i;
GPIO_InitTypeDef GPIO_InitStructure;
//----------------------------------------------------------------------------
// R3 --> PH9 | G2 --> PH13 | B3 --> PG11 | VSYNC --> PI10 原
// R4 --> PH10 | G3 --> PH14 | B4 --> PG12 | HSYNC --> PI9
// R5 --> PH11 | G4 --> PH15 | B5 --> PI5 | DE --> PF10
// R6 --> PB1 | G5 --> PI0 | B6 --> PI6 | CLK --> PG7
// R7 --> PG6 | G6 --> PI1 | B7 --> PI7 | BL_EN --> PG13
// | G7 --> PI2 |
//----------------------------------------------------------------------------
// R3 --> PH9 | G2 --> PH13 | B3 --> PG11 | VSYNC --> PI9 现 为何与原来相反!!!!
// R4 --> PH10 | G3 --> PH14 | B4 --> PI4 | HSYNC --> PI10
// R5 --> PH11 | G4 --> PH15 | B5 --> PI5 | DE --> PF10
// R6 --> PH12 | G5 --> PI0 | B6 --> PI6 | CLK --> PG7
// R7 --> PG6 | G6 --> PI1 | B7 --> PI7 | LCD_BM--> PH6
// | G7 --> PI2 |
// 使能GPIO时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG
| RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, ENABLE);
LCD_HSYNCOn();
LCD_VSYNCOn();
LCD_U_DOn();
// LCD_U_DOff();
// LCD_L_ROn();
LCD_L_ROff();
LCD_RESETOn(); for(i=0;i<10000000;i++);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
// PFxx设置为LCD[1 00]
GPIO_PinAFConfig(GPIOF, GPIO_PinSource10, GPIO_AF_LTDC); //LCD_DE
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOF, &GPIO_InitStructure);
// PGxx设置为LCD[1 02]
GPIO_PinAFConfig(GPIOG, GPIO_PinSource7, GPIO_AF_LTDC); //LCD_CLK
GPIO_PinAFConfig(GPIOG, GPIO_PinSource6, GPIO_AF_LTDC); //LCD_R7
GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_LTDC); //LCD_B3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 |GPIO_Pin_7 | GPIO_Pin_11;
GPIO_Init(GPIOG, &GPIO_InitStructure);
// PHxx设置为LCD[0 07]
GPIO_PinAFConfig(GPIOH, GPIO_PinSource9, GPIO_AF_LTDC); //LCD_R3
GPIO_PinAFConfig(GPIOH, GPIO_PinSource10, GPIO_AF_LTDC); //LCD_R4
GPIO_PinAFConfig(GPIOH, GPIO_PinSource11, GPIO_AF_LTDC); //LCD_R5
GPIO_PinAFConfig(GPIOH, GPIO_PinSource12, GPIO_AF_LTDC); //LCD_R6
GPIO_PinAFConfig(GPIOH, GPIO_PinSource13, GPIO_AF_LTDC); //LCD_G2
GPIO_PinAFConfig(GPIOH, GPIO_PinSource14, GPIO_AF_LTDC); //LCD_G3
GPIO_PinAFConfig(GPIOH, GPIO_PinSource15, GPIO_AF_LTDC); //LCD_G4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11
| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14
| GPIO_Pin_15;
GPIO_Init(GPIOH, &GPIO_InitStructure);
// PIxx设置为LCD[0 07]
//7+2
GPIO_PinAFConfig(GPIOI, GPIO_PinSource0, GPIO_AF_LTDC); //LCD_G5
GPIO_PinAFConfig(GPIOI, GPIO_PinSource1, GPIO_AF_LTDC); //LCD_G6
GPIO_PinAFConfig(GPIOI, GPIO_PinSource2, GPIO_AF_LTDC); //LCD_G7
GPIO_PinAFConfig(GPIOI, GPIO_PinSource4, GPIO_AF_LTDC); //LCD_B4
GPIO_PinAFConfig(GPIOI, GPIO_PinSource5, GPIO_AF_LTDC); //LCD_B5
GPIO_PinAFConfig(GPIOI, GPIO_PinSource6, GPIO_AF_LTDC); //LCD_B6
GPIO_PinAFConfig(GPIOI, GPIO_PinSource7, GPIO_AF_LTDC); //LCD_B7
GPIO_PinAFConfig(GPIOI, GPIO_PinSource9, GPIO_AF_LTDC); //LCD_VSYNC
GPIO_PinAFConfig(GPIOI, GPIO_PinSource10, GPIO_AF_LTDC); //LCD_HSYNC
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2
| GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6
| GPIO_Pin_7 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init(GPIOI, &GPIO_InitStructure);
/* BL_EN pin configuration */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOH, &GPIO_InitStructure);
//_________________________________________________________________________________
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_8; //添加PH8!!!!!!
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_12 ; //添加PA!!!!!!
GPIO_Init(GPIOA, &GPIO_InitStructure);
LCD_RESETOff();
for(i=0;i<100000;i++);
LCD_RESETOn();
}
//-----------------------------------------------------------------------------
//函数:void LCD_GPIOInit(void)
//输入:void
//输出:void
//描述:LCD初始化
//-----------------------------------------------------------------------------
void LCD_Init(void)
{ //unsigned short *
LTDC_InitTypeDef LTDC_InitStruct;
LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
LTDC_Layer_TypeDef LTDC_Layerx;
/* IO口初始化 */
LCD_GPIOInit();
LCD_DisplayOff();
/* 使能LCD时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
/* 使能DMA时钟*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE);
/* 水平同步信号---低电平有效 */
LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;
/* 垂直同步信号---低电平有效 */
LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;
/* 数据使能信号---低电平有效 */
LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;
/* 像素时钟配置--- */
LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
/* LCD背光设置 */
LTDC_InitStruct.LTDC_BackgroundRedValue = 0;
LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;
LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
/*
****************************************************************************
*PLLSAI_VCO = HSE*PLLSAI_N / PLL_M = 8 * 192 / 8 = 192MHz
*PLLLCDCLK = PLLSAI_VCO / PLLSAI_R = 192 / 3 = 64 Mhz
*LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64 / 2 = 32 Mhz
****************************************************************************
*/
RCC_PLLSAIConfig(192, 7, 3);
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div2);//RCC_PLLSAIDivR_Div2
/* 使能PLLSAI时钟 */
RCC_PLLSAICmd(ENABLE);
/* 等待PLLSAI时钟 */
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET){}
/* */
/* Timing configuration */
/* Configure horizontal synchronization width */
LTDC_InitStruct.LTDC_HorizontalSync = 39;//40-1
/* Configure vertical synchronization height */
LTDC_InitStruct.LTDC_VerticalSync = 19;//20-1
/* Configure accumulated horizontal back porch */
LTDC_InitStruct.LTDC_AccumulatedHBP = (46-1);
/* Configure accumulated vertical back porch */
LTDC_InitStruct.LTDC_AccumulatedVBP = (23-1);
/* Configure accumulated active width */
LTDC_InitStruct.LTDC_AccumulatedActiveW = (46+LCD_PIXEL_WIDTH-1);
/* Configure accumulated active height */
LTDC_InitStruct.LTDC_AccumulatedActiveH = (23+LCD_PIXEL_HEIGHT-1);
/* Configure total width */
LTDC_InitStruct.LTDC_TotalWidth = (46+LCD_PIXEL_WIDTH+210-1);
/* Configure total height */
LTDC_InitStruct.LTDC_TotalHeigh = (23+LCD_PIXEL_HEIGHT+22-1);
LTDC_Init(<DC_InitStruct);
LTDC_Layer_InitStruct.LTDC_HorizontalStart = 46;
LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_PIXEL_WIDTH + 46 - 1);
LTDC_Layer_InitStruct.LTDC_VarticalStart = 23;
LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_PIXEL_HEIGHT +23 - 1);
/* Pixel Format configuration*/
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
/* Alpha constant (255 totally opaque) */
LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
/* Default Color configuration (configure A,R,G,B component values) */
LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;
LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;
LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;
LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;
/* Configure blending factors */
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
/* the length of one line of pixels in bytes + 3 then :
Line Lenth = Active high width x number of bytes per pixel + 3
Active high width = LCD_PIXEL_WIDTH
number of bytes per pixel = 2 (pixel_format : RGB565)
*/
LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_PIXEL_WIDTH * 2) + 3);
/* the pitch is the increment from the start of one line of pixels to the
start of the next line in bytes, then :
Pitch = Active high width x number of bytes per pixel
*/
LTDC_Layer_InitStruct.LTDC_CFBPitch = (LCD_PIXEL_WIDTH * 2);
/* configure the number of lines */
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_PIXEL_HEIGHT;
/* Input Address configuration */
LTDC_Layer_InitStruct.LTDC_CFBStartAdress =(uint32_t)gRam1;
LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct);
/* Configure Layer2 */
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (uint32_t)gRam2;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;
LTDC_LayerInit(LTDC_Layer2, <DC_Layer_InitStruct);
LTDC_ReloadConfig(LTDC_IMReload);
/* Enable foreground & background Layers */
LTDC_LayerCmd(LTDC_Layer1, ENABLE);
// LTDC_LayerCmd(LTDC_Layer2, ENABLE);//ENABLE
LTDC_ReloadConfig(LTDC_IMReload);
/* dithering activation */
LTDC_DitherCmd(ENABLE);
/* Enable the LTDC */
//LTDC_Cmd(ENABLE);
LCD_DisplayOn();
LCD_LTDC_Layer1_SetTransparency(255); //127
// LCD_LTDC_Layer2_SetTransparency(127); //127
}
//---------------------------------------------------
//函数:void LCD_DisplayOn(void)[PH06]
//描述:LCD显示开启,使能背光,使能电源
void LCD_DisplayOn(void)
{ GPIO_SetBits(GPIOH, GPIO_Pin_6);
LTDC_Cmd(ENABLE); /* display ON */
}
//函数:void LCD_DisplayOff(void)
//描述:LCD显示关闭,失能背光,失能电源
void LCD_DisplayOff(void)
{ GPIO_ResetBits(GPIOH, GPIO_Pin_6);
LTDC_Cmd(DISABLE);
}
//--------------------------------------------------- |
|