' {$STAMP BS2p} ' {$PBASIC 2.5} ' ' Example program to test I2C-DAC (I2C 8-bit Digital-to-Analog Converter) unit. ' The program configures the device as the Normal Operation mode (PD1 = 0 and PD0 = 0). ' Analog output is set by user inputer HEX value from the debug terminal. ' ' Setup: A0=0 ' ' Document: DAC5571 datasheet ' Updated: July 21, 2007 ' E-mail: support@gravitech.us ' MicroResearch, Gravitech Group ' (C) Copyright 2007 All Rights Reserved ' ' NOTE: For BS2P, this program only work with firmware rev. 1.3 or grater. #IF ($STAMP < BS2P) #THEN #ERROR "Program requires BS2p, BS2pe, or BS2px." #ENDIF '************************************************************ SDA PIN 0 ' I2C SDA pin SCL PIN SDA+1 ' I2C SCL pin I2C_WR CON $98 ' I2C write address I2C_RD CON $99 ' I2C read address DACVAL VAR Byte ' Store A/D value DAT0 VAR Byte ' I2C data DAT1 VAR Byte ' I2C data MAIN: DEBUG CR, "Enter D/A value in HEX (00-FF): " ' Display prompt for D/A value DEBUGIN HEX2 DACVAL ' Get DAC data from user DAT1 = DACVAL >> 4 ' Ctrl/MS-Byte (PD1&PD0 = 0) DAT0 = DACVAL << 4 ' LS-Byte I2COUT SDA,I2C_WR,[DAT1,DAT0] ' Setup DAC GOTO MAIN END