话不多说,下面是main.c
#define PERIPH_BASE ((unsigned int)0x40000000)
//总线基址
#define APB1PERIPH_BASE PERIPH_BASE
#define APB2PERIPH_BASE ((unsigned int)PERIPH_BASE + 0x00010000)
#define AHB1PERIPH_BASE ((unsigned int)PERIPH_BASE + 0X00020000)
#define AHB2PERIPH_BASE ((unsigned int)PERIPH_BASE + 0x10000000)
//时钟基址
#define RCC_BASE ((unsigned int)PERIPH_BASE + 0x00020000 + 0x3800)
//端口基址
#define GPIOE_BASE ((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000)
//寄存器基址
#define RCC_AHB1ENR (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x3800 + 0x30))
#define GPIOE_BSRRL (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x38))
#define GPIOE_BSRRH (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x1a))
#define GPIOE_MODER (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x00))
#define GPIOE_OTYPER (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x04))
#define GPIOE_OSPEEDR (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x08))
#define GPIOE_PUPDR (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x0c))
#define GPIOE_BSSR (*(unsigned int *)((unsigned int)PERIPH_BASE + 0x00020000 + 0x1000 + 0x30))
unsigned short int Delay_ms(unsigned short int count);
int main()
{
//LED初始化
RCC_AHB1ENR |= (1<<4); //端口时钟使能
GPIOE_MODER |= (1<<28); //引脚工作模式为输出
GPIOE_OTYPER |= (0<<28); //引脚输出模式为推挽
GPIOE_PUPDR |= (1<<28); //上拉模式
GPIOE_OSPEEDR |= (1<<28); //引脚工作时钟速度
GPIOE_MODER |= (1<<24); //引脚工作模式为输出
GPIOE_OTYPER |= (0<<24); //引脚输出模式为推挽
GPIOE_PUPDR |= (1<<24); //上拉模式
GPIOE_OSPEEDR |= (1<<24); //引脚工作时钟速度
GPIOE_MODER |= (1<<20); //引脚工作模式为输出
GPIOE_OTYPER |= (0<<20); //引脚输出模式为推挽
GPIOE_PUPDR |= (1<<20); //上拉模式
GPIOE_OSPEEDR |= (1<<20); //引脚工作时钟速度
GPIOE_MODER |= (1<<16); //引脚工作模式为输出
GPIOE_OTYPER |= (0<<16); //引脚输出模式为推挽
GPIOE_PUPDR |= (1<<16); //上拉模式
GPIOE_OSPEEDR |= (1<<16); //引脚工作时钟速度
/********************************************************************************/
while(1)
{
GPIOE_BSRRH = (1<<14); //点亮相应的LED
Delay_ms(100); //函数延时
GPIOE_BSRRL = (1<<14); //熄灭相应的LED
Delay_ms(100); //函数延时
GPIOE_BSRRH = (1<<12); //点亮相应的LED
Delay_ms(100);
GPIOE_BSRRL = (1<<12); //熄灭相应的LED
Delay_ms(100);
GPIOE_BSRRH = (1<<10); //点亮相应的LED
Delay_ms(100);
GPIOE_BSRRL = (1<<10); //熄灭相应的LED
Delay_ms(100);
GPIOE_BSRRH = (1<<8); //点亮相应的LED
Delay_ms(100);
GPIOE_BSRRL = (1<<8); //熄灭相应的LED
Delay_ms(100);
GPIOE_BSRRH = (1<<8); //点亮相应的LED
Delay_ms(100);
GPIOE_BSRRL = (1<<8); //熄灭相应的LED
Delay_ms(100);
GPIOE_BSRRH = (1<<10); //点亮相应的LED
Delay_ms(100);
GPIOE_BSRRL = (1<<10); //熄灭相应的LED
Delay_ms(100);
GPIOE_BSRRH = (1<<12); //点亮相应的LED
Delay_ms(100);
GPIOE_BSRRL = (1<<12); //熄灭相应的LED
Delay_ms(100);
GPIOE_BSRRH = (1<<14); //点亮相应的LED
Delay_ms(100); //函数延时
GPIOE_BSRRL = (1<<14); //熄灭相应的LED
Delay_ms(100); //函数延时
}
}
/***********************************延时函数*************************************/
unsigned short int Delay_ms(unsigned short int count)
{
unsigned short int i=0;
while(count--)
{
for(i=12000;i>0;i--);
}
return count;
}
如题,不知道有啥毛病