Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we have '@' operator in embedded c or embedded c++ ? If yes please explain me the below code?

code:

static volatile unsigned char   TMR0    @ 0x01;

static volatile unsigned char   PORTA   @ 0x05;

static volatile unsigned char   PORTB   @ 0x06;

static volatile unsigned char   PORTC   @ 0x07;

This code is from HT-PICC compiler pic.h library file for PIC16F877A

I understand what static volatile and other keyword means . Here Timer0 register address is 0x01 but why they use @ in front of it? Does it have something to do with pointer?

like image 222
Electro Voyager Avatar asked Dec 07 '22 13:12

Electro Voyager


1 Answers

It's a common compiler extension in many embedded compilers, which allows you to place variable in absolute memory address.

From HI-TECH C compiler manual:

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.

In your example:

static volatile unsigned char   TMR0    @ 0x01;

TMR0 is presumably 8-bit unsigned hardware register which exists at address 0x01.

like image 72
user694733 Avatar answered Dec 31 '22 01:12

user694733