|
本帖最后由 robinsonlin 于 2021-3-4 14:37 編輯
//--------對(duì)于每個(gè)端口,定義一個(gè)結(jié)構(gòu)體
struct ADDR
{
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;
}addrP0;
//---------定義一個(gè)狀態(tài)變量
unsigned char Dev_AddrP0 ;
//---------端口狀態(tài)讀取函數(shù)
unsigned char ReadDevAddrP0(void)
{
if(P0^0 == 1)addrP0.bit0 = 1;
else addrP0.bit0 = 0;
if(P0^1 == 1)addrP0.bit1 = 1;
elseaddrP0.bit1 = 0;
if(P0^2 == 1)addrP0.bit2 = 1;
else addrP0.bit2 = 0;
.........省略P0^3到P0^7的檢測(cè)語(yǔ)句
Dev_AddrP0 = (*((unsigned char*)&addrP0)) & 0xff;
return Dev_AddrP0;
}
檢測(cè)函數(shù)返回的值,就是端口對(duì)于IO口的狀態(tài) |
|