#ifndef __LED_H__
#define __LED_H__
#define RCC (*(volatile unsigned int*)0x50000A28)
typedef struct{
volatile unsigned int MODER;
volatile unsigned int OTYPER;
volatile unsigned int OSPEEDR;
volatile unsigned int PUPDR;
volatile unsigned int IDR;
volatile unsigned int ODR;
}gpio_t;
#define GPIOE ((gpio_t*)0x50006000)
#define GPIOF ((gpio_t*)0x50007000)
int LD1_reset();
int LED1_on();
int LED1_off();
#endif
#include "led.h"
int LD1_reset()
{
RCC=RCC|(0x1 << 4);
//pe10
GPIOE->MODER=GPIOE->MODER & (~(0x3 << 20));
GPIOE->MODER=GPIOE->MODER | (0x1 << 20);
GPIOE->OTYPER=GPIOE->OTYPER & (~(0x1 << 10));
GPIOE->OSPEEDR=GPIOE->OSPEEDR & (~(0x3 << 20));
GPIOE->PUPDR=GPIOE->PUPDR & (~(0x3 << 20));
//pe8
GPIOE->MODER=GPIOE->MODER & (~(0x3 << 16));
GPIOE->MODER=GPIOE->MODER | (0x1 << 16);
GPIOE->OTYPER=GPIOE->OTYPER & (~(0x1 << 8));
GPIOE->OSPEEDR=GPIOE->OSPEEDR & (~(0x3 << 16));
GPIOE->PUPDR=GPIOE->PUPDR & (~(0x3 << 16));
//pf10
RCC=RCC|(0x1 << 5);
GPIOF->MODER=GPIOF->MODER & (~(0x3 << 20));
GPIOF->MODER=GPIOF->MODER | (0x1 << 20);
GPIOF->OTYPER=GPIOF->OTYPER & (~(0x1 << 10));
GPIOF->OSPEEDR=GPIOF->OSPEEDR & (~(0x3 << 20));
GPIOF->PUPDR=GPIOF->PUPDR & (~(0x3 << 20));
return 0;
}
int LED1_on()
{
GPIOE->ODR=GPIOE->ODR | (0x1 << 10);
GPIOE->ODR=GPIOE->ODR | (0x1 << 8);
GPIOF->ODR=GPIOF->ODR | (0x1 << 10);
return 0;
}
int LED1_off()
{
GPIOE->ODR=GPIOE->ODR & (~(0x1 << 10));
GPIOE->ODR=GPIOE->ODR & (~(0x1 << 8));
GPIOF->ODR=GPIOF->ODR & (~(0x1 << 10));
return 0;
}
main.c:
#include "led.h"
extern void printf(const char *fmt, ...);
void delay_ms(int ms)
{
int i,j;
for(i = 0; i < ms;i++)
for (j = 0; j < 1800; j++);
}
int main()
{
LD1_reset();// LED1灯初始化
while(1)
{
LED1_on();
delay_ms(500);
LED1_off();
delay_ms(500);
}
return 0;
}