注:是循环亮灭,每次只亮一个灯,不是流水灯
完整代码如下:
#include "stm32f10x.h"
uint16_t temp,i;
void Delay(unsigned int count)
{
unsigned int i;
for(;count!=0;count--)
{
i=5000;
while(i--);
}
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使能GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //时钟A使能
GPIO_InitStructure.GPIO_Pin =
GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;//PA1-PA8引脚配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速率
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化PA1-PA8
while(1)
{
temp=0x001;
for(i=0;i<8;i++)
{
GPIO_Write(GPIOA,~temp);
Delay(200);
temp=temp<<1;
}
}
}