//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO,ENABLE);//ê1?üPORTB,D,E,Gò??°AFIO?′ó?1|?üê±?ó
/*Configure GPIO pin : PC5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PB0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* GPIO_InitStruct */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
/* GPIO_InitStruct */
GPIO_InitStruct.Pin = GPIO_PIN_7|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_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* GPIO_InitStruct */
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
readWriteTiming.AddressSetupTime = 0x01; //μ??·?¨á¢ê±??£¨ADDSET£??a2??HCLK 1/36M=27ns
readWriteTiming.AddressHoldTime = 0x00; //μ??·±£3?ê±??£¨ADDHLD£??£ê?A?′ó?μ?
readWriteTiming.DataSetupTime = 0x0f; // êy?Y±£′?ê±???a16??HCLK,òò?aòo?§?y?ˉICμ??áêy?Yμ?ê±oò£??ù?è2??üì??ì£?óè????1289?a??IC?£
readWriteTiming.BusTurnAroundDuration = 0x00;
readWriteTiming.CLKDivision = 0x00;
readWriteTiming.DataLatency = 0x00;
readWriteTiming.AccessMode = FSMC_ACCESS_MODE_A; //?£ê?A
writeTiming.AddressSetupTime = 0x02; //0x01 μ??·?¨á¢ê±??£¨ADDSET£??a1??HCLK
writeTiming.AddressHoldTime = 0x00; //μ??·±£3?ê±??£¨A
writeTiming.DataSetupTime = 0x05; ////0x03 êy?Y±£′?ê±???a4??HCLK
writeTiming.BusTurnAroundDuration = 0x00;
writeTiming.CLKDivision = 0x00;
writeTiming.DataLatency = 0x00;
writeTiming.AccessMode = FSMC_ACCESS_MODE_A; //?£ê?A
hsram2.Init.NSBank = FSMC_NORSRAM_BANK4;//? ?aà??ò??ê1ó?NE4 £?ò2?í??ó|BTCR[6],[7]?£
hsram2.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE; // 2??′ó?êy?Yμ??·
hsram2.Init.MemoryType =FSMC_MEMORY_TYPE_SRAM;// FSMC_MemoryType_SRAM;? //SRAM
hsram2.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;//′?′¢?÷êy?Y?í?è?a16bit
hsram2.Init.BurstAccessMode =FSMC_BURST_ACCESS_MODE_DISABLE;// FSMC_BurstAccessMode_Disable;
hsram2.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
hsram2.Init.AsynchronousWait=FSMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram2.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
hsram2.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
hsram2.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE; //? ′?′¢?÷D′ê1?ü
hsram2.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
hsram2.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE; // ?áD′ê1ó?2?í?μ?ê±Dò
hsram2.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
//FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming; //?áD′ê±Dò
//FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming;? //D′ê±Dò
if (HAL_SRAM_Init(&hsram2, &readWriteTiming, &writeTiming) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
__FSMC_NORSRAM_ENABLE(FSMC_NORSRAM_DEVICE,FSMC_NORSRAM_BANK4);
}
修改后的LCD初始化函數
void LCD_Init(void)
{
LCD_GPIOInit();
LCD_RESET();
//************* Start Initial Sequence **********//
LCD_WriteReg(0x00E5,0x78F0);
LCD_WriteReg(0x0001,0x0100);
LCD_WriteReg(0x0002,0x0700);
LCD_WriteReg(0x0003,0x1030);
LCD_WriteReg(0x0004,0x0000);
LCD_WriteReg(0x0008,0x0202);
LCD_WriteReg(0x0009,0x0000);
LCD_WriteReg(0x000A,0x0000);
LCD_WriteReg(0x000C,0x0000);
LCD_WriteReg(0x000D,0x0000);
LCD_WriteReg(0x000F,0x0000);
//power on sequence VGHVGL
LCD_WriteReg(0x0010,0x0000);
LCD_WriteReg(0x0011,0x0007);
LCD_WriteReg(0x0012,0x0000);
LCD_WriteReg(0x0013,0x0000);
LCD_WriteReg(0x0007,0x0000);
//vgh
LCD_WriteReg(0x0010,0x1690);
LCD_WriteReg(0x0011,0x0227);
//delay_ms(100);
//vregiout
LCD_WriteReg(0x0012,0x009D); //0x001b
//delay_ms(100);
//vom amplitude
LCD_WriteReg(0x0013,0x1900);
//delay_ms(100);
//vom H
LCD_WriteReg(0x0029,0x0025);
LCD_WriteReg(0x002B,0x000D);
//gamma
LCD_WriteReg(0x0030,0x0007);
LCD_WriteReg(0x0031,0x0303);
LCD_WriteReg(0x0032,0x0003);// 0006
LCD_WriteReg(0x0035,0x0206);
LCD_WriteReg(0x0036,0x0008);
LCD_WriteReg(0x0037,0x0406);
LCD_WriteReg(0x0038,0x0304);//0200
LCD_WriteReg(0x0039,0x0007);
LCD_WriteReg(0x003C,0x0602);// 0504
LCD_WriteReg(0x003D,0x0008);
//ram
LCD_WriteReg(0x0050,0x0000);
LCD_WriteReg(0x0051,0x00EF);
LCD_WriteReg(0x0052,0x0000);
LCD_WriteReg(0x0053,0x013F);
LCD_WriteReg(0x0060,0xA700);
LCD_WriteReg(0x0061,0x0001);
LCD_WriteReg(0x006A,0x0000);
//
LCD_WriteReg(0x0080,0x0000);
LCD_WriteReg(0x0081,0x0000);
LCD_WriteReg(0x0082,0x0000);
LCD_WriteReg(0x0083,0x0000);
LCD_WriteReg(0x0084,0x0000);
LCD_WriteReg(0x0085,0x0000);
//
LCD_WriteReg(0x0090,0x0010);
LCD_WriteReg(0x0092,0x0600);
LCD_WriteReg(0x0007,0x0133);
LCD_WriteReg(0x00,0x0022);//
LCD_SetParam();//éè??LCD2?êy
//LCD_LED=1;//μ?áá±31a
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
LCD_Clear(WHITE);
}
修改后在main函數中使用繪圖函數時要注釋掉原有的GPIO和FSMC初始化函數。
測試結果:
?
圖片發自簡書App
?
圖片發自簡書App
修改后即可以在STM32CubeMX中配置后就可以將之前修改好的文件直接添加到工程中使用,這樣即可在LCD上顯示其他功能的狀態信息。
評論
查看更多