|
匠人按:匠人最近因为机缘巧合,接触了一下三星的8位单片机,小试一把,发现居然没有直接针对位的操作指令。这样一来写程序就非常麻烦了。为了便于写程序,匠人特意定义了以下四个宏:
//-------------------------------------------------------- //位操作 //范例: //Set_Bit(P0,0); //P00=1 //Clr_Bit(P0,0); //P00=0 //Com_Bit(P0,0); //P00=!P00 //if(Test_Bit(P0,0)) Set_Bit(P0,1) ; //如果P00=1,则P01=1 //-------------------------------------------------------- #define Set_Bit(byte,bit) (byte|=(1<<bit)) //置位 #define Clr_Bit(byte,bit) (byte&=~(1<<bit)) //清零 #define Com_Bit(byte,bit) (byte^=(1<<bit)) //取反 #define Test_Bit(byte,bit) (byte&(1<<bit)) //测试
|