Nick Stedman wrote: > I'd like to cycle through the 8 A/D Channels on a 16f877a, read > each channel and store the results in separate variables. The > channel select bits are 5-3 of the ADCON0 register. So far I've > come up with: > > bcf/bsf ADCON0, 3 > bcf/bsf ADCON0, 4 > bcf/bsf ADCON0, 5 > > and using a different combo of bcf/bsf for each channel. It > doesn't seem very efficient though. Am I missing something? Any > help would be appreciated. Nick: To increment the channel number, rolling over from 7 to 0, do this: COMF ADCON0,W ;If we're already pointing to ANDLW 00111000B ;channel 7, set the Z flag. MOVLW 00001000B ;Assume that we aren't at 7, so prepare ;to just increment the channel number. SKPNZ ;If we really aren't at 7, skip ahead. MOVLW -00111000B ;Otherwise, we are already at 7, so ;prepare to add negative-7 to the ;channel number in order to roll it ;over to 0. ADDWF ADCON0 ;Perform the addition. To load FSR with the address of the variable that's associated with each channel (assuming that the 8 variables are in a contiguous array from register FIRST to register FIRST+7): RLF ADCON0,W ;Move the channel number from bits 3-5 MOVWF FSR ;of ADCON0 to bits 0-2 of W. SWAPF FSR,W ; ANDLW 00000111B ; ADDLW FIRST ;Add the channel number to the address of the MOVWF FSR ;FIRST register, and store the result in FSR. To store the A/D result in the register pointed to by the FSR: MOVF ADRES,W ;Grab the A/D result. MOVWF INDF ;Store it in the register pointed to by FSR. The standard disclaimer (i.e., this code hasn't even been assembled, let alone tested) applies to all of the above. -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.