本帖最后由 740071911 于 2022-6-30 21:29 编辑
#申请原创#目的:
1:使用定时器中断,来使LED小灯闪烁
2:驱动0.91inch的OLED显示芯源的L-O-G-O
现象:
实现方式:
1.制作图片,找一张图片导入PCtoLCD2002
2.导入图片后生成的图片可能很模糊(见下图)
芯源的L-O-G-O的字母W看不到,汉字也看不清,只能手动修改,精工出细活。
3.生成图库,写入代码中。
4.代码实现
- /*
- main.c
- */
- /******************************************************************************
- * Include files
- ******************************************************************************/
- #include "main.h"
- #include "OLED.h"
- #include "bmp.h"
- #include "tim1.h"
- //#include "Icon10_8.h"
- /******************************************************************************
- * Local pre-processor symbols/macros ('#define')
- ******************************************************************************/
- #define LED_GPIO_PORT CW_GPIOB
- #define LED_GPIO_PINS GPIO_PIN_9
- /******************************************************************************
- * Global variable definitions (declared in header file with 'extern')
- ******************************************************************************/
- volatile u16 LED_PERIOD = 100;
- u8 LED_INDEX = 0;
- /******************************************************************************
- * Local type definitions ('typedef')
- ******************************************************************************/
- /******************************************************************************
- * Local function prototypes ('static')
- ******************************************************************************/
- /******************************************************************************
- * Local variable definitions ('static') *
- ******************************************************************************/
- static u8 AB_count = 0;
- static u8 K0_count = 0;
- /******************************************************************************
- * Local pre-processor symbols/macros ('#define')
- ******************************************************************************/
- /*****************************************************************************
- * Function implementation - global ('extern') and local ('static')
- ******************************************************************************/
- void MX_SYS_Init(void);
- void MX_GPIO_Init(void);
- void Delay(uint32_t nCount);
- /**
- ******************************************************************************
- ** \brief Main function of project
- **
- ** \return uint32_t return value, if needed
- **
- ** LED1, LED2闪烁
- **
- ******************************************************************************/
- int32_t main(void)
- {
- MX_SYS_Init();
- MX_GPIO_Init();
-
- OLED_Init();
- OLED_DrawBMP(0, 0, 128, 8, (unsigned char *)BMP_CW32);
-
- MX_TIM1_Init();
-
- while (1)
- {
-
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] SYSCLK
- *
- * @param None
- */
- void MX_SYS_Init(void)
- {
- /* HSI使能并校准 */
- RCC_HSI_Enable(RCC_HSIOSC_DIV6);
-
- /* 设置HCLK和PCLK的分频系数 */
- RCC_HCLKPRS_Config(RCC_HCLK_DIV1);
- RCC_PCLKPRS_Config(RCC_PCLK_DIV1);
-
- /* 使能PLL,通过PLL实现8倍频到8MHz*8=64MHz */
- RCC_PLL_Enable(RCC_PLLSOURCE_HSI, 8000000, 8);
-
- /* RCC_PLL_OUT(); // PC13输出PLL时钟 */
-
- /* 当使用的时钟源 24MHz < HCLK <= 48MHz,设置 FLASH 读等待周期为 2 cycle */
- /* 当使用的时钟源 HCLK > 48MHz,设置 FLASH 读等待周期为 3 cycle */
- __RCC_FLASH_CLK_ENABLE();
- FLASH_SetLatency(FLASH_Latency_3);
-
- /* 时钟切换到PLL */
- RCC_SysClk_Switch(RCC_SYSCLKSRC_PLL);
- RCC_SystemCoreClockUpdate(64000000);
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] GPIO
- *
- * @param None
- */
- void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- __RCC_GPIOB_CLK_ENABLE();
- __RCC_GPIOA_CLK_ENABLE();
- //PC13---LED
- GPIO_InitStruct.IT = GPIO_IT_NONE;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pins = LED_GPIO_PINS;
- GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
- GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
-
- //PA12---BUZZER
- GPIO_InitStruct.IT = GPIO_IT_NONE;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pins = GPIO_PIN_12;
- GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
- GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
-
- PB09_SETLOW();
- PA12_SETHIGH();
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] 循环延时
- *
- * @param nCount
- */
- void Delay(__IO uint32_t nCount)
- {
- /* Decrement nCount value */
- while (nCount != 0)
- {
- nCount--;
- }
- }
- /******************************************************************************
- * EOF (not truncated)
- ******************************************************************************/
tim.c
- /*
- tim.c
- */
- #include "tim1.h"
- void MX_TIM1_Init(void)
- {
- BTIM_TimeBaseInitTypeDef tim1Config;
- /* Timer1时钟开启 */
- __RCC_BTIM_CLK_ENABLE();
-
- __disable_irq();
- NVIC_EnableIRQ(BTIM1_IRQn);
- __enable_irq();
- tim1Config.BTIM_Mode = BTIM_Mode_TIMER;
- tim1Config.BTIM_Period = 1000;
- tim1Config.BTIM_Prescaler = BTIM_PRS_DIV64;
- BTIM_TimeBaseInit(CW_BTIM1, &tim1Config);
-
- BTIM_ITConfig(CW_BTIM1, BTIM_IT_OV, ENABLE);
-
- BTIM_Cmd(CW_BTIM1, ENABLE);
- }
5.代码附件
cw32-startkit-v1.0.zip
(213.63 KB, 下载次数: 17)
|