Hello all,
a little newbe question:
Does everybody have a code example how to read data from an PCF8591 A/D converter over the i2c bus.
I have some problems with that. Always when I start reading with I2CREAD the Watchdog will reset the PIC.
Here my code:
' Switch comperator mode on all ports off
ADCON1 = %00000111
' LCD-Module settings
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD-RSBIT 4
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
DEFINE I2C_HOLD 0
DEFINE I2C_SLOW 1
SCL VAR PORTC.3 ' Clock pin
SDA VAR PORTC.4 ' Data pin
SAMPLE VAR BYTE ' Holds data from slave
CONTROL VAR BYTE
DEVICE1 VAR BYTE
CONTROL = %00000000
DEVICE1 = %10010100
Pause 100 ' Wait for LCD to start up
LCDOut $fe, 1, "I2C-TEST" ' Display
Pause 1000
loop:
' DEVICE 1
LCDOut $fe, 1, "DEVICE1: "
I2CRead SDA,SCL,CONTROL,DEVICE1,SAMPLE,timeout
LCDOUT SAMPLE
Pause 500
GoTo loop
timeout:
LCDOut $fe, 1
LCDOut $fe, $80, "timed out"
Pause 1000
GoTo loop
Thanks, Habasch
Bookmarks