STM32位绑定失败
时间:10-02
整理:3721RD
点击:
如题,当我绑定之后,想要PA的第8脚输出高电平,但是不成功。求解答。附上代码,请找错误。在线等、、、、
#include <stm32f10x_lib.h>
#define GPIOA_ODR_A (GPIOA_BASE+0X0C)
#define bitband(addr,n) *((volatile unsigned long *)(addr & 0xf0000000 +0x2000000 + (addr & 0x0fffffff) << 5 + n <<2))
#define PAO(n) bitband(GPIOA_ODR_A,n)
int main(void)
{
RCC->CR |= 0X00010000; //HSE打开
while(!(RCC->CR & 0X00020000)); //判断HSE稳定
FLASH->ACR|=0x32; //FLASH 2个延时周期
RCC->CFGR |= 0X001D0000; //配置PLL 选择HES,9倍频
RCC->CR |= 0X01000000; //打开PLL
while(!(RCC->CR & 0X02000000)); //判断PLL稳定
RCC->CFGR |= 0X00000002; //配置系统时钟为PLL
RCC->APB2ENR |= 0X000001FC; //使能GPIOA~G时钟
GPIOA->CRL=0X11111111;
while(1)
{
GPIOA->ODR = 0X0F;
PAO(8) = 1;
}
}其中GPIOA->ODR = 0X0F;正常,就是下面的PAO(8) = 1;不显示。
#include <stm32f10x_lib.h>
#define GPIOA_ODR_A (GPIOA_BASE+0X0C)
#define bitband(addr,n) *((volatile unsigned long *)(addr & 0xf0000000 +0x2000000 + (addr & 0x0fffffff) << 5 + n <<2))
#define PAO(n) bitband(GPIOA_ODR_A,n)
int main(void)
{
RCC->CR |= 0X00010000; //HSE打开
while(!(RCC->CR & 0X00020000)); //判断HSE稳定
FLASH->ACR|=0x32; //FLASH 2个延时周期
RCC->CFGR |= 0X001D0000; //配置PLL 选择HES,9倍频
RCC->CR |= 0X01000000; //打开PLL
while(!(RCC->CR & 0X02000000)); //判断PLL稳定
RCC->CFGR |= 0X00000002; //配置系统时钟为PLL
RCC->APB2ENR |= 0X000001FC; //使能GPIOA~G时钟
GPIOA->CRL=0X11111111;
while(1)
{
GPIOA->ODR = 0X0F;
PAO(8) = 1;
}
}其中GPIOA->ODR = 0X0F;正常,就是下面的PAO(8) = 1;不显示。
((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
注意运算符与优先级
试一下使用这个宏定义
#define BIT_0(PORT,x) (PORT &= (~(1<<x)))
#define BIT_1(PORT,x) (PORT |= (1<<x))
是的,后来我也发现了
是前面的同学的答案,我试过了,改了之后就对了