5月21日
bootloader程序写一个寄存器时,由于没有使用volatile产生了错误,一直不能理解.
程序如下:
unsigned int data;
unsigned int *data_w;
data_w = 0xbb800800; /*0xbb800800是一个器件寄存器地址*/
data = 0x1234;
*data_w = data;
printf("0xbb800800:%08x\r\n", *((unsigned int*)0xbb800800));
printf("0xbb800800:%08x\r\n", *((unsigned int*)0xbb800800));
打印结果如下:
0xbb800800:0x1234
0xbb800800:0x14
如果在变量定义前都加上volatile打印结果就正常: