fixed operator precedance bug
[fw/sdcc] / device / examples / ds390 / i2c390 / pcf8591.c
1 #include "i2clole.h"
2 #include "pcf8591.h"
3
4 unsigned char ReadPCF8591(char address, char channel) {
5   
6   unsigned char id=PCF8591_ID+(address<<1);
7   
8   while (!I2CReset()) {
9     //fprintf (stderr, "I2C bus busy, retrying.\n");
10   }
11   
12   // set output enable, no autoincrement
13   i2cTransmitBuffer[0]=(channel&0x03)+0x40;
14
15   // read 2 bytes, since the first one is the old value
16   if (I2CSendReceive(id, 1, 2))
17     return 0;
18
19   return i2cReceiveBuffer[1];
20 }
21