c语言的bit类型

c语言的bit类型,第1张

C语言中bit类型是“位”数据类型,一般在嵌入式软件中应用较多,用于IO口的控制,可以是单独申明位变量,也可以申请位结构数据类型,比如:

struct st_flash {                                           /* struct FLASH */

union {                                       /* FLMCR1       */

unsigned char BYTE            /*  Byte Access */

struct {                                  /*  Bit  Access */

unsigned char FWE :1      /*    FWE       */

unsigned char SWE1:1      /*    SWE1      */

unsigned char ESU1:1      /*    ESU1      */

unsigned char PSU1:1      /*    PSU1      */

unsigned char EV1 :1      /*    EV1       */

unsigned char PV1 :1      /*    PV1       */

unsigned char E1 启档瞎 :1       /*    E1        */

unsigned char P1  :1       /*    P1        */

}      BIT

}         FLMCR1

union {                                 /* FLMCR2       */

unsigned char BYTE               /*  Byte Access */

struct {                                     /*  Bit  Access */

unsigned char FLER:1      /*    FLER      */

unsigned char SWE2:1      /*    SWE2      */

unsigned char ESU2:1      /*    ESU2      */

unsigned char PSU2:1      /*    PSU2      */

unsigned char EV2 :1      /*    EV2       */

unsigned char PV2 :1      /*    PV2       */

unsigned char E2  :1      /*    E2        */

unsigned char P2  :1      /*    P2        */

}      BIT

}         FLMCR2

union {                                 /* EBR1         */

unsigned char BYTE               /*  Byte Access */

struct {                          /*  Bit  Access */

unsigned char EB7:1       /*    EB7       */

unsigned char EB6:1       /*    EB6       */

unsigned char EB5:1       /*    EB5       */

unsigned char EB4:1       /*    EB4       */

unsigned char EB3:1       /*    EB3       */

unsigned char EB2:1       /*    EB2       */

unsigned char EB1:1       /*    EB1       */

unsigned char EB0:1       /*    EB0       */

} 蠢唤     BIT

}         EBR1

union {            悄空                     /* EBR2         */

unsigned char BYTE               /*  Byte Access */

struct {                          /*  Bit  Access */

unsigned char EB15:1      /*    EB15      */

unsigned char EB14:1      /*    EB14      */

unsigned char EB13:1      /*    EB13      */

unsigned char EB12:1      /*    EB12      */

unsigned char EB11:1      /*    EB11      */

unsigned char EB10:1      /*    EB10      */

unsigned char EB9 :1      /*    EB9       */

unsigned char EB8 :1      /*    EB8       */

}      BIT

}         EBR2

}

可以试一下这个闷迹:先建一个头文件如:thehead.h(是保存为.h类型的)内空如下:

#ifndef

HEAD_H

#define

HEAD_H

uchar

bdata

OUT_temp

sbit

AA

=

OUT_temp^0

sbit

BB

=

OUT_temp^1

sbit

CC

=

OUT_temp^2

sbit

DD

=

OUT_temp^3

sbit

EE

=

OUT_temp^4

sbit

FF

=

OUT_temp^5

sbit

GG

=

OUT_temp^6

sbit

HH

=

OUT_temp^7

#endif

再在每要用到上面内蚂型并容的文件中加#include"租备thehead.h"语句。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12219024.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存