XC8变数宣告问题

2020-02-06 10:08发布

请教高人
在C51里可用以下方式宣告
unsigned char bdata home;
sbit father     = home^0;
sbit mother1 = home^1;
sbit mother2 = home^2;
.
.
.

而在XC8里
要如何宣告?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
DIY7777
2020-02-06 18:15
本帖最后由 DIY7777 于 2015-12-5 10:54 编辑

sbit是c51用的
在xc8当然不会直接用
xc8下需改成bit
如下
unsigned char bdata home;
bit father     = home^0;
bit mother1 = home^1;
bit mother2 = home^2;
.
但编译后出错
错误讯息指示这个宣告不正确

当然
XC8是有宣告方式
如下例子
// Register: PORTA
extern volatile unsigned char PORTA @ 0x005;
#ifndef _LIB_BUILD
asm("PORTA equ 05h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned RA0 :1;
unsigned RA1 :1;
unsigned RA2 :1;
unsigned RA3 :1;
unsigned RA4 :1;
unsigned RA5 :1;
unsigned RA6 :1;
unsigned RA7 :1;
};
} PORTAbits_t;
extern volatile PORTAbits_t PORTAbits @ 0x005;

but
太复杂
所以请教高人
XC8有无较简单的方式宣告

一周热门 更多>