stm32单片机 怎么直接操作寄存器
楼主你这样真的很为难人,以stm32的跑马灯为例
#include "led.h"//头文件自己写
#include "stm32f4xx.h"//直接操作寄存器必备的头文件
void LED_Init(void)
{
RCC->AHB1ENR|= 1<<5;//时钟初始化;1<<5是对寄存器第五位进行操作
//PF9为LED所接引脚
GPIOF->MODER &= ~(3<<2*9);
GPIOF->MODER |= 1<<(2*9);
GPIOF->OSPEEDR &= ~(3<<2*9);
GPIOF->OSPEEDR |= 2<<(2*9);
GPIOF->PUPDR &= ~(3<<2*9);
GPIOF->PUPDR |=1<<(2*9);
GPIOF->OTYPER &= ~(1<<9);
GPIOF->OTYPER |=0<<9;
GPIOF->ODR|= 1<<9;//1
//GPIOF->ODR&=~(1<<9);//0
//PF10类比于PF9
GPIOF->MODER &= ~(3<<2*10);
GPIOF->MODER |= 1<<(2*10);
GPIOF->OSPEEDR &= ~(3<<2*10);
GPIOF->OSPEEDR |= 2<<(2*10);
GPIOF->PUPDR &= ~(3<<2*10);
GPIOF->PUPDR |=1<<(2*10);
GPIOF->OTYPER &= ~(1<<10);
GPIOF->OTYPER |=0<<10;
GPIOF->ODR|= 1<<10;
}