- C/C++ code
include <reg52.h>#include <intrins.h>sbit beep = P2^3;void delay();void main(){ unsigned char b; unsigned char tmp; b = 1; tmp = 0xfe; while (1) { P1 = tmp; beep = 0; delay(); tmp = _crol_(tmp,b); beep = 1; delay(); }}void delay(){ unsigned int i, j; for (i = 0; i < 500; i++) for (j = 0; j < 500; j++) ;}
问题是为什么不能把
- C/C++ code
sbit beep = P2^3;
谢谢大家
------解决方案--------------------
在keil的帮助文件里面可以找到原因!
[code=C/C++][/code]
Note:
1、Not all SFRs are bit-addressable. Only those SFRs whose address is evenly divisible by 8 are bit-addressable. The lower nibble of the SFR's address must be 0 or 8. For example, SFRs at 0xA8 and 0xD0 are bit-addressable, whereas SFRs at 0xC7 and 0xEB are not. To calculate an SFR bit address, add the bit position to the SFR byte address. So, to access bit 6 in the SFR at 0xC8, the SFR bit address would be 0xCE (0xC8 + 6).
2、Special function bits represent an independent declaration class that may not be interchangeable with other bit declarations or bit fields.
The sbit data type declaration may be used to access individual bits of variables declared with the bdata memory type specifier. Refer to Bit-addressable Objects for more information.
3、sbit variables may not be declared inside a function. They must be declared outside of the function body.