利用cubemx生成的模拟IO代码驱动5110屏幕 速度很慢 ,20分钟才显示完整三个字符。找不到问题在哪。
代码如下。
5110.c文件
- #include "Header_File.h"
- /**********************************************************************
- *函数名称: OLED_WriteData(uint8_t dat)
- *函数功能: OLED些数据
- *入口参数: dat 数据
- *出口参数: void
- *示 例: OLED_WriteData(0x21)
- **********************************************************************/
- void OLED_WriteData( uint8_t dat)
- {
- uint8_t i;
- HAL_GPIO_WritePin(DC_GPIO_Port,DC_Pin,GPIO_PIN_SET);
- for(i=0;i<8;i++)
- {
- if((dat << i) & 0x80)
- {
- HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_SET);
- }
- else
- HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_RESET);
- HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_RESET);
- HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_SET);
- }
- }
- /**********************************************************************
- *函数名称: OLED_WriteCmd(uint8_t cmd)
- *函数功能: OLED写命令
- *入口参数: cmd 命令
- *出口参数: void
- *示 例: OLED_WriteCmd(0x21)
- **********************************************************************/
- void OLED_WriteCmd(uint8_t cmd)
- {
- uint8_t i;
- HAL_GPIO_WritePin(DC_GPIO_Port,DC_Pin,GPIO_PIN_RESET);
- for(i=0;i<8;i++)
- {
- if((cmd << i) & 0x80)
- {
- HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_SET);
- }
- else
- HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_RESET);
- HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_RESET);
- HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_SET);
- }
- }
- /**********************************************************************
- *函数名称: OLED_SetPos(uint8_t x, uint8_t y)
- *函数功能: OLED写坐标
- *入口参数: X 横坐标 Y纵坐标
- *出口参数: void
- *示 例: OLED_SetPos(2,1)
- **********************************************************************/
- void OLED_SetPos(uint8_t x, uint8_t y)
- {
- OLED_WriteCmd(0xb0+y);
- OLED_WriteCmd(((x&0xf0)>>4)|0x10);
- OLED_WriteCmd((x&0x0f)|0x01);
- }
- /**********************************************************************
- *函数名称: void OLED_Fill(uint8_t bmp_dat)
- *函数功能: 满屏写数据
- *入口参数: bmp_dat数据
- *出口参数: void
- *示 例: OLED_Fill(0) 清屏函数
- **********************************************************************/
- void OLED_Fill(uint8_t bmp_dat)
- {
- uint8_t y,x;
- for(y=0;y<8;y++)
- {
- OLED_WriteCmd(0xb0+y);
- OLED_WriteCmd(0x01);
- OLED_WriteCmd(0x10);
- for(x=0;x<128;x++)
- OLED_WriteData(bmp_dat);
- }
- }
- /**********************************************************************
- *函数名称: OLED_Init(void)
- *函数功能: OLED初始化函数
- *入口参数: void
- *出口参数: void
- *示 例: OLED_Init( )
- **********************************************************************/
- void OLED_Init(void)
- {
- HAL_GPIO_WritePin(RES_GPIO_Port,RES_Pin,GPIO_PIN_SET);
- HAL_Delay(100);
- HAL_GPIO_WritePin(RES_GPIO_Port,RES_Pin,GPIO_PIN_RESET);
- HAL_Delay(100);
- HAL_GPIO_WritePin(RES_GPIO_Port,RES_Pin,GPIO_PIN_SET);
- HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
- HAL_Delay(500);
- HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
- OLED_WriteCmd(0xae);//--turn off oled panel
- OLED_WriteCmd(0x00);//---set low column address
- OLED_WriteCmd(0x10);//---set high column address
- OLED_WriteCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
- OLED_WriteCmd(0x81);//--set contrast control register
- OLED_WriteCmd(0xcf); // Set SEG Output Current Brightness
- OLED_WriteCmd(0xa1);//--Set SEG/Column Mapping 0xa0???? 0xa1??
- OLED_WriteCmd(0xc8);//Set COM/Row Scan Direction 0xc0???? 0xc8??
- OLED_WriteCmd(0xa6);//--set normal display
- OLED_WriteCmd(0xa8);//--set multiplex ratio(1 to 64)
- OLED_WriteCmd(0x3f);//--1/64 duty
- OLED_WriteCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
- OLED_WriteCmd(0x00);//-not offset
- OLED_WriteCmd(0xd5);//--set display clock divide ratio/oscillator frequency
- OLED_WriteCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
- OLED_WriteCmd(0xd9);//--set pre-charge period
- OLED_WriteCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
- OLED_WriteCmd(0xda);//--set com pins hardware configuration
- OLED_WriteCmd(0x12);
- OLED_WriteCmd(0xdb);//--set vcomh
- OLED_WriteCmd(0x40);//Set VCOM Deselect Level
- OLED_WriteCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
- OLED_WriteCmd(0x02);//
- OLED_WriteCmd(0x8d);//--set Charge Pump enable/disable
- OLED_WriteCmd(0x14);//--set(0x10) disable
- OLED_WriteCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
- OLED_WriteCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
- OLED_WriteCmd(0xaf);//--turn on oled panel
- OLED_Fill(0x00); //清屏
- OLED_SetPos(0,0);
- }
- /**********************************************************************
- *函数名称: LCD_PrintfChinese16x16( uint8_t IndexY , uint8_t IndexX ,const uint8_t pString[] ,uint8_t mode )
- *函数功能: 显示16x16字符
- *入口参数: IndexX页地址 IndexY列地址 pString[]显示的字符 mode显示模式
- *出口参数: void
- *示 例: LCD_PrintfChinese16x16( 0 , 0 ,"显示16x16字符" ,normal )
- **********************************************************************/
- void LCD_PrintfChinese16x16( uint8_t IndexY , uint8_t IndexX ,const uint8_t pString[] ,uint8_t mode )
- {
-
- uint8_t temp1, temp2,i;
- uint16_t Code_Address;
-
- IndexY <<= 1;
-
- temp1 = 0;
-
- while(pString[temp1] != ' ')
- {
- temp2 = 0;
- Code_Address = 1;
-
- while( INDEX_CHINESE_16x16[temp2] > 127 )
- {//扫描字库中的文字
-
- if(INDEX_CHINESE_16x16[temp2] == pString[temp1])
- {
-
- if(INDEX_CHINESE_16x16[temp2 + 1] == pString[temp1 + 1])
- {
-
- Code_Address = temp2 * 16;
- break;
- }
- }
- temp2 += 2; //每个字占2个字符
- }
-
- if(Code_Address != 1)
- {//显示上半部汉字
- OLED_SetPos(IndexX, IndexY);
- for(i = 0; i < 16; i++)
- {
-
- if(mode==0)
- {
- OLED_WriteData(CODETAB_CHINESE_16x16[Code_Address]);
- }
- else
- {
- OLED_WriteData(~CODETAB_CHINESE_16x16[Code_Address]);
- }
-
- Code_Address++;
- }
- //显示下半部分
- OLED_SetPos(IndexX,IndexY + 1);
- for(i = 0;i < 16;i++)
- {
-
- if(mode==0)
- {
- OLED_WriteData(CODETAB_CHINESE_16x16[Code_Address]);
- }
- else
- {
- OLED_WriteData(~CODETAB_CHINESE_16x16[Code_Address]);
- }
- Code_Address++;
- }
-
- temp1 += 2;
-
- }
- else
- { //显示空白部分
-
- OLED_SetPos(IndexX, IndexY);
- for(i = 0;i < 16;i++)
- {
-
- OLED_WriteData(0);
- }
-
- OLED_SetPos(IndexX,IndexY + 1);
- for(i = 0;i < 16;i++)
- {
-
- OLED_WriteData(0);
- }
-
- temp1+=1;
- }
-
- IndexX += 16;//更新下一个字符
- }
- return;
- }
- /**********************************************************************
- *函数名称: LCD_PrintfChineseMix16x16( uint8_t IndexX , uint8_t IndexY , const uint8_t pString[] , uint8_t mode)
- *函数功能: 显示16x16字符、汉字
- *入口参数: IndexX页地址 IndexY列地址 pString[]显示的字符 mode显示模式
- *出口参数: void
- *示 例: LCD_PrintfChineseMix16x16( 0 , 0 ,"显示16x16字符ABC" ,abnormal )
- **********************************************************************/
- void LCD_PrintfChineseMix16x16( uint8_t IndexX , uint8_t IndexY , const uint8_t pString[] , uint8_t mode)
- {
- uint8_t tempStr[3];
- uint8_t i = 0;
-
- while(pString[i] != ' ')
- {
- if(pString[i] > 127)
- {
- tempStr[0] = pString[i];
- tempStr[1] = pString[i + 1];
- tempStr[2] = ' '; //空格
- LCD_PrintfChinese16x16(IndexX , IndexY , tempStr , mode);
- IndexY += 16;
- i += 2;
- }
- else
- {
- LCD_PrintfChar8x16(IndexY, IndexX, pString[i] , mode); //显示字母
- IndexY += 8;
- i += 1;
- }
- }
-
- }
- /**********************************************************************
- *函数名称: LCD_PrintfChar8x16( uint8_t IndexX , uint8_t IndexY , uint8_t pData , uint8_t mode)
- *函数功能: 显示8x16字幕
- *入口参数: IndexX页地址 IndexY列地址 pData显示的字符 mode显示模式
- *出口参数: void
- *示例 :LCD_PrintfChar8x16( 0 , 0 ,"ABCDE" ,abnormal )
- **********************************************************************/
- void LCD_PrintfChar8x16( uint8_t IndexX , uint8_t IndexY , uint8_t pData , uint8_t mode)
- {
-
- uint8_t i;
-
- IndexY <<= 1;
-
- if(IndexX > 120)
- {
- IndexX = 0;
- IndexY+=2;
- }
- pData = (pData-32);
-
- OLED_SetPos(IndexX, IndexY);
- for(i = 0; i < 8; i++)
- {
- if(mode==0)
- {
- OLED_WriteData((Tab_Ascii_8x16[(pData << 4) + i]));
- }
- else
- {
- OLED_WriteData((~Tab_Ascii_8x16[(pData << 4) + i]));
- }
- }
- OLED_SetPos(IndexX, IndexY+1);
- for(i = 0; i < 8; i++)
- {
- if(mode==0)
- {
- OLED_WriteData((Tab_Ascii_8x16[(pData << 4) + i + 8 ]));
- }
- else
- {
- OLED_WriteData((~Tab_Ascii_8x16[(pData << 4) + i + 8 ]));
- }
- }
- }
复制代码下面是main.c
- /**
- ******************************************************************************
- * File Name : main.c
- * Description : Main program body
- ******************************************************************************
- *
- * COPYRIGHT(c) 2016 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f1xx_hal.h"
- /* USER CODE BEGIN Includes */
- #include "Header_File.h"
- /* USER CODE END Includes */
- /* Private variables ---------------------------------------------------------*/
- UART_HandleTypeDef huart1;
- /* USER CODE BEGIN PV */
- /* Private variables ---------------------------------------------------------*/
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_USART1_UART_Init(void);
- /* USER CODE BEGIN PFP */
- /* Private function prototypes -----------------------------------------------*/
- /* USER CODE END PFP */
- /* USER CODE BEGIN 0 */
- /* USER CODE END 0 */
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MCU Configuration----------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* Configure the system clock */
- SystemClock_Config();
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_USART1_UART_Init();
- /* USER CODE BEGIN 2 */
- OLED_Init();
- HAL_Delay(1000);
- LCD_PrintfChineseMix16x16(2,3,"ϵBCDEFGHIJKLMN",0);
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- // HAL_Delay(1000);
- for(uint8_t i=0;i<0xf;i++)
- {
- uint32_t j=100000;
- while(j--);
- }
- HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
- // LCD_clear();
- }
- /* USER CODE END 3 */
- }
- /** System Clock Configuration
- */
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
- HAL_RCC_OscConfig(&RCC_OscInitStruct);
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
- HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/8000);
- HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK_DIV8);
- /* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
- }
- /* USART1 init function */
- void MX_USART1_UART_Init(void)
- {
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 115200;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_TX_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- HAL_UART_Init(&huart1);
- }
- /** Configure pins as
- * Analog
- * Input
- * Output
- * EVENT_OUT
- * EXTI
- */
- void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOE, RES_Pin|DI_Pin|DO_Pin|CS_Pin
- |DC_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pins : RES_Pin DI_Pin DO_Pin CS_Pin
- DC_Pin */
- GPIO_InitStruct.Pin = RES_Pin|DI_Pin|DO_Pin|CS_Pin
- |DC_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
- /*Configure GPIO pin : LED_Pin */
- GPIO_InitStruct.Pin = LED_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
- }
- /* USER CODE BEGIN 4 */
- /* USER CODE END 4 */
- #ifdef USE_FULL_ASSERT
- /**
- * [url=home.php?mod=space&uid=159083]@brief[/url] Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d
", file, line) */
- /* USER CODE END 6 */
- }
- #endif
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码哪位大侠能看出问题在哪
此帖出自
小平头技术问答
一周热门 更多>