#include "stm32f10x.h"
#define uint unsigned int
void Delay(uint time);
void LEDInit(uint i);
int main(){
RCC->APB2ENR |= (1<<2); //开启时钟,GPIOA属于总线APB2; GPIOA对应APB2的第二位 0:为关闭(默认) 1:开启
while(1)
{
uint i;
for (i = 0; i < 8; i++){
LEDInit(i);
Delay(100000); //试运行
// GPIOA->ODR |= 0xFFFFFFFF; //延迟之后给灯高电平(熄灭)
// Delay(1000000); //试运行
}
if (i >= 8){
i = 0;
}
//GPIOA->CRL = 0x11111111; //推挽输出 把PA0,PA1,PA2,PA3,PA4,PA4,PA5,PA6,PA7配置成输出
//输出寄存器
//GPIOA->ODR &= 0xFFFFFFFE; //让GPIOA输出0 默认输出低电平亮
}
}
void SystemInit(void){
}
//传入1000000就是1s
void Delay(uint time){
uint i;
for (i = 0; i < time; i++){
uint t = 11;
while (t != 0){
t--;
}
}
}
void LEDInit(uint i){
GPIOA->ODR = 0;
switch(i){
case 0:
GPIOA->CRL = 0x01; //把PA0设置为推免输出
GPIOA->ODR &= 0xFFFFFFFE; //把PA0设置为低电平
break;
case 1:
GPIOA->CRL = 0x10; //把PA1设置为推免输出
GPIOA->ODR &= 0xFFFFFFFD; //把PA1设置为低电平
break;
case 2:
GPIOA->CRL = 0x100; //把PA2设置为推免输出
GPIOA->ODR &= 0xFFFFFFFC; //把PA2设置为低电平
break;
case 3:
GPIOA->CRL = 0x1000; //把PA3设置为推免输出
GPIOA->ODR &= 0xFFFFFFFB; //把PA3设置为低电平
break;
case 4:
GPIOA->CRL = 0x10000; //把PA4设置为推免输出
GPIOA->ODR &= 0xFFFFFFFA; //把PA4设置为低电平
break;
case 5:
GPIOA->CRL = 0x100000; //把PA5设置为推免输出
GPIOA->ODR &= 0xFFFFFFF9; //把PA5设置为低电平
break;
case 6:
GPIOA->CRL = 0x1000000; //把PA6设置为推免输出
GPIOA->ODR &= 0xFFFFFFF8; //把PA6设置为低电平
break;
case 7:
GPIOA->CRL = 0x1000000; //把PA7设置为推免输出
GPIOA->ODR &= 0xFFFFFFF7; //把PA7设置为低电平
break;
}
}