头文件
#ifndef __LED_H__
#define __LED_H__
#define RCC (*(unsigned int *)0X50000A28)
#define GPIOE_MODER (*(unsigned int *)0X50006000)
#define GPIOF_MODER (*(unsigned int *)0X50007000)
#define GPIOE_OTYPER (*(unsigned int *)0X50006004)
#define GPIOE_OSPEEDR (*(unsigned int *)0X50006008)
#define GPIOE_OPUPDR (*(unsigned int *)0X5000600C)
#define GPIOE_ODR (*(unsigned int *)0X50006014)
#define GPIOF_OTYPER (*(unsigned int *)0X50007004)
#define GPIOF_OSPEEDR (*(unsigned int *)0X50007008)
#define GPIOF_OPUPDR (*(unsigned int *)0X5000700C)
#define GPIOF_ODR (*(unsigned int *)0X50007014)
void all_led_init();
void LED1_ON();
void LED2_ON();
void LED3_ON();
void LED1_OFF();
void LED2_OFF();
void LED3_OFF();
#endif
.c
#include "led.h"
void all_led_init()//led灯的初始化
{
//GPIOE/GPIOF时钟使能
RCC |= (0x3<<4);
//PE10设置为输出
GPIOE_MODER &= (~(0X3<<20));
GPIOE_MODER |= (0X1<<20);
//PF10设置为输出
GPIOF_MODER &= (~(0X3<<20));
GPIOF_MODER |= (0X1<<20);
//PE8设置为输出
GPIOE_MODER &= (~(0X3<<16));
GPIOE_MODER |= (0X1<<16);
//PE10设置为推挽输出
GPIOE_OTYPER &= (~(0X1<<10));
//PF10设置为推挽输出
GPIOF_OTYPER &= (~(0X1<<10));
//PE8设置为推挽输出
GPIOE_OTYPER &= (~(0X1<<8));
//PE10设置为低速输出
GPIOE_OSPEEDR &= (~(0X3<<20));
//PF10设置为低速输出
GPIOF_OSPEEDR &= (~(0X3<<20));
//PE8设置为低速输出
GPIOE_OSPEEDR &= (~(0X3<<16));
//PE10无上拉下拉电阻
GPIOE_OPUPDR &= (~(0X3<<20));
//PF10无上拉下拉电阻
GPIOF_OPUPDR &= (~(0X3<<20));
//PE8无上拉下拉电阻
GPIOE_OPUPDR &= (~(0X3<<16));
//三盏灯默认输出低电平
GPIOE_ODR &= (~(0X1<<10));
GPIOF_ODR &= (~(0X1<<10));
GPIOE_ODR &= (~(0X1<<8));
}
//led1亮
void LED1_ON()
{
GPIOE_ODR |= (0X1<<10);
}
//led2亮
void LED2_ON()
{
GPIOF_ODR |= (0X1<<10);
}
//led3亮
void LED3_ON()
{
GPIOE_ODR |= (0X1<<8);
}
//LED1灭
void LED1_OFF()
{
GPIOE_ODR &= (~(0X1<<10));
}
//LED2灭
void LED2_OFF()
{
GPIOF_ODR &= (~(0X1<<10));
}
//LED3灭
void LED3_OFF()
{
GPIOE_ODR &= (~(0X1<<8));
}