stm32点亮LED跑马灯 protues-stm32流水灯
通过网盘分享的文件:LED跑马灯
链接: https://pan.baidu.com/s/1_ep-87xvgmrAMpJWHgYdUQ 提取码: q7nq
#include "stm32f10x.h" // Device header
#include "Delay.h"int main(void)
{
/*开启时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //开启GPIOA的时钟
//使用各个外设前必须开启时钟,否则对外设的操作无效
/*GPIO初始化*/
GPIO_InitTypeDef GPIO_InitStructure; //定义结构体变量
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //GPIO模式,赋值为推挽输出模式
GPIO_InitStructure.GPIO_Pin = 0XFFFF; //GPIO引脚,赋值为所有引脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //GPIO速度,赋值为50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //将赋值后的构体变量传递给GPIO_Init函数
//函数内部会自动根据结构体的参数配置相应寄存器
//实现GPIOA的初始化
/*主循环,循环体内的代码会一直循环执行*/
while (1)
{
GPIO_Write(GPIOA, 0xffff); //1111 1111 1111 1111,PA引脚为高电平
/*使用GPIO_Write,同时设置GPIOA所有引脚的高低电平,实现LED流水灯*/
GPIO_ResetBits (GPIOA,GPIO_Pin_0);//实现GPIOA PA0为低电平
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_0);//实现GPIOA PA0为高电平
GPIO_ResetBits (GPIOA,GPIO_Pin_1);//实现GPIOA PA1为低电平
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_1);
GPIO_ResetBits (GPIOA,GPIO_Pin_2);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_2);
GPIO_ResetBits (GPIOA,GPIO_Pin_3);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_3);
GPIO_ResetBits (GPIOA,GPIO_Pin_4);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_4);
GPIO_ResetBits (GPIOA,GPIO_Pin_5);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_5);
GPIO_ResetBits (GPIOA,GPIO_Pin_6);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_6);
GPIO_ResetBits (GPIOA,GPIO_Pin_7);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_7);
GPIO_ResetBits (GPIOA,GPIO_Pin_8);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_8);
GPIO_ResetBits (GPIOA,GPIO_Pin_9);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_9);
GPIO_ResetBits (GPIOA,GPIO_Pin_10);
Delay_s(50);
GPIO_SetBits (GPIOA,GPIO_Pin_10);
GPIO_Write(GPIOA, ~0x0400); //0000 0100 0000 0000,PA0引脚为低电平,其他引脚均为高电平,注意数据有按位取反
Delay_s(50);
GPIO_Write(GPIOA, ~0x0800); //0000 1000 0000 0000,PA0引脚为低电平,其他引脚均为高电平,注意数据有按位取反
Delay_s(50);
GPIO_Write(GPIOA, ~0x1000); //0001 0000 0000 0000,PA0引脚为低电平,其他引脚均为高电平,注意数据有按位取反
Delay_s(50);
GPIO_Write(GPIOA, ~0x2000); //0010 0000 0000 0000,PA0引脚为低电平,其他引脚均为高电平,注意数据有按位取反
Delay_s(50);
GPIO_Write(GPIOA, ~0x4000); //0100 0000 0000 0000,PA0引脚为低电平,其他引脚均为高电平,注意数据有按位取反
Delay_s(50);
}
}




最新发布