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

本文介绍了如何使用STM32微控制器通过定时器中断实现LED灯的闪烁,并利用PCtoLCD2002软件生成OLED显示的L-O-G-O图像。在实践中,由于图片质量不理想,需要手动调整,最终成功驱动0.91寸OLED显示。代码包括了系统初始化、GPIO配置、延时函数以及TIM1定时器的初始化。
摘要由CSDN通过智能技术生成

目的:
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);

   

    /* 设置HCLKPCLK的分频系数 */

    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)
---------------------
作者:740071911
链接:https://bbs.21ic.com/icview-3235760-1-1.html
来源:21ic.com
此文章已获得原创/原创奖标签,著作权归21ic所有,任何人未经允许禁止转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值