| Electronic Components Datasheet Search |
|
SFH7773 Datasheet(PDF) 20 Page - OSRAM GmbH |
|
|
|||||||||||||||||||||||||||||
SFH7773 Datasheet(HTML) 20 Page - OSRAM GmbH |
|
20 / 23 page ![]() 12.1.3 Subroutine I2C_w_2_r_1 void I2C_w_2_r_1 (unsigned char addr, unsigned char com) { unsigned char var; OpenI2C (MASTER, SLEW_ON); SSPADD = 0x27; StartI2C (); IdleI2C (); var = WriteI2C(addr); if (var == 0) read_s++; if (var == -1) read_c++; if (var == -2) read_ac++; if (var < 0) goto stop; var = WriteI2C(com); if (var == 0) read_s++; if (var == -1) read_c++; if (var == -2) read_ac++; if (var < 0) goto stop; RestartI2C (); // generates I2C bus restart condition IdleI2C (); var = WriteI2C(addr+1); if (var == 0) read_s++; if (var == -1) read_c++; if (var == -2) read_ac++; if (var < 0) goto stop; Content = 0; Content = ReadI2C (); SSPCON2bits.ACKDT = 1; // No master Acknowledge to terminate sequence SSPCON2bits.ACKEN = 1; // sending No Acknowledge bit PIR1bits.SSPIF = 0; while (SSPCON2bits.ACKEN == 1); PIR1bits.SSPIF = 0; // waiting till NA causes interrupt stop: StopI2C (); CloseI2C (); } 12.2 Operating the PS Below is a small C-code for the main program to operate the proximity sensor of the SFH 7773. The two subroutines, I2C_w_3 and I2C_w2_r1 are the same as above (see Sec. 12.1.2 and 12.1.3). C-code for main program: sfh_address = 0x38; // address of SFH 7773 I2C_w_3 (sfh_address*2, 0x81, 0x03); // initialize PS of the SFH 7773 I2C_w_3 (sfh_address*2, 0x82, 0x1E); // set PS LED current to 200 mA I2C_w_2_r_1 (sfh_address*2, 0x8F); // read data byte of PS, register 0x8F PS = Content; 12.3 Operating the ALS and PS in Interrupt Mode The small C-code below operates the SFH 7773 in the interrupt mode. The ALS and PS are in free-running mode. The interrupt event can occur through an ALS or PS event. The limits for ALS (LB_LL, HB_LL, LB_HL, HB_HL) and PS (Prox_Limit) are set within the program. After the interrupt has triggered the microcontroller the relevant sensor is determined and the ALS or PS value is read out. December 12, 2011 page 20 of 23 |
|
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |