[CW32F030系列] 【CW32F030CxTx StartKit测评】LED+定时器+OLED显示

[复制链接]
4568|11
 楼主| 740071911 发表于 2022-6-30 21:26 | 显示全部楼层 |阅读模式
ar, cw
本帖最后由 740071911 于 2022-6-30 21:29 编辑

#申请原创#目的:
1:使用定时器中断,来使LED小灯闪烁
2:驱动0.91inch的OLED显示芯源的L-O-G-O
屏幕截图 2022-06-30 203453.png
现象:
录制_2022_06_30_20_57_16_599.gif

实现方式:
1.制作图片,找一张图片导入PCtoLCD2002
ccccc.bmp
2.导入图片后生成的图片可能很模糊(见下图)
ddddd.png
芯源的L-O-G-O的字母W看不到,汉字也看不清,只能手动修改,精工出细活。
3.生成图库,写入代码中。
4.代码实现
  1. /*
  2. main.c
  3. */
  4. /******************************************************************************
  5. * Include files
  6. ******************************************************************************/
  7. #include "main.h"
  8. #include "OLED.h"
  9. #include "bmp.h"
  10. #include "tim1.h"

  11. //#include "Icon10_8.h"
  12. /******************************************************************************
  13. * Local pre-processor symbols/macros ('#define')
  14. ******************************************************************************/
  15. #define LED_GPIO_PORT CW_GPIOB
  16. #define LED_GPIO_PINS GPIO_PIN_9

  17. /******************************************************************************
  18. * Global variable definitions (declared in header file with 'extern')
  19. ******************************************************************************/
  20. volatile u16 LED_PERIOD = 100;
  21. u8 LED_INDEX = 0;
  22. /******************************************************************************
  23. * Local type definitions ('typedef')
  24. ******************************************************************************/

  25. /******************************************************************************
  26. * Local function prototypes ('static')
  27. ******************************************************************************/

  28. /******************************************************************************
  29. * Local variable definitions ('static')                                      *
  30. ******************************************************************************/
  31. static u8 AB_count = 0;
  32. static u8 K0_count = 0;

  33. /******************************************************************************
  34. * Local pre-processor symbols/macros ('#define')
  35. ******************************************************************************/

  36. /*****************************************************************************
  37. * Function implementation - global ('extern') and local ('static')
  38. ******************************************************************************/
  39. void MX_SYS_Init(void);
  40. void MX_GPIO_Init(void);
  41. void Delay(uint32_t nCount);
  42. /**
  43. ******************************************************************************
  44. ** \brief  Main function of project
  45. **
  46. ** \return uint32_t return value, if needed
  47. **
  48. ** LED1, LED2闪烁
  49. **
  50. ******************************************************************************/
  51. int32_t main(void)
  52. {
  53.     MX_SYS_Init();
  54.     MX_GPIO_Init();
  55.    
  56.     OLED_Init();
  57.     OLED_DrawBMP(0, 0, 128, 8, (unsigned char *)BMP_CW32);
  58.    
  59.     MX_TIM1_Init();
  60.    
  61.     while (1)
  62.     {
  63.         
  64.     }
  65. }


  66. /**
  67. * [url=home.php?mod=space&uid=247401]@brief[/url] SYSCLK
  68. *
  69. * @param None
  70. */
  71. void MX_SYS_Init(void)
  72. {
  73.     /* HSI使能并校准 */
  74.     RCC_HSI_Enable(RCC_HSIOSC_DIV6);
  75.    
  76.     /* 设置HCLK和PCLK的分频系数 */
  77.     RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
  78.     RCC_PCLKPRS_Config(RCC_PCLK_DIV1);
  79.    
  80.     /* 使能PLL,通过PLL实现8倍频到8MHz*8=64MHz */
  81.     RCC_PLL_Enable(RCC_PLLSOURCE_HSI, 8000000, 8);
  82.    
  83.     /* RCC_PLL_OUT(); // PC13输出PLL时钟 */
  84.    
  85.     /* 当使用的时钟源 24MHz < HCLK <= 48MHz,设置 FLASH 读等待周期为 2 cycle */
  86.     /* 当使用的时钟源 HCLK > 48MHz,设置 FLASH 读等待周期为 3 cycle */
  87.     __RCC_FLASH_CLK_ENABLE();
  88.     FLASH_SetLatency(FLASH_Latency_3);
  89.    
  90.     /* 时钟切换到PLL */
  91.     RCC_SysClk_Switch(RCC_SYSCLKSRC_PLL);
  92.     RCC_SystemCoreClockUpdate(64000000);
  93. }


  94. /**
  95. * [url=home.php?mod=space&uid=247401]@brief[/url] GPIO
  96. *
  97. * @param None
  98. */
  99. void MX_GPIO_Init(void)
  100. {
  101.     GPIO_InitTypeDef GPIO_InitStruct;

  102.     __RCC_GPIOB_CLK_ENABLE();
  103.     __RCC_GPIOA_CLK_ENABLE();

  104.     //PC13---LED
  105.     GPIO_InitStruct.IT = GPIO_IT_NONE;
  106.     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  107.     GPIO_InitStruct.Pins = LED_GPIO_PINS;
  108.     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  109.     GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
  110.    
  111.     //PA12---BUZZER
  112.     GPIO_InitStruct.IT = GPIO_IT_NONE;
  113.     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  114.     GPIO_InitStruct.Pins = GPIO_PIN_12;
  115.     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  116.     GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
  117.    
  118.     PB09_SETLOW();
  119.     PA12_SETHIGH();
  120. }


  121. /**
  122. * [url=home.php?mod=space&uid=247401]@brief[/url] 循环延时
  123. *
  124. * @param nCount
  125. */
  126. void Delay(__IO uint32_t nCount)
  127. {
  128.     /* Decrement nCount value */
  129.     while (nCount != 0)
  130.     {
  131.         nCount--;
  132.     }
  133. }

  134. /******************************************************************************
  135. * EOF (not truncated)
  136. ******************************************************************************/

tim.c
  1. /*
  2. tim.c
  3. */
  4. #include "tim1.h"

  5. void MX_TIM1_Init(void)
  6. {
  7.     BTIM_TimeBaseInitTypeDef tim1Config;

  8.     /* Timer1时钟开启 */
  9.     __RCC_BTIM_CLK_ENABLE();
  10.    
  11.     __disable_irq();
  12.     NVIC_EnableIRQ(BTIM1_IRQn);
  13.     __enable_irq();

  14.     tim1Config.BTIM_Mode = BTIM_Mode_TIMER;
  15.     tim1Config.BTIM_Period = 1000;
  16.     tim1Config.BTIM_Prescaler = BTIM_PRS_DIV64;
  17.     BTIM_TimeBaseInit(CW_BTIM1, &tim1Config);
  18.    
  19.     BTIM_ITConfig(CW_BTIM1, BTIM_IT_OV, ENABLE);
  20.    
  21.     BTIM_Cmd(CW_BTIM1, ENABLE);
  22. }

5.代码附件
cw32-startkit-v1.0.zip (213.63 KB, 下载次数: 17)



  
caigang13 发表于 2022-7-1 07:58 来自手机 | 显示全部楼层
0.91寸的屏很少见啊
onlycook 发表于 2022-7-1 10:29 来自手机 | 显示全部楼层
都很敬业,测评贴这么快就发出来了
mickit 发表于 2022-7-9 12:07 | 显示全部楼层
字符开发比较复杂了。   
pentruman 发表于 2022-7-9 12:46 | 显示全部楼层
可以显示汉字吗   
chenci2013 发表于 2022-7-9 13:45 | 显示全部楼层
iic和spi有什么不同呢   
 楼主| 740071911 发表于 2022-7-9 13:59 | 显示全部楼层
 楼主| 740071911 发表于 2022-7-9 14:00 | 显示全部楼层
chenci2013 发表于 2022-7-9 13:45
iic和spi有什么不同呢

iic速度比spi慢,但是线少,简洁
wwppd 发表于 2022-7-9 14:18 | 显示全部楼层
这个定时器作用是什么?
 楼主| 740071911 发表于 2022-7-9 16:56 | 显示全部楼层
wwppd 发表于 2022-7-9 14:18
这个定时器作用是什么?

定时器做led翻转的定时
yeates333 发表于 2022-8-19 22:25 | 显示全部楼层
如何实现图形显示的?   
houjiakai 发表于 2022-8-20 21:15 | 显示全部楼层
谢谢楼主分享的资料了。   
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:想低声说句不在乎,可会飞的心总是在高处!

48

主题

887

帖子

5

粉丝
快速回复 在线客服 返回列表 返回顶部