c - 我们在嵌入式 c 或嵌入式 c++ 中有 '@' 运算符吗?如果是,请向我解释以下代码?

标签 c embedded pic hi-tech-c

代码:

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/

相关文章:

c - Microchip PIC 周期寄存器 PR2

c - XC8 错误 224 : illegal # directive (first line)

C中的条件表达式

c - 当我要将 uint32 变量与 sint32 变量相乘时,为什么我会出错?

c - 我怎样才能开始微 Controller 编程?

embedded - 使用 EXTI 线进行软件中断

microcontroller - 读取 PIC18 上输入引脚的状态

c - 从指针数组获取值 - 通过引用调用

c++ - "make"是否知道如何在子目录中搜索包含文件?

c - 如何仅使用 x 和 y 位置更改 RGB 值