keil5呼吸灯程序代码
时间: 2024-06-09 17:03:02 浏览: 15
KEIL5是一款嵌入式系统开发软件,用于编写嵌入式程序。呼吸灯程序是一个常见的嵌入式程序案例,其实现原理是让LED灯逐渐从暗到亮,再由亮变为暗的过程,不断重复,形成“呼吸”的效果。以下是一个基于STM32的KEIL5呼吸灯程序代码示例:
```
#include "stm32f10x.h"
void Delay(__IO uint32_t nCount);
int main(void)
{
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);
while (1)
{
for (int i = 0; i < 1000; i++)
{
GPIO_SetBits(GPIOB, GPIO_Pin_0);
Delay(1000 - i);
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
Delay(i);
}
for (int i = 1000; i > 0; i--)
{
GPIO_SetBits(GPIOB, GPIO_Pin_0);
Delay(1000 - i);
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
Delay(i);
}
}
}
void Delay(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)