初级会员
- 积分
- 62
- 金钱
- 62
- 注册时间
- 2012-10-11
- 在线时间
- 8 小时
|
发表于 2015-11-12 20:50:48
|
显示全部楼层
回复【5楼】tony129:
---------------------------------
给个我用的代码你自己对照吧。。。。
void LCD_AF_GPIOConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*
****************************************************************************
*R0 -->  H2 | G0 -->  E5 | B0 -->  E4 | VSYNC --> I10
*R1 -->  H3 | G1 -->  E6 | B1 --> G12 | HSYNC --> I9
*R2 -->  H8 | G2 --> H13 | B2 --> PG10 | DE --> PF10
*R3 --> PH9 | G3 --> PH14 | B3 --> PG11 | CLK --> PG7
*R4 --> PH10 | G4 --> PH15 | B4 --> PI4 | BL_EN --> PD13
*R5 --> PH11 | G5 --> PI0 | B5 --> PI5 |
*R6 --> PH12 | G6 --> PI1 | B6 --> PI6 | G3->PH14/PE11
*R7 --> PG6 | G7 --> PI2 | B7 --> PI7 | B3->PG11/PD10 B2->PD6
****************************************************************************
*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG
| RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, ENABLE);
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;
GPIO_PinAFConfig(GPIOG, GPIO_PinSource4, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource5, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource6, GPIO_AF_LTDC);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 ;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource10, GPIO_AF_LTDC);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource6, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource7, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource10, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource12, GPIO_AF_LTDC);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 |
GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource2, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource3, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource8, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource9, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource10, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource11, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource12, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource13, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource14, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource15, GPIO_AF_LTDC);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_8
| 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);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource0, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource1, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource2, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource4, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource5, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource6, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource7, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource9, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource10, GPIO_AF_LTDC);
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);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/**
* @brief LCD configuration.
* @note This function Configure tha LTDC peripheral:
* 1) Configure the Pixel Clock for the LCD
* 2) Configure the LTDC Timing and Polarity
* 3) Configure the LTDC Layer 1:
* - The frame buffer is located at SDRAM buffer
* - The Layer size configuration: 240x320
* 4) Configure the Color Keying for Layer 1.
* @retval
* None
*/
void LCD_Init(void)
{
LTDC_InitTypeDef LTDC_InitStruct;
LCD_DisplayOn();
/* Enable the LTDC Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
/* Enable the DMA2D Clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE);
/* Configure the LCD Control pins */
LCD_AF_GPIOConfig();
/* Configure the FMC Parallel interface: SDRAM is used as Frame Buffer for LCD */
// SDRAM_Init();
/* Enable Pixel Clock --------------------------------------------------------*/
/* Configure PLLSAI prescalers for LCD */
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
/* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */
/* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */
/* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */
RCC_PLLSAIConfig(192, 7, 3);
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4);
/* Enable PLLSAI Clock */
RCC_PLLSAICmd(ENABLE);
/* Wait for PLLSAI activation */
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
{
}
/* LTDC Initialization -------------------------------------------------------*/
/* Initialize the horizontal synchronization polarity as active low*/
LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;
/* Initialize the vertical synchronization polarity as active low */
LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;
/* Initialize the data enable polarity as active low */
LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;
/* Initialize the pixel clock polarity as input pixel clock */
LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
/* Timing configuration */
/* Configure horizontal synchronization width */
LTDC_InitStruct.LTDC_HorizontalSync = 1;
/* Configure vertical synchronization height */
LTDC_InitStruct.LTDC_VerticalSync = 1;
/* Configure accumulated horizontal back porch */
LTDC_InitStruct.LTDC_AccumulatedHBP = 46;
/* Configure accumulated vertical back porch */
LTDC_InitStruct.LTDC_AccumulatedVBP = 23;
/* Configure accumulated active width */
LTDC_InitStruct.LTDC_AccumulatedActiveW = 800+46;
/* Configure accumulated active height */
LTDC_InitStruct.LTDC_AccumulatedActiveH = 480+23;
/* Configure total width */
LTDC_InitStruct.LTDC_TotalWidth = 800+46+210;
/* Configure total height */
LTDC_InitStruct.LTDC_TotalHeigh = 480+23+22;
LTDC_Init(<DC_InitStruct);
/* Configure R,G,B component values for LCD background color */
LTDC_InitStruct.LTDC_BackgroundRedValue = 0;
LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;
LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
LTDC_Init(<DC_InitStruct);
/* LTDC initialization end ---------------------------------------------------*/
LCD_LayerInit();
}
void LCD_LayerInit(void)
{
LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
LTDC_Layer_InitStruct.LTDC_HorizontalStart = 46+1;
LTDC_Layer_InitStruct.LTDC_HorizontalStop = (800 + 46);
LTDC_Layer_InitStruct.LTDC_VerticalStart = 23+1;
LTDC_Layer_InitStruct.LTDC_VerticalStop = (480 + 23);
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_ARGB8888;
LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;
LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;
LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;
LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER;
LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((800 * 4))+3;
LTDC_Layer_InitStruct.LTDC_CFBPitch = (800 * 4);
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 480;
LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct);
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER+BUFFER_OFFSET;
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);
LTDC_LayerCmd(LTDC_Layer1, ENABLE);
LTDC_LayerCmd(LTDC_Layer2, ENABLE);
LTDC_ReloadConfig(LTDC_IMReload);
LTDC_DitherCmd(ENABLE);
} |
|