代码:
static volatile unsigned char TMR0 @ 0x01;
static volatile unsigned char PORTA @ 0x05;
static volatile unsigned char PORTB @ 0x06;
static volatile unsigned char PORTC @ 0x07;
此代码来自PIC16F877A的HT-PICC编译器pic.h库文件
我理解 static volatile 和其他关键字的含义。
这里 Timer0 寄存器地址是 0x01 但为什么他们在它前面使用 @
?跟指针有关系吗?
最佳答案
它是许多嵌入式编译器中常见的编译器扩展,允许您将变量放置在绝对内存地址中。
来自 HI-TECH C 编译器手册:
3.5.4 Absolute Variables
Most variables can be located at an absolute address by following its declaration with the construct @ address, where address is the location in memory where the variable is to be positioned. Such a variables is known as an absolute variables.
3.5.4.1 ABSOLUTE VARIABLES IN DATA MEMORY
Absolute variables are primarily intended for equating the address of a C identifier with a special function register, but can be used to place ordinary variables at an absolute address in data memory.
在你的例子中:
static volatile unsigned char TMR0 @ 0x01;
TMR0
大概是 8 位无符号硬件寄存器,位于地址 0x01。
关于c - 我们在嵌入式 c 或嵌入式 c++ 中有 '@' 运算符吗?如果是,请向我解释以下代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52753296/