代码如下:
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x02000000+((addr & 0x00FFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
#define GPIOC_ODR_Addr (GPIOC+0xC) //0x4001100C
#define GPIOC_IDR_Addr (GPIOC+0x8) //0x40011008
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n)
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n)
int main(void)
{
systick_config();
GPIO_Config();
while(1)
{
PCout(12) = 1; //?
delay_1ms(2000);
PCout(12) = 0; // ?
delay_1ms(1000);
}
}
运行到主循环就会进入硬件故障 |