学号最后两位为ab,学号为奇数的使用GPIOA,学号为偶数使用GPIOC,引脚分别为(ab+5)%16,(ab+6)%16。直接调用延时函数为Delay(m),单位ms(不需要定义)。共阳接法,设计一个流水灯程序。
时间: 2023-04-10 13:01:11 浏览: 58
好的,这是一个关于嵌入式开发的问题,我可以回答。以下是代码实现:
#include "stm32f10x.h"
void Delay(uint32_t nTime);
int main(void)
{
uint8_t ab = 0x0A; // 假设学号最后两位为10
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE); // 使能GPIOA和GPIOC时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); // 配置GPIOA.5为输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOC, &GPIO_InitStructure); // 配置GPIOC.6为输出
while (1)
{
GPIO_SetBits(GPIOA, GPIO_Pin_5); // 点亮GPIOA.5
Delay(500); // 延时500ms
GPIO_ResetBits(GPIOA, GPIO_Pin_5); // 熄灭GPIOA.5
GPIO_SetBits(GPIOC, GPIO_Pin_6); // 点亮GPIOC.6
Delay(500); // 延时500ms
GPIO_ResetBits(GPIOC, GPIO_Pin_6); // 熄灭GPIOC.6
}
}
void Delay(uint32_t nTime)
{
uint32_t i;
for (i = 0; i < nTime * 1000; i++);
}
希望这个代码可以帮到你。
相关推荐
![](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)