'********************************************************************************** ' READING OUT THE FOUR ADC's OF A PCF 8591 WITH AN ATMEGA 8 AND BASCOM '********************************************************************************** ' ' Connection diagram: ' _ _ ' (0V...+5V) ADC0 =| `-´ |= VDD (+5V) ' (0V...+5V) ADC1 =| P |= Aout (NC) ' (0V...+5V) ADC2 =| C |= Vref (+5V) ' (0V...+5V) ADC3 =| F |= Agnd (GND) ' ADDR0 (GND) =| 8 |= EXT (GND) ' ADDR1 (GND) =| 5 |= OSC (NC) ' ADDR2 (GND) =| 9 |= SCL (To Atmega 8 / Portd.4 + 10K pullup to +5V) ' VSS (GND) =|__1__|= SDA (To Atmega 8 / Portd.5 + 10K pullup to +5V) ' '********************************************************************************** $regfile = "m8def.dat" 'Atmega8-declarations $crystal = 3686400 $baud = 9600 Config Sda = Portd.5 Config Scl = Portd.4 Config I2cdelay = 10 Dim In0 As Byte Dim In1 As Byte Dim In2 As Byte Dim In3 As Byte Do I2cstart 'i2c start condition I2cwbyte &B10010000 'send pcf address (write) I2cwbyte &B01000101 'send control byte (auto-increment on, internal oscillator on) I2cstart 'repeated start condition I2cwbyte &B10010001 'send pcf addressieren (read) I2crbyte In0 , Ack 'read value of adc0 & acknowledge I2crbyte In1 , Ack '... I2crbyte In2 , Ack '... I2crbyte In3 , Nack 'read value of adc3 / don't acknowledge I2cstop 'i2c stop condition Print " 0>>" ; In0 ; " 1>>" ; In1 ; " 2>>" ; In2 ; " 3>>" ; In3; 'send values to serial port Waitms 500 Loop End