PCF8591 I2C _ADC read library for LPC11U24
Dependents: mbed_PCF8591_LPC11U24_ADC_RAJESH_NIELIT_CALICUT
Revision 0:3c4cd2f477ea, committed 2016-06-15
- Comitter:
- rajeshnielit
- Date:
- Wed Jun 15 21:31:05 2016 +0000
- Commit message:
- PCF8591_ADC Read for LPC11U24 _ver01
Changed in this revision
PCF8591.h | Show annotated file Show diff for this revision Revisions of this file |
PCF8591_ADC.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PCF8591.h Wed Jun 15 21:31:05 2016 +0000 @@ -0,0 +1,20 @@ + +#include "mbed.h" +#define PCF8591_ADDR 0x90 +#define ADC_CH00 0x00 +#define ADC_CH01 0x01 +#define ADC_CH02 0x02 +#define ADC_CH03 0x03 + +class PCF8591 { +public: + + PCF8591(I2C *i2c); + +uint8_t ADC_read(uint8_t); + +protected: + I2C *_i2c; //I2C bus reference + uint8_t _slaveAddress; //I2C Slave address of device + +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PCF8591_ADC.cpp Wed Jun 15 21:31:05 2016 +0000 @@ -0,0 +1,27 @@ + + #include "mbed.h" +#include "PCF8591.h" + + +/** Create a PCF8591 AD and DA object using a specified I2C bus and slaveaddress + * + * @param I2C &i2c the I2C port to connect to + * @param char deviceAddress the address of the PCF8591 + */ +PCF8591::PCF8591(I2C *i2c) : _i2c(i2c) { + + _slaveAddress = PCF8591_ADDR; + +} + + +uint8_t PCF8591::ADC_read(uint8_t channel) { + +char cmd; + char anaval; + cmd=channel; + _i2c->write( _slaveAddress, &cmd, 1 ); + _i2c->read( _slaveAddress, &anaval, 1 ); + return anaval; + +};