写一段在stm32f103上控制流水灯依次闪烁的代码
时间: 2024-05-25 12:18:34 浏览: 12
#include "stm32f10x.h"
#define LED_PORT GPIOC
#define LED_PIN_1 GPIO_Pin_13
#define LED_PIN_2 GPIO_Pin_14
#define LED_PIN_3 GPIO_Pin_15
void delay(uint32_t time)
{
while(time--);
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = LED_PIN_1|LED_PIN_2|LED_PIN_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_PORT, &GPIO_InitStructure);
while(1)
{
GPIO_SetBits(LED_PORT, LED_PIN_1);
delay(5000000);
GPIO_ResetBits(LED_PORT, LED_PIN_1);
GPIO_SetBits(LED_PORT, LED_PIN_2);
delay(5000000);
GPIO_ResetBits(LED_PORT, LED_PIN_2);
GPIO_SetBits(LED_PORT, LED_PIN_3);
delay(5000000);
GPIO_ResetBits(LED_PORT, LED_PIN_3);
}
}