欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: STM32F030以SPI方式驅動OLED(HAL庫版) [打印本頁]

作者: 天藍色的Toto    時間: 2021-2-28 15:58
標題: STM32F030以SPI方式驅動OLED(HAL庫版)
運用HAL庫驅動的硬件SPI OLED程序,用起來爽歪歪,快得很

單片機源程序如下:

  1. /* USER CODE END Header */
  2. /* Includes ------------------------------------------------------------------*/
  3. #include "main.h"
  4. #include "spi.h"
  5. #include "gpio.h"
  6. #include "oledspi.h"
  7. /* Private includes ----------------------------------------------------------*/
  8. /* USER CODE BEGIN Includes */
  9. #include "bmp.h"
  10. /* USER CODE END Includes */

  11. /* Private typedef -----------------------------------------------------------*/
  12. /* USER CODE BEGIN PTD */

  13. /* USER CODE END PTD */

  14. /* Private define ------------------------------------------------------------*/
  15. /* USER CODE BEGIN PD */
  16. /* USER CODE END PD */

  17. /* Private macro -------------------------------------------------------------*/
  18. /* USER CODE BEGIN PM */

  19. /* USER CODE END PM */

  20. /* Private variables ---------------------------------------------------------*/

  21. /* USER CODE BEGIN PV */

  22. /* USER CODE END PV */

  23. /* Private function prototypes -----------------------------------------------*/
  24. void SystemClock_Config(void);
  25. /* USER CODE BEGIN PFP */

  26. /* USER CODE END PFP */

  27. /* Private user code ---------------------------------------------------------*/
  28. /* USER CODE BEGIN 0 */

  29. /* USER CODE END 0 */

  30. /**
  31.   * @brief  The application entry point.
  32.   * @retval int
  33.   */
  34. int main(void)
  35. {
  36.   /* USER CODE BEGIN 1 */
  37.         uint8_t t;
  38.   /* USER CODE END 1 */

  39.   /* MCU Configuration--------------------------------------------------------*/

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

  42.   /* USER CODE BEGIN Init */

  43.   /* USER CODE END Init */

  44.   /* Configure the system clock */
  45.   SystemClock_Config();

  46.   /* USER CODE BEGIN SysInit */

  47.   /* USER CODE END SysInit */

  48.   /* Initialize all configured peripherals */
  49.   MX_GPIO_Init();
  50.   MX_SPI1_Init();
  51.   /* USER CODE BEGIN 2 */
  52.         OLED_Init();                        //初始化OLED  
  53.         OLED_Clear()          ;
  54.   /* USER CODE END 2 */

  55.   /* Infinite loop */
  56.   /* USER CODE BEGIN WHILE */
  57.   while (1)
  58.   {
  59.     /* USER CODE END WHILE */               
  60.     /* USER CODE BEGIN 3 */
  61.                 OLED_Clear();
  62.                 OLED_ShowCHinese(0,0,0);//晶
  63.                 OLED_ShowCHinese(18,0,1);//藍
  64.                 OLED_ShowCHinese(36,0,2);//電
  65.                 OLED_ShowCHinese(54,0,3);//子
  66.                 OLED_ShowCHinese(72,0,4);//科
  67.                 OLED_ShowCHinese(90,0,5);//技
  68.                 OLED_ShowString(0,2,"0.96 OLED TEST");
  69.                  OLED_ShowString(20,4,"2020/02/28");  
  70.                 OLED_ShowString(0,6,"ASCII:");  
  71.                 OLED_ShowString(63,6,"CODE:");  
  72.                 OLED_ShowChar(48,6,t);//顯示ASCII字符          
  73.                 t++;
  74.                 if(t>'~')t=' ';
  75.                 OLED_ShowNum(103,6,t,3,16);//顯示ASCII字符的碼值        
  76.                        
  77.                
  78.                 HAL_Delay(500);
  79.                 OLED_Clear();
  80.                 HAL_Delay(500);
  81.                 OLED_DrawBMP(0,0,128,8,(uint8_t*)BMP1);  //圖片顯示(圖片顯示慎用,生成的字表較大,會占用較多空間,FLASH空間8K以下慎用)
  82.                 HAL_Delay(500);
  83.                 OLED_DrawBMP(0,0,128,8,(uint8_t*)BMP2);
  84.                 HAL_Delay(500);
  85.   }
  86.   /* USER CODE END 3 */
  87. }

  88. /**
  89.   * @brief System Clock Configuration
  90.   * @retval None
  91.   */
  92. void SystemClock_Config(void)
  93. {
  94.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  95.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  96.   /** Initializes the RCC Oscillators according to the specified parameters
  97.   * in the RCC_OscInitTypeDef structure.
  98.   */
  99.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  100.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  101.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  102.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  103.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  104.   RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  105.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  106.   {
  107.     Error_Handler();
  108.   }
  109.   /** Initializes the CPU, AHB and APB buses clocks
  110.   */
  111.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  112.                               |RCC_CLOCKTYPE_PCLK1;
  113.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  114.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  115.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  116.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  117.   {
  118.     Error_Handler();
  119.   }
  120.   /** Enables the Clock Security System
  121.   */
  122.   HAL_RCC_EnableCSS();
  123. }

  124. /* USER CODE BEGIN 4 */

  125. /* USER CODE END 4 */

  126. /**
  127.   * @brief  This function is executed in case of error occurrence.
  128.   * @retval None
  129.   */
  130. void Error_Handler(void)
  131. {
  132.   /* USER CODE BEGIN Error_Handler_Debug */
  133.   /* User can add his own implementation to report the HAL error return state */
  134.   __disable_irq();
  135.   while (1)
  136.   {
  137.   }
  138.   /* USER CODE END Error_Handler_Debug */
  139. }

  140. #ifdef  USE_FULL_ASSERT
  141. /**
  142.   * @brief  Reports the name of the source file and the source line number
  143.   *         where the assert_param error has occurred.
  144.   * @param  file: pointer to the source file name
  145.   * @param  line: assert_param error line source number
  146.   * @retval None
  147.   */
  148. void assert_failed(uint8_t *file, uint32_t line)
  149. {
  150.   /* USER CODE BEGIN 6 */
  151.   /* User can add his own implementation to report the file name and line number,
  152.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  153.   /* USER CODE END 6 */
  154. }
  155. #endif /* USE_FULL_ASSERT */

  156. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復制代碼

所有程序51hei提供下載:
OLED_SPI.7z (5.11 MB, 下載次數: 87)



作者: Grey_World    時間: 2021-7-9 00:41
兄弟,不對呀,你這不是硬件SPI啊
作者: shumivan    時間: 2021-7-9 09:12
還是不帶字庫的,這個開發起來未免有些麻煩吧,,直接使用帶字庫的多方便




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1