在建立编译环境的时候用typedef定义了指向volatile 单元的指针,最后终于发现行不通。
typedef char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;
typedef char * p8;
typedef unsigned short * p16;
typedef unsigned int * p32;
typedef char volatile * vp8;
typedef unsigned short volatile * vp16;
typedef unsigned int volatile * vp32;
原来上述三行定义为
typedef volatile p8 vp8;
typedef volatile p16 vp16;
typedef volatile p32 vp32;
蓝色的部分语法通过了,但是volatile根本不起作用。
另外提一下寄存器还可以这样定义:
typedef uint32_t special_register;
{
special_register ULCON;
special_register UCON; /*控制*/
special_register USTAT; /*状态*/
special_register UTXBUF; /*发送缓冲*/
special_register URXBUF; /*接收缓冲*/
special_register UBRDIV;
};
http://xjbclz.banzhu.net/article/xjbclz-16-880646.html
#define UART0 (( UART volatile *) 0x03FFD000)
另一种是通过常量指针:
UART volatile *const UART0 = ( UART volatile *)0x03FFD000;