typedef unsigned int unit32;
#define RCC_AHB1ENR *(( unit32 *)(0x40023800+0x30))
//E端口时钟
#define GPIOE_MODER *(( unit32 *)(0x40021000))
#define GPIOE_OTYPER *(( unit32 *)(0x40021004))
#define GPIOE_OSPEEDR *(( unit32 *)(0x40021008))
#define GPIOE_PUPDR *(( unit32 *)(0x4002100C))
#define GPIOE_ODR *(( unit32 *)(0x40021014))
//F端口时钟
#define GPIOF_MODER *(( unit32 *)(0x40021400))
#define GPIOF_OTYPER *(( unit32 *)(0x40021404))
#define GPIOF_OSPEEDR *(( unit32 *)(0x40021408))
#define GPIOF_PUPDR *(( unit32 *)(0x4002140C))
#define GPIOF_ODR *(( unit32 *)(0x40021414))
void led_init()
{
//打开EF端口的时钟
RCC_AHB1ENR|=((0x01<<5)|(0x01<<4));
//启动端口
//配置9号引脚
GPIOF_MODER &=~(0x01<<19);
GPIOF_MODER|=0x01<<18;
//配置10号引脚
GPIOF_MODER &=~(0x01<<21);
GPIOF_MODER|=0x01<<20;
//选择输出模式
//9号引脚
GPIOF_OTYPER |=0x01<<9;
//10号引脚
GPIOF_OTYPER |=0x01<<10;
//速度配置 9号引脚
GPIOF_OSPEEDR &=~(0x01<<19);
GPIOF_OSPEEDR |=0x01<<18;
//速度配置 10号引脚
GPIOF_OSPEEDR &=~(0x01<<21);
GPIOF_OSPEEDR |=0x01<<20;
//上拉配置9号引脚
GPIOF_PUPDR &=~(0x01<<19);
GPIOF_PUPDR |=0x01<<18;
//上拉配置10号引脚
GPIOF_PUPDR &=~(0x01<<21);
GPIOF_PUPDR |=0x01<<20;
//启动端口
//配置13号引脚
GPIOE_MODER &=~(0x01<<27);
GPIOE_MODER|=0x01<<26;
//配置14号引脚
GPIOE_MODER &=~(0x01<<29);
GPIOE_MODER|=0x01<<28;
//选择输出模式
//13号引脚
GPIOE_OTYPER |=0x01<<13;
//14号引脚
GPIOE_OTYPER |=0x01<<14;
//速度配置 13号引脚
GPIOE_OSPEEDR &=~(0x01<<27);
GPIOE_OSPEEDR |=0x01<<26;
//速度配置 14号引脚
GPIOE_OSPEEDR &=~(0x01<<29);
GPIOE_OSPEEDR |=0x01<<28;
//上拉配置13号引脚
GPIOE_PUPDR &=~(0x01<<27);
GPIOE_PUPDR |=0x01<<26;
//上拉配置14号引脚
GPIOE_PUPDR &=~(0x01<<29);
GPIOE_PUPDR |=0x01<<28;
//对数据位填充
GPIOE_ODR &=~(0x01<<13);
GPIOE_ODR &=~(0x01<<14);
STM32F4系列寄存器配置GPIO
最新推荐文章于 2024-11-15 20:32:27 发布