#include "stm32f10x.h" void APClkInit(void); void GPIO_Init(void); //32位的处理器 int 是4个字节的 #define BIT2 1 << 2; #define GPIOA_EN BIT2 int main(void) { APClkInit(); GPIO_Init(); GPIOA->BSRR = 1<<4; // 置位PA.4 while(1); } /*HSI high speed internal clk 内部高速时钟 HSE high speed external clk 外部高速时钟 LSE low speed external clk 32768 RTC LSI low speed internal clk 40KHz || CLK >> 30KHz && CLK << 60KHz 内部时钟可能和温度有关 单片机复位的时候 是用的HSI typedef struct { __IO uint32_t CR; //control register __IO uint32_t CFGR; //config __IO uint32_t CIR; //interrup __IO uint32_t APB2RSTR; // APB2 reset __IO uint32_t APB1RSTR; // APB1 reset __IO uint32_t AHBENR; // __IO uint32_t APB2ENR; __IO uint32_t APB1ENR; // AHB APB1 APB2 __IO uint32_t BDCR; __IO uint32_t CSR; // state #ifdef STM32F10X_CL __IO uint32_t AHBRSTR; __IO uint32_t CFGR2; #endif /// STM32F10X_CL/ } RCC_TypeDef; #define PERIPH_BASE ((uint32_t)0x40000000) //!< SRAM base address in the bit-band region #define AHBPERIPH_BASE (PERIPH_BASE + 0x20000) #define RCC_BASE (AHBPERIPH_BASE + 0x1000) #define RCC ((RCC_TypeDef *) RCC_BASE) */ void APClkInit(void) { RCC->APB2ENR = GPIOA_EN; } /*typedef struct { __IO uint32_t CRL; __IO uint32_t CRH; // 配置 __IO uint32_t IDR; //
__IO uint32_t ODR; //
__IO uint32_t BSRR;// 清除和复位 __IO uint32_t BRR; // 清除 __IO uint32_t LCKR; } GPIO_TypeDef; IO 有8种模式 推挽输出 开漏输出 上拉输入 下拉输入 复用推挽 复用开漏 模拟输入 浮动输入 响应速度 2M 10M 50M这个不是IO的速度是指的IO响应的速度,算STM32 功耗设计吧 */ void GPIO_Init(void) { GPIOA->CRL = 0x01 << 16; // PA.4 10M OUTPP }
STM32 GPIO
最新推荐文章于 2024-05-14 23:04:23 发布