re: Reading a 12 Bit A/D David, I've always been hesitant to post code in this group because I use the Parallax assembler with 805x syntax and the code is usually `snipped' from an application that I've done and may not be optimized for other apps. Anyway, here is a `snippet' of code that I use to talk with a Maxim 186 12-Bit A/D with an 8-channel mux. It reads a variety of sensors and has been working fine for over a year. The conversion to Microchip's syntax should be easy. Note, I'm using a 16C74A with an external data bus and a 74HCT138 address decoder (BCS). I also talk to a variety of serial devices so I use a separate routine to pulse SCLK. Ignore the "!CS" stuff as you would have to see the overall design to make sense out of it. Basically, I send a control byte (in another routine) and read the 4 MSBs, then the 8 LSBs in 2 variables. - Tom -------- ; Read A/D Converter ; Entry: ; serdata = Control Byte/Channel Select ; Exit: ; Temp16L = LSB (Lower 8 Bits, B0-B7) ; Temp16H = MSB (Upper 4 Bits, B8-B11) Read_ADC AND RB,#CSMASK ; Set A/D CS Address Mask OR RB,#ADCS CLRB BCS ; Set !CS Low CALL Send_Data ; Send Control Byte SETB BCS ; Set !CS High CLR Temp16L ; Clear Temp 16 Bit register LSB CLR Temp16H ; Clear Temp 16 Bit register MSB :loop1 JNB ADBUSY,:loop1 ; Wait for Conversion MOV bcount,#4 ; Set Bit counter for 4 Bits CLRB BCS ; Set !CS Low :loop2 CALL SCLKP ; Pulse SCLK MOVB C,SDI ; Put MSB Bit in Carry RL Temp16H ; Rotate Carry into data buffer DJNZ bcount,:loop2 ; If not 4 Bits, get another MOV bcount,#8 ; Set Bit counter for 8 Bits :loop3 CALL SCLKP ; Pulse SCLK MOVB C,SDI ; Put MSB Bit in Carry RL Temp16L ; Rotate Carry into data buffer DJNZ bcount,:loop3 ; If not 8 Bits, get another SETB BCS ; Set !CS High RET At 12:29 PM 7/10/97 +0200, you wrote: >Thanks to all who replied. Kieran, in fact, I need to rotate, its a >reception of 12 bytes from TLC2543 ADC (a great part to work with PICs!) > >Bye > >David