你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

cubemx生成的F103代码驱动5110屏幕 速度很慢

[复制链接]
wanyisq 提问时间:2016-5-23 19:14 /
本帖最后由 wanyisq 于 2016-5-23 19:22 编辑

我是用cubemx初始化的IO管脚,模拟方式驱动5110屏幕。写了三个字,20分钟才显示完整。不知道什么原因。
配置如下:8M的外部晶振

复制代码
main.c文件
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f1xx_hal.h"

  3. /* USER CODE BEGIN Includes */
  4. #include "Header_File.h"
  5. /* USER CODE END Includes */

  6. /* Private variables ---------------------------------------------------------*/
  7. UART_HandleTypeDef huart1;

  8. /* USER CODE BEGIN PV */
  9. /* Private variables ---------------------------------------------------------*/

  10. /* USER CODE END PV */

  11. /* Private function prototypes -----------------------------------------------*/
  12. void SystemClock_Config(void);
  13. static void MX_GPIO_Init(void);
  14. static void MX_USART1_UART_Init(void);

  15. /* USER CODE BEGIN PFP */
  16. /* Private function prototypes -----------------------------------------------*/

  17. /* USER CODE END PFP */

  18. /* USER CODE BEGIN 0 */

  19. /* USER CODE END 0 */

  20. int main(void)
  21. {

  22.   /* USER CODE BEGIN 1 */

  23.   /* USER CODE END 1 */

  24.   /* MCU Configuration----------------------------------------------------------*/

  25.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  26.   HAL_Init();

  27.   /* Configure the system clock */
  28.   SystemClock_Config();

  29.   /* Initialize all configured peripherals */
  30.   MX_GPIO_Init();
  31.   MX_USART1_UART_Init();

  32.   /* USER CODE BEGIN 2 */
  33.         OLED_Init();
  34.         HAL_Delay(1000);
  35.         LCD_PrintfChineseMix16x16(2,3,"ϵBCDEFGHIJKLMN",0);
  36.   /* USER CODE END 2 */

  37.   /* Infinite loop */
  38.   /* USER CODE BEGIN WHILE */
  39.   while (1)
  40.   {
  41.   /* USER CODE END WHILE */

  42.   /* USER CODE BEGIN 3 */
  43. //                HAL_Delay(1000);
  44.                 for(uint8_t i=0;i<0xf;i++)
  45.                 {
  46.                         uint32_t j=100000;
  47.                         while(j--);
  48.                 }

  49.                 HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
  50. //                LCD_clear();
  51.   }
  52.   /* USER CODE END 3 */

  53. }

  54. /** System Clock Configuration
  55. */
  56. void SystemClock_Config(void)
  57. {

  58.   RCC_OscInitTypeDef RCC_OscInitStruct;
  59.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  60.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  61.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  62.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  63.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  64.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  65.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  66.   HAL_RCC_OscConfig(&RCC_OscInitStruct);

  67.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  68.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  69.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  70.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  71.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  72.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  73.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);

  74.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/8000);

  75.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK_DIV8);

  76.   /* SysTick_IRQn interrupt configuration */
  77.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  78. }

  79. /* USART1 init function */
  80. void MX_USART1_UART_Init(void)
  81. {

  82.   huart1.Instance = USART1;
  83.   huart1.Init.BaudRate = 115200;
  84.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  85.   huart1.Init.StopBits = UART_STOPBITS_1;
  86.   huart1.Init.Parity = UART_PARITY_NONE;
  87.   huart1.Init.Mode = UART_MODE_TX_RX;
  88.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  89.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  90.   HAL_UART_Init(&huart1);

  91. }

  92. /** Configure pins as
  93.         * Analog
  94.         * Input
  95.         * Output
  96.         * EVENT_OUT
  97.         * EXTI
  98. */
  99. void MX_GPIO_Init(void)
  100. {

  101.   GPIO_InitTypeDef GPIO_InitStruct;

  102.   /* GPIO Ports Clock Enable */
  103.   __HAL_RCC_GPIOE_CLK_ENABLE();
  104.   __HAL_RCC_GPIOD_CLK_ENABLE();
  105.   __HAL_RCC_GPIOA_CLK_ENABLE();

  106.   /*Configure GPIO pin Output Level */
  107.   HAL_GPIO_WritePin(GPIOE, RES_Pin|DI_Pin|DO_Pin|CS_Pin
  108.                           |DC_Pin, GPIO_PIN_RESET);

  109.   /*Configure GPIO pin Output Level */
  110.   HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

  111.   /*Configure GPIO pins : RES_Pin DI_Pin DO_Pin CS_Pin
  112.                            DC_Pin */
  113.   GPIO_InitStruct.Pin = RES_Pin|DI_Pin|DO_Pin|CS_Pin
  114.                           |DC_Pin;
  115.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  116.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  117.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  118.   /*Configure GPIO pin : LED_Pin */
  119.   GPIO_InitStruct.Pin = LED_Pin;
  120.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  121.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  122.   HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);

  123. }

  124. /* USER CODE BEGIN 4 */

  125. /* USER CODE END 4 */

  126. #ifdef USE_FULL_ASSERT

  127. /**
  128.    * @brief Reports the name of the source file and the source line number
  129.    * where the assert_param error has occurred.
  130.    * @param file: pointer to the source file name
  131.    * @param line: assert_param error line source number
  132.    * @retval None
  133.    */
  134. void assert_failed(uint8_t* file, uint32_t line)
  135. {
  136.   /* USER CODE BEGIN 6 */
  137.   /* User can add his own implementation to report the file name and line number,
  138.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  139.   /* USER CODE END 6 */

  140. }

  141. #endif

  142. /**
  143.   * @}
  144.   */

  145. /**
  146.   * @}
  147. */

  148. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码
5110.c文件
  1. #include "Header_File.h"


  2. /**********************************************************************
  3. *函数名称: OLED_WriteData(uint8_t dat)
  4. *函数功能: OLED些数据
  5. *入口参数: dat 数据   
  6. *出口参数: void
  7. *示    例: OLED_WriteData(0x21)
  8. **********************************************************************/
  9. void OLED_WriteData( uint8_t dat)        
  10. {
  11.         uint8_t i;
  12.   HAL_GPIO_WritePin(DC_GPIO_Port,DC_Pin,GPIO_PIN_SET);
  13.         for(i=0;i<8;i++)
  14.         {
  15.                 if((dat << i) & 0x80)
  16.                 {
  17.                         HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_SET);
  18.                 }
  19.                 else
  20.                         HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_RESET);
  21.                 HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_RESET);
  22.                 HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_SET);
  23.         }
  24. }


  25. /**********************************************************************
  26. *函数名称: OLED_WriteCmd(uint8_t cmd)
  27. *函数功能: OLED写命令
  28. *入口参数: cmd 命令   
  29. *出口参数: void
  30. *示    例: OLED_WriteCmd(0x21)
  31. **********************************************************************/
  32. void OLED_WriteCmd(uint8_t cmd)        
  33. {
  34.         uint8_t i;
  35.   HAL_GPIO_WritePin(DC_GPIO_Port,DC_Pin,GPIO_PIN_RESET);
  36.         for(i=0;i<8;i++)
  37.         {
  38.                 if((cmd << i) & 0x80)
  39.                 {
  40.                         HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_SET);
  41.                 }
  42.                 else
  43.                         HAL_GPIO_WritePin(DI_GPIO_Port,DI_Pin,GPIO_PIN_RESET);
  44.                 HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_RESET);
  45.                 HAL_GPIO_WritePin(DO_GPIO_Port,DO_Pin,GPIO_PIN_SET);
  46.         }
  47. }


  48. /**********************************************************************
  49. *函数名称: OLED_SetPos(uint8_t x, uint8_t y)
  50. *函数功能: OLED写坐标
  51. *入口参数: X 横坐标  Y纵坐标  
  52. *出口参数: void
  53. *示    例: OLED_SetPos(2,1)
  54. **********************************************************************/
  55. void OLED_SetPos(uint8_t x, uint8_t y)
  56. {
  57.   OLED_WriteCmd(0xb0+y);
  58.   OLED_WriteCmd(((x&0xf0)>>4)|0x10);
  59.   OLED_WriteCmd((x&0x0f)|0x01);
  60. }


  61. /**********************************************************************
  62. *函数名称: void OLED_Fill(uint8_t bmp_dat)
  63. *函数功能: 满屏写数据
  64. *入口参数: bmp_dat数据
  65. *出口参数: void
  66. *示    例: OLED_Fill(0) 清屏函数
  67. **********************************************************************/
  68. void OLED_Fill(uint8_t bmp_dat)
  69. {
  70.   uint8_t y,x;
  71.   for(y=0;y<8;y++)
  72.   {
  73.     OLED_WriteCmd(0xb0+y);
  74.     OLED_WriteCmd(0x01);
  75.     OLED_WriteCmd(0x10);
  76.     for(x=0;x<128;x++)
  77.     OLED_WriteData(bmp_dat);
  78.   }
  79. }


  80. /**********************************************************************
  81. *函数名称: OLED_Init(void)
  82. *函数功能: OLED初始化函数
  83. *入口参数: void
  84. *出口参数: void
  85. *示    例: OLED_Init( )
  86. **********************************************************************/
  87. void OLED_Init(void)     
  88. {
  89.         HAL_GPIO_WritePin(RES_GPIO_Port,RES_Pin,GPIO_PIN_SET);
  90.   HAL_Delay(100);
  91.   HAL_GPIO_WritePin(RES_GPIO_Port,RES_Pin,GPIO_PIN_RESET);
  92.   HAL_Delay(100);
  93.   HAL_GPIO_WritePin(RES_GPIO_Port,RES_Pin,GPIO_PIN_SET);
  94.   HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
  95.   HAL_Delay(500);
  96.   HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
  97.   OLED_WriteCmd(0xae);//--turn off oled panel
  98.   OLED_WriteCmd(0x00);//---set low column address
  99.   OLED_WriteCmd(0x10);//---set high column address
  100.   OLED_WriteCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  101.   OLED_WriteCmd(0x81);//--set contrast control register
  102.   OLED_WriteCmd(0xcf); // Set SEG Output Current Brightness
  103.   OLED_WriteCmd(0xa1);//--Set SEG/Column Mapping     0xa0???? 0xa1??
  104.   OLED_WriteCmd(0xc8);//Set COM/Row Scan Direction   0xc0???? 0xc8??
  105.   OLED_WriteCmd(0xa6);//--set normal display
  106.   OLED_WriteCmd(0xa8);//--set multiplex ratio(1 to 64)
  107.   OLED_WriteCmd(0x3f);//--1/64 duty
  108.   OLED_WriteCmd(0xd3);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  109.   OLED_WriteCmd(0x00);//-not offset
  110.   OLED_WriteCmd(0xd5);//--set display clock divide ratio/oscillator frequency
  111.   OLED_WriteCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
  112.   OLED_WriteCmd(0xd9);//--set pre-charge period
  113.   OLED_WriteCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  114.   OLED_WriteCmd(0xda);//--set com pins hardware configuration
  115.   OLED_WriteCmd(0x12);
  116.   OLED_WriteCmd(0xdb);//--set vcomh
  117.   OLED_WriteCmd(0x40);//Set VCOM Deselect Level
  118.   OLED_WriteCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
  119.   OLED_WriteCmd(0x02);//
  120.   OLED_WriteCmd(0x8d);//--set Charge Pump enable/disable
  121.   OLED_WriteCmd(0x14);//--set(0x10) disable
  122.   OLED_WriteCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
  123.   OLED_WriteCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
  124.   OLED_WriteCmd(0xaf);//--turn on oled panel
  125.   OLED_Fill(0x00);    //清屏
  126.   OLED_SetPos(0,0);
  127. }


  128. /**********************************************************************
  129. *函数名称: LCD_PrintfChinese16x16( uint8_t IndexY , uint8_t IndexX ,const  uint8_t pString[] ,uint8_t mode )
  130. *函数功能: 显示16x16字符
  131. *入口参数: IndexX页地址   IndexY列地址 pString[]显示的字符  mode显示模式
  132. *出口参数: void
  133. *示    例: LCD_PrintfChinese16x16( 0 , 0 ,"显示16x16字符" ,normal )
  134. **********************************************************************/
  135. void  LCD_PrintfChinese16x16( uint8_t IndexY , uint8_t IndexX ,const  uint8_t pString[] ,uint8_t mode )
  136. {
  137.    
  138.     uint8_t temp1, temp2,i;
  139.     uint16_t Code_Address;
  140.    
  141.     IndexY <<= 1;
  142.    
  143.     temp1 = 0;
  144.    
  145.     while(pString[temp1] != '\0')
  146.     {
  147.         temp2 = 0;
  148.         Code_Address = 1;
  149.         
  150.         while( INDEX_CHINESE_16x16[temp2] > 127 )
  151.         {//扫描字库中的文字
  152.         
  153.             if(INDEX_CHINESE_16x16[temp2] == pString[temp1])
  154.             {
  155.             
  156.                 if(INDEX_CHINESE_16x16[temp2 + 1] == pString[temp1 + 1])
  157.                 {
  158.                
  159.                     Code_Address = temp2 * 16;
  160.                     break;
  161.                 }
  162.             }
  163.             temp2 += 2; //每个字占2个字符         
  164.         }
  165.                
  166.         if(Code_Address != 1)
  167.         {//显示上半部汉字
  168.             OLED_SetPos(IndexX, IndexY);
  169.             for(i = 0; i < 16; i++)
  170.             {               
  171.             
  172.               if(mode==0)
  173.               {
  174.                 OLED_WriteData(CODETAB_CHINESE_16x16[Code_Address]);
  175.               }
  176.               else
  177.               {
  178.                 OLED_WriteData(~CODETAB_CHINESE_16x16[Code_Address]);
  179.               }
  180.                   
  181.                 Code_Address++;
  182.             }
  183.             //显示下半部分
  184.             OLED_SetPos(IndexX,IndexY + 1);
  185.             for(i = 0;i < 16;i++)
  186.             {         
  187.             
  188.               if(mode==0)
  189.               {
  190.                 OLED_WriteData(CODETAB_CHINESE_16x16[Code_Address]);
  191.               }
  192.               else
  193.               {
  194.                 OLED_WriteData(~CODETAB_CHINESE_16x16[Code_Address]);
  195.               }
  196.                 Code_Address++;
  197.             }
  198.             
  199.             temp1 += 2;        
  200.         
  201.         }
  202.         else
  203.         {              //显示空白部分      
  204.         
  205.             OLED_SetPos(IndexX, IndexY);
  206.             for(i = 0;i < 16;i++)
  207.             {
  208.             
  209.                 OLED_WriteData(0);
  210.             }
  211.             
  212.             OLED_SetPos(IndexX,IndexY + 1);
  213.             for(i = 0;i < 16;i++)
  214.             {
  215.                        
  216.                 OLED_WriteData(0);   
  217.             }
  218.             
  219.             temp1+=1;
  220.         }
  221.         
  222.         IndexX += 16;//更新下一个字符
  223.     }
  224.     return;  
  225. }


  226. /**********************************************************************
  227. *函数名称: LCD_PrintfChineseMix16x16( uint8_t IndexX , uint8_t IndexY , const uint8_t pString[] , uint8_t mode)
  228. *函数功能: 显示16x16字符、汉字
  229. *入口参数: IndexX页地址   IndexY列地址 pString[]显示的字符  mode显示模式
  230. *出口参数: void
  231. *示    例: LCD_PrintfChineseMix16x16( 0 , 0 ,"显示16x16字符ABC" ,abnormal )
  232. **********************************************************************/
  233. void LCD_PrintfChineseMix16x16( uint8_t IndexX , uint8_t IndexY , const uint8_t pString[] , uint8_t mode)
  234. {
  235.     uint8_t tempStr[3];
  236.     uint8_t i = 0;   
  237.    
  238.     while(pString[i] != '\0')
  239.     {
  240.         if(pString[i] > 127)
  241.         {
  242.             tempStr[0] = pString[i];
  243.             tempStr[1] = pString[i + 1];
  244.             tempStr[2] = '\0';          //空格
  245.             LCD_PrintfChinese16x16(IndexX , IndexY , tempStr , mode);
  246.             IndexY += 16;
  247.             i += 2;
  248.         }
  249.         else
  250.         {
  251.             LCD_PrintfChar8x16(IndexY, IndexX, pString[i] , mode);  //显示字母
  252.             IndexY += 8;
  253.             i += 1;
  254.         }
  255.     }
  256.   
  257. }


  258. /**********************************************************************
  259. *函数名称: LCD_PrintfChar8x16( uint8_t IndexX , uint8_t IndexY , uint8_t pData , uint8_t mode)
  260. *函数功能: 显示8x16字幕
  261. *入口参数: IndexX页地址   IndexY列地址 pData显示的字符  mode显示模式
  262. *出口参数: void
  263. *示例    :LCD_PrintfChar8x16( 0 , 0 ,"ABCDE" ,abnormal )
  264. **********************************************************************/
  265. void LCD_PrintfChar8x16( uint8_t IndexX , uint8_t IndexY , uint8_t pData , uint8_t mode)
  266. {
  267.   
  268.   uint8_t i;
  269.   
  270.   IndexY <<= 1;
  271.   
  272.     if(IndexX > 120)
  273.     {
  274.         IndexX = 0;
  275.         IndexY+=2;
  276.     }
  277.     pData = (pData-32);
  278.    
  279.     OLED_SetPos(IndexX, IndexY);
  280.     for(i = 0; i < 8; i++)
  281.     {     
  282.       if(mode==0)
  283.       {
  284.         OLED_WriteData((Tab_Ascii_8x16[(pData << 4) + i]));
  285.       }
  286.       else
  287.       {
  288.         OLED_WriteData((~Tab_Ascii_8x16[(pData << 4) + i]));
  289.       }
  290.     }
  291.     OLED_SetPos(IndexX, IndexY+1);
  292.     for(i = 0; i < 8; i++)
  293.     {     
  294.       if(mode==0)
  295.       {
  296.         OLED_WriteData((Tab_Ascii_8x16[(pData << 4) + i + 8 ]));
  297.       }
  298.       else
  299.       {
  300.         OLED_WriteData((~Tab_Ascii_8x16[(pData << 4) + i + 8 ]));
  301.       }
  302.     }
  303. }
复制代码

收藏 评论8 发布时间:2016-5-23 19:14

举报

8个回答
suoma 回答时间:2016-5-23 23:24:25
时钟配置有关系吧?
zcl201207 回答时间:2016-5-23 23:46:28
楼主真有耐心,20分钟观察显示3个字
jinglixixi 回答时间:2016-5-24 08:24:29
20分钟的效果真的容易被漏掉,精神可贵。
wanyisq 回答时间:2016-5-24 08:43:00
suoma 发表于 2016-5-23 23:24
时钟配置有关系吧?

外部8M晶振,时钟倍频到72M了  最快了
wanyisq 回答时间:2016-5-24 08:43:46
zcl201207 发表于 2016-5-23 23:46
楼主真有耐心,20分钟观察显示3个字

因为当时正好叫了份外卖,一边吃一边看着它
wanyisq 回答时间:2016-5-24 08:44:19
jinglixixi 发表于 2016-5-24 08:24
20分钟的效果真的容易被漏掉,精神可贵。

哈哈哈哈 没有一直盯着,隔几分钟看一眼
jinglixixi 回答时间:2016-5-24 09:40:08
wanyisq 发表于 2016-5-24 08:44
哈哈哈哈 没有一直盯着,隔几分钟看一眼

哈哈有意思。
wanyisq 回答时间:2016-5-25 08:40:59
没人遇到这种情况吗?

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版