logo
carrot

太阳当空照,花儿对我笑

stm32呼吸灯

7/7/2023, 10:28:21 AM
  1. 首页
  2. /
  3. 正文
#include <stm32f10x_gpio.h>
#include <stm32f10x_rcc.h>
#include "delay.h"

int main() {
	RCC_Configuration(); //时钟设置

	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);

	u8 s = 0;
	while (1) {
		s++;
		s &= 1;
		for (int i = 0; i <= 250; i++) {
			for (int j = 0; j < 20; j++) {
				GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(0 ^ s));
				delay_us(i);
				GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(1 ^ s));
				delay_us(250 - i);
			}
		}
	}
}
热门文章
标签云
© 2021 Copyright 本站由 upyun 提供储存服务