unsigned long ReadTempHum(){ unsigned int Timer_Cnt; unsigned long Result; DATA_PxDIR |= DATA; DATA_PxOUT &= ~DATA; __delay_cycles(19000); //至少18ms DATA_PxDIR &= ~DATA; while(DATA_PxIN & DATA); DATA_PxIES |= DATA; DATA_PxIFG &= ~DATA; while(!(DATA_PxIFG & DATA)); DATA_PxIFG &= ~DATA; for(char k=0;k<32;k++) { Result <<= 1; TACTL |= TACLR; while(!(DATA_PxIFG&DATA)); DATA_PxIFG &= ~DATA; Timer_Cnt = TAR; if(Timer_Cnt>90) { Result |= 1; } } for(char k=0;k<8;k++) { Cal <<= 1; TACTL |= TACLR; while(!(DATA_PxIFG&DATA)); DATA_PxIFG &= ~DATA; Timer_Cnt = TAR; if(Timer_Cnt>90) { Cal |= 1; } } return Result;}调试可行。我程序中没有加超时检测,可能会死循环。仅供参考。