写了一个stm32f10x的关于位绑定的程序,但是一直出现错误警告,跟人感觉是宏定义不起作用的原因,但是不知道问题出现在哪里
/*******************程序**********************/
/******************************************************
SRAM区 0x2000 0000 ~ 0x200f ffff 1M
AliasAddr = (0x22000000 + (A-0x2000 0000)*8+n)*4
= 0x22000000 + (A-0x2000 0000)*32+n*4
片上外设0x4000 0000 ~ 0x400 ffff 1M
AliasAddr = 0x42000000 + ((A-0x4000 0000)*8+n)*4
= 0x42000000 + (A-0x4000 0000)*32+n*4
******************************************************/
#include <stm32f10x.h>
#define GPIOA_ODR_A (GPIOA_BASE+0x0C)
#define GPIOA_IDR_A (GPIOA_BASE+0x08)
#define BitBand(Addr,BitNum) *((volatile unsignede long *)(Addr&0xf0000000(0x2000000 + (Addr&0xfffff)<<5+BitNum<<2)))//位绑定公式
#define PAout(n) BitBand(GPIOA_ODR_A,n)
#define PAin(n) BitBand(GPIOA_IDR_A,n)
int main()
{
u32 *PA03 = (u32 *)(0x42000000 + (0x4001080C-0x40000000)*32+3*4);
u32 *PAI11 = (u32 *)(0x42000000 + (0x40010808-0x40000000)*32+11*4);
//也可以写为u32 *PAI11 = (u32 *)(0x42000000 + (0x40010809-0x40000000)*32+3*4);
GPIOA->CRL = 0X33333333;
GPIOA->CRH = 0X44444444;
while(1)
{
//A = GPIOA_BASE+ODR偏移地址=GPIOA_BASE+0x0C n=3
//A = GPIOA_BASE+IDR偏移地址=GPIOA_BASE+0x08 n=11
if(*PAI11 == 1)
*PA03 = 1;
//GPIOA->ODR = GPIOA->ODR | 0x80;
else
*PA03 = 0;
//GPIOA->ODR = GPIOA->ODR & (~0x80);
if(PAin(9) == 1)
PAout(1) = 1;
else
PAout(1) = 0;
}
}
|