STM32通过数组的方式、宏定义的方式、函数的方式和Systick中断的方式实现跑马灯的循环移位。
文章目录
基于数组的方式实现流水灯的循环左移
led.c
LED_Init
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//1、开启时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
//2、指定哪些引脚需要修改
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4
|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9
|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14
|GPIO_Pin_15;
//3、IO口的属性设置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; //LED的话2M就行
GPIO_Init(GPIOE, &GPIO_InitStructure); //推挽输出 ,IO口速度为50MHz
}
一般来说,GPIO初始化工作主要有三步:
1、开始时钟
2、指定哪些引脚需要修改
3、IO口的属性设置
main.c
LED[16]
LED[16]={
0xfffe,0xfffd,0xfffb,0xfff7,
0xffef,0xffdf,0xffbf,0xff7f,
0xfeff,0xfdff,0xfbff,0xf7ff,
0xefff