Application Note AN114 Interfacing the X9408/X9418 XDCP to 8051 Microcontrollers by Applications Staff, This application note describes the routines for the control of an X9408 or X9418 digitally controllable potentiometer. The X9408/X9418 devices have a variety of different instructions that provide flexibility to the designer. Additionally, the nonvolatile nature of the device allows for stored wiper positions that can be retrieved after power cycles. The following code implements all of the available X9408/ X9418 instructions using a standard bi-directional bus protocol. Although the routines occupy less than 300 bytes of program memory, designers who won't need to implement all of the instructions can shorten the code by removing any unnecessary routines. However, this will necessitate the reassembly of the code. For those instructions which program the nonvolatile data registers (XFR_WCR, GXFR_WCR, & WRITE_DR), acknowledge polling has been implemented to determine an early completion of the internal write cycle. Although this is automatically handled by the routines, a word or two regarding the procedure should be informative. After issuing a start condition, the master sends a slave address and receives an acknowledge. It then issues an instruction byte to the X9408/X9418 and again receives an acknowledge. If necessary, it now transmits the data byte and receives a final acknowledge. The master must then initiate a stop condition which will cause the X9408/ X9418 to begin an internal write cycle. The X9408/X9418 pins go to high impedance until this internal cycle is complete. The master can now begin acknowledge polling by successively sending start conditions followed by "dummy" instructions. When the X9408/X9418 finally answers with an acknowledge, the internal write cycle has been completed. The master must then initiate a stop condition. After the next start condition, the X9408/X9418 is ready to receive further instructions. 5V 39 38 37 36 35 34 33 32 P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 21 22 23 24 26 26 27 28 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 17 16 29 30 11 10 RD WR PSEN ALE/P TXD RXD 80C51 EA/VP X1 31 19 R? 10K R? 10K U? X2 RESET 18 9 INT0 INT1 T0 T1 12 13 14 15 P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 1 2 3 4 5 6 7 8 17 7 19 18 5 8 20 SCL SDA VHO VWO VLO 3 4 2 VH1 VW1 VL1 10 11 9 VSS VH2 VW2 VL2 15 14 16 A3 A2 A1 A0 VH2 VW2 VL2 21 22 23 V+ V- 24 13 X9408 +5V -5V Figure 1. Connecting the X9408 to an 80C51 microcontroller AN114-1 Xicor Application Note In the code listing, an assumption was made that the code executes upon a reset of the microcontroller. That is, the code is loaded into low memory, however this can be changed with an ORG assembler directive. A simple MAIN program to exercise these routines is included in the code listing. In this listing, the commands cause an X9408/X9418 (at A3A2A1A0 = 0000) to be accessed and the WCR of EEPOT #2 to be rewritten with the value 43 (for wiper tap position #43). Then a 15 pulse decrement of the wiper tap is initiated, causing the selected WCR to be reduced to the value 28 (for wiper tap position #28). AN114 The issuing of other commands follows the same general procedure. In Figure 1, a representative hardware connection between the X9408 and an 8051 family microcontroller is shown. The pull-up resistors on the SDA and SCL lines are determined by the total capacitance of all of the devices connected to the bus, which is about 18pF. in this case, however these may not be necessary since I/O port pins on 8051 family devices have internal pull-ups. AN114-2