原来自定义寄存器后,不用包含任何头文件也可以,程序运行正常,有点好玩,就是格式不知道是否规范?真诚的希望大家能指点一下
//没有包含任何头文件
#define R32_GPIOB_CFGLR (*(unsigned long *)0x40010C00) //请问这样自定义行不行?是否规范?
#define R32_RCC_APB2PCENR (*(unsigned long *)0x40021018)
#define R32_RCC_CTLR (*(unsigned long *)0x40021000)
#define R32_GPIOB_OUTDR (*(unsigned long *)0x40010C0C)
#define B7_H R32_GPIOB_OUTDR |= 1<<7 //高电平,驱动LED闪烁
#define B7_L R32_GPIOB_OUTDR &= ~(1<<7) //低电平
unsigned long u32a;
int main(void)
{
R32_RCC_CTLR = 0x00000081; //使能内部HSI振荡器8MHz,时钟微调默认
R32_RCC_APB2PCENR |= 8; //使能PB端口时钟
R32_GPIOB_CFGLR &= 0x0FFFFFFF; //清空位PB7
R32_GPIOB_CFGLR |= 0x30000000; //位PB7推换输出,最快50MHz
while(1)
{
B7_H;
for(u32a=0; u32a<3000000; u32a++) asm("nop");
B7_L;
for(u32a=0; u32a<3000000; u32a++) asm("nop");
}
}
|