STM32103c8t6花样灯代码
时间: 2023-08-28 22:08:00 浏览: 162
以下是STM32F103C8T6花样灯的代码示例:
```
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* GPIOB Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PB0, PB1 and PB5 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
while (1)
{
/* PB0, PB1 and PB5 LED on */
GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_5);
Delay(0x7FFFF);
/* PB0, PB1 and PB5 LED off */
GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_5);
Delay(0x7FFFF);
/* PB0 LED on */
GPIO_SetBits(GPIOB, GPIO_Pin_0);
Delay(0x7FFFF);
/* PB0 LED off */
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
Delay(0x7FFFF);
/* PB1 LED on */
GPIO_SetBits(GPIOB, GPIO_Pin_1);
Delay(0x7FFFF);
/* PB1 LED off */
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
Delay(0x7FFFF);
/* PB5 LED on */
GPIO_SetBits(GPIOB, GPIO_Pin_5);
Delay(0x7FFFF);
/* PB5 LED off */
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
Delay(0x7FFFF);
}
}
/**
* @brief Delay.
* @param nCount
* @retval None
*/
void Delay(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
```
此代码是用来控制STM32F103C8T6开发板上的三个LED灯(PB0、PB1、PB5),并且可以实现LED灯的闪烁效果。在代码中,使用了GPIO_InitTypeDef结构体来配置GPIO端口,使用了RCC_APB2PeriphClockCmd函数来使能GPIOB端口的时钟,使用了GPIO_SetBits和GPIO_ResetBits函数来控制LED灯的亮灭,以及使用了Delay函数来实现延时。
阅读全文