@符号在C变量声明 [英] @ sign in C variable declaration

查看:136
本文介绍了@符号在C变量声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现通过pic1250.h的名称PIC单片机这个头文件,我无法得到它使用的一些语法的窍门。

I found this header file for PIC microcontrollers by the name of pic1250.h and I'm unable to get the hang of some syntax used in it.

该文件的来源是:

/*
 *  Header file for the Microchip 
 *  PIC 12c508 chip 
 *  PIC 12c509 chip
 *  Baseline Microcontrollers
 */

static volatile unsigned char   RTCC    @ 0x01;
static volatile unsigned char   TMR0    @ 0x01;
static volatile unsigned char   PCL @ 0x02;
static volatile unsigned char   STATUS  @ 0x03;
static          unsigned char   FSR @ 0x04;
static volatile unsigned char   OSCCAL  @ 0x05;
static volatile unsigned char   GPIO    @ 0x06;

static          unsigned char control   OPTION  @ 0x00;
static volatile unsigned char control   TRIS    @ 0x06;

/*  STATUS bits */
static bit  GPWUF   @ (unsigned)&STATUS*8+7;
static bit  PA0 @ (unsigned)&STATUS*8+5;
static bit  TO  @ (unsigned)&STATUS*8+4;
static bit  PD  @ (unsigned)&STATUS*8+3;
static bit  ZERO    @ (unsigned)&STATUS*8+2;
static bit  DC  @ (unsigned)&STATUS*8+1;
static bit  CARRY   @ (unsigned)&STATUS*8+0;

/*  OPTION bits */
#define     GPWU    (1<<7)
#define     GPPU    (1<<6)
#define     T0CS    (1<<5)
#define     T0SE    (1<<4)
#define     PSA (1<<3)
#define     PS2 (1<<2)
#define     PS1 (1<<1)
#define     PS0 (1<<0)

/*  OSCCAL bits */
static bit  CAL7    @ (unsigned)&OSCCAL*8+7;
static bit  CAL6    @ (unsigned)&OSCCAL*8+6;
static bit  CAL5    @ (unsigned)&OSCCAL*8+5;
static bit  CAL4    @ (unsigned)&OSCCAL*8+4;

/*  GPIO bits   */
static bit  GP5 @ (unsigned)&GPIO*8+5;
static bit  GP4 @ (unsigned)&GPIO*8+4;
static bit  GP3 @ (unsigned)&GPIO*8+3;
static bit  GP2 @ (unsigned)&GPIO*8+2;
static bit  GP1 @ (unsigned)&GPIO*8+1;
static bit  GP0 @ (unsigned)&GPIO*8+0;

#define CONFIG_ADDR 0xFFF
#define FOSC0       0x01
#define FOSC1       0x02
#define WDTE        0x04
#define CP      0x08
#define MCLRE       0x0F

我无法了解整个修改器,数据类型@声明出头。是否有人可以帮助我吗?我在此只是个新手。

I'm unable to understand the whole modifer-datatype @ declaration-something. Can someone please help me out? I'm just a newbie at this.

推荐答案

这是一个编译器扩展。

从PIC MPLAB XC8 编译器文档(重点煤矿):

From PIC MPLAB XC8 compiler documentation (emphasis mine):

5.5.4绝对变量

大多数变量可以在一个绝对地址与下面的声明位于
  构建@地址
,其中地址是在内存中的位置在哪里
  变量是被定位。这样的变量被称为绝对变量

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.

5.5.4.1绝对变量数据存储器

5.5.4.1 ABSOLUTE VARIABLES IN DATA MEMORY

绝对变量主要用于与等同一个C标识符的地址
  特殊功能寄存器,但可以用来放置普通变量在绝对
  解决数据存储。

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.

例如:

挥发性unsigned char型Portvar @ 0×06;

将声明一个称为Portvar变量位于在数据存储器06h中。编译器
  会预留存储该对象(如果地址落入通用RAM)和
  将等同变量的标识符到该地址。

will declare a variable called Portvar located at 06h in the data memory. The compiler will reserve storage for this object (if the address falls into general-purpose RAM) and will equate the variable’s identifier to that address.

注意,MPLAB XC8是不是有同样的 @ 结构将对象放置在特定的存储位置仅有的编译器。

Note that MPLAB XC8 is not the only compiler to have the same @ construct to place an object in the specific memory location.

另一个公知的编译器是Freescale codeWarrior(至少HCS08)

Another well known compiler is Freescale CodeWarrior (at least for HCS08).

另外一个是IAR C编译器(至少MSP430和AVR)。

Another one is IAR C Compiler (at least for MSP430 and AVR).

这篇关于@符号在C变量声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆