语句sbit wei2=P2^6中的^是异或运算符吗

语句P2^6=1;错误,必须在申明sbit wei2=P2^6;才正确。
为什么P2^6=1;是错误的呢?这里的^是按位异或运算符可以理解,但是语句“sbit wei2=P2^6;”中的^什么类型运算符?
谢谢

sbit这个类型定义了SFR中的一个bit, 使用操作符^, 这里是容易引起疑惑的一个地方, 这个符号仅仅在代码变量声明的地方可用, 代表了SFR中这个bit的位置.

在程序当中, 这个符号才是标准的bit异或操作符(XOR Operator).

The character ^ is used to denote the bit position in the byte address of the SFR. This syntax is only valid for Declaration code lines. If used inside the program, then the ^ operator is the standard bitwise xor operator from the standard C language (not specific to C51).

//方式1和2: 前面的sfr-name/sfr-address是其基础地址, 一定是要可以被8整除的, 例如0xD0, 0xA8, 后面的bit-position取值可以是0~7
sbit name = sfr-name ^ bit-position;
sbit name = sfr-address ^ bit-position;

//方式3: 必须是0x80-0xFF之间的一个值, 例如0xD2, 0xD7, 0xAF
sbit name = sbit-address;

```
其中

  • name 变量名
  • sfr-name 已经定义的SFR变量
  • bit-position 在SFR变量中的位置
  • sfr-address SFR的地址
  • sbit-address 此bit的地址

什么语言?VB的话,是乘方,C才是异或