PIC单片机 C编程技巧(15)
发布时间:2021-06-06
发布时间:2021-06-06
void main(){ char myvar; myvar=0B10101010; a=testbit(myvar,0); setbit(myvar,0); a=testbit(myvar,0); clrbit(myvar,5); b=testbit(myvar,5); if(!testbit(myvar,3)) a=255; else a=100; while(1){;} } 四:用标准C的共用体来表示: 用标准C的共用体来表示: #i nclude<pic.h> union var{ unsigned char byte; struct { unsigned b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1; } bits; }; char a,b; void main(){ static union var myvar; myvar.byte=0B10101010; a=myvar.bits.b0; b=myvar.bits.b1; if(myvar.bits.b7) a=255; else a=100; while(1){;}