您的位置:網站首頁 > 電器維修資料網 > 正文 >
接近檢測的門限門限滯回設置的C程序代碼
★★★★★【文章導讀】:接近檢測的門限門限滯回設置的C程序代碼具體內容是:將接近檢測傳感器集成到系統后,一個經常遇到的問題是如何正確選擇接近檢測的門限,以便在用戶通話期間打開或關閉屏幕。門限設置須確保出現錯誤判斷的幾率非常低,而且能夠支持絕大多數使用者的情況。門限滯回例程#d…
來源: 日期:2013-12-18 14:01:17 人氣:標簽:
將接近檢測傳感器集成到系統后,一個經常遇到的問題是如何正確選擇接近檢測的門限,以便在用戶通話期間打開或關閉屏幕。門限設置須確保出現錯誤判斷的幾率非常低,而且能夠支持絕大多數使用者的情況。
門限滯回例程
#define MAX44000_ADDR0x94#define INT_STATUS_REG0x00#define OFF_THRESHOLD4600#define OFF_DELAY1#define ON_THRESHOLD4000#define ON_DELAY3uint8 screenStatus;// 0 means off, 1 means on/* i2cWriteBytes() Arguments:uint8 address - devICe addressuint8 start_reg - register where the first byte is writtenuint8 *data - data to writeuint8 nbytes - number of bytes to write Consecutively writes several bytes to some i2c device starting at some specified address -- implemented elsewhere*/void i2cWriteBytes(uint8 address,uint8 start_reg,uint8 *data,uint8 nbytes);/* MAX44000InterruptHandler()
以下代碼用于實現MAX44000 INT引腳的中斷處理,假設MAX44000的接近檢測傳感器設置為14位模式,并已使能中斷。此外,假設屏幕狀態初始化為1或0,詳細信息請參閱數據資料的寄存器說明部分。
*/void MAX44000InterruptHandler() {uint8 i2cData[3];i2cRead1Byte(MAX44000_ADDR,INT_STATUS_REG,&i2cData);if (i2cData&0x01 != 0)return;// check to make sure interrupt really fired// this simultaneously clears the interrupt flagif (screenStatus) {i2cData[0] = ON_DELAY;i2cData[1] = ON_THRESHOLD >> 8 & 0xBF; // set ABOVE = 0i2cData[2] = ON_THRESHOLD & 0xFF;} else {i2cData[0] = OFF_DELAY; i2cData[1] = OFF_THRESHOLD >> 8 | 0x40; // set ABOVE = 1i2cData[2] = OFF_THRESHOLD & 0xFF;} // set the new threshold depending on what the screen status was// set the delay and threshold after each interrupti2cWriteBytes(MAX44000_ADDR,0x0A,i2cData,3);return;} // MAX44000InterruptHandler
【看看這篇文章在百度的收錄情況】