标题: 还是linux下的sdcc问题,请大佬给予指导 [打印本页]

作者: hyq1979    时间: 2020-10-8 13:00
标题: 还是linux下的sdcc问题,请大佬给予指导
数据类型扩充:
1、sfc:特殊功能寄存器声明
举例:
__sfc __at 0x80 led;
将P0口声明为led

#define led P0;
将P0口宏预处理为led

2、sbit:特殊功能位声明
举例:
__sbit __at 0x80 led;
将P0_0口声明为led

问题点:

sbit怎么用#define?
另外bit取反为什么不能用,比如led=~led就报错。



作者: hyq1979    时间: 2020-10-8 14:07
报错内容为:
using ~ on bit/bool/unsigned char variables can give unexpected results due to promotion to int
作者: hyq1979    时间: 2020-10-8 14:48
取反确实看的教材没写清楚,正确方式为:
!符号是位取反(是“位”),只针对位变量。
~符号是按位取反(是“按位”),针对字节变量
作者: straywind    时间: 2021-9-13 16:10
在“#define led P0”可用前,一定需要 #include 一个定义了IO口的头文件,例如你 #include "stc15fxx.h" 之后就可以直接 #define led P0了,要注意没有分号。
在stc15fxx.h 里会有如下:
#define _P0 0x80
SFR(P0, 0x80);          //1111,1111 端口0
SBIT(P00, _P0, 0);
SBIT(P01, _P0, 1);
SBIT(P02, _P0, 2);
SBIT(P03, _P0, 3);
SBIT(P04, _P0, 4);
SBIT(P05, _P0, 5);
SBIT(P06, _P0, 6);
SBIT(P07, _P0, 7);




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1