单片机c语言外部变量问题
我定义了一个位域结构体和共用体的嵌套函数,因为多个程序中都要调用到这个函数,所以想在主函数中声明其为外部变量,这样就可以在被调函数中引用了,我声明方式与声明一般的变量方式...
我定义了一个位域结构体和共用体的嵌套函数,因为多个程序中都要调用到这个函数,所以想在主函数中声明其为外部变量,这样就可以在被调函数中引用了,我声明方式与声明一般的变量方式一样,在.c文件中定以在.h文件中进行声明,但是怎么声明都不通过。。望大侠们多指教,共用结构体如下:
union unxs
{
struct stxs
{
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
} jg_byte;
unsigned char gy_byte;
} lcd_wz;
要是好的话,还会再加分,谢谢了先。 展开
union unxs
{
struct stxs
{
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
} jg_byte;
unsigned char gy_byte;
} lcd_wz;
要是好的话,还会再加分,谢谢了先。 展开
展开全部
你在头文件中定义类型
typedef union unxs
{
struct stxs
{
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
} jg_byte;
unsigned char gy_byte;
} UNXS;
然后在C文件里定义变量
UNXS lcd_wz;
最在在要引用的地方或是头文件里声明一下
extern UNXS lcd_wz;就可以了。
typedef union unxs
{
struct stxs
{
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
} jg_byte;
unsigned char gy_byte;
} UNXS;
然后在C文件里定义变量
UNXS lcd_wz;
最在在要引用的地方或是头文件里声明一下
extern UNXS lcd_wz;就可以了。
展开全部
#IFNDEF ABC_UNION
#DEFINE ABC_UNION
union unxs
{
struct stxs
{
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
} jg_byte;
unsigned char gy_byte;
} lcd_wz;
#ENDIF
#DEFINE ABC_UNION
union unxs
{
struct stxs
{
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
} jg_byte;
unsigned char gy_byte;
} lcd_wz;
#ENDIF
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询