LED流水灯1.设置多个引脚 接着使用LED闪烁的代码 (有关使用函数的介绍和LED闪烁的代码:https://mp.csdn.net/mp_blog/creation/editor/129776176)
2. 程序- #include "stm32f10x.h" // Device header
- #include "Delay.h"
- int main()
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
- //也可以这么写GPIO_Pin_0|GPIO_Pin_0|GPIO_Pin_0....;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- while(1)
- {
- GPIO_Write(GPIOA,~0x0001);
- //因为是低电平点亮,所以加一个取反符号.这样就是第一个灯亮
- Delay_ms(500);
- //Delay.c文件在LED闪烁中有就不再写了
- GPIO_Write(GPIOA,~0x0002);
- Delay_ms(500);
- GPIO_Write(GPIOA,~0x0004);
- Delay_ms(500);
- GPIO_Write(GPIOA,~0x0008);
- Delay_ms(500);
- GPIO_Write(GPIOA,~0x0010);
- Delay_ms(500);
- GPIO_Write(GPIOA,~0x0020);
- Delay_ms(500);
- GPIO_Write(GPIOA,~0x0040);
- Delay_ms(500);
- GPIO_Write(GPIOA,~0x0080);
- Delay_ms(500);
- }
- }
转换为二进制
0x00001---->0000 0000 0000 0001
0x00002---->0000 0000 0000 0010
0x00004---->0000 0000 0000 0100
0x00008---->0000 0000 0000 1000
0x00010---->0000 0000 0001 0000
0x00020---->0000 0000 0010 0000
0x00040---->0000 0000 0100 0000
0x00080---->0000 0000 1000 0000
|