在电子词典中,使用GPIO来控制LED的点亮或熄灭来测试系统是否正常启动,通过端口F控制LED1和LED2的状态转换,请给出硬件设计示意图 ; 用C语言编写应用程序,实现LED1和LED2按照以下要求进行状态转换: 状态1(LED1、LED2同时点亮,LED1、LED2同时熄灭); 状态2(LED1长亮); 要求重复状态1三次后进入状态2 ; 程序包含两个部分,对端口的初始化和端口的读写应用 。
时间: 2024-03-21 19:41:22 浏览: 14
硬件设计示意图如下:
```
+-------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
+-------------+
LED1 LED2
| |
| |
PF0 PF1
| |
| |
+---------+
```
C语言应用程序如下:
```c
#include "stm32f10x.h"
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
void Delay(uint32_t nCount)
{
uint32_t i;
for (i = 0; i < nCount; i++);
}
int main(void)
{
GPIO_Configuration();
while (1)
{
// 状态1:LED1、LED2同时点亮
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
// 状态1:LED1、LED2同时熄灭
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
// 状态2:LED1长亮
GPIO_SetBits(GPIOF, GPIO_Pin_0);
Delay(500000);
// 重复状态1三次
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_SetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
GPIO_ResetBits(GPIOF, GPIO_Pin_0 | GPIO_Pin_1);
Delay(500000);
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)