On Thu, 19 Feb 1998, James Tilley wrote: > I am trying to set a specific bit on portb, and I wanted to do this by > using a variable and the bsf function. Problem is, the bsf function > evaluates the variable as the literal file register address. Is there a > way to do this aside from writing to the whole of portb? bcf and bsf do a read/modify/write cycle, so they also write to the whole of portb. Only the pins set as outputs by trisb will actually change. Bitmasks work almost like bit pointers. The bitmask 00000001b is the "bit pointer" to bit 0. 00001000b points to bit 3. Say your "bit pointer" is in the file register "BitP". "bsf BitP" and "bcf BitP" can be simulated with these little functions. bsfbitp ; subroutine to set the bit in portb pointed to by BitP movf BitP,w iorwf portb,f return bcfbitp ; subroutine to clear the bit in portb pointed to by BitP comf BitP,w andwf portb,f return Use rotates to increment and decrement these "bit pointers". If the carry bit gets set, you've reached the end of the byte. I'm sure someone on the list has a clever way of converting a number in the range 0 to 7 into a bitmask with one bit set and vice versa. -- paulh@hamjudo.com http://www.hamjudo.com The April 97 WebSight magazine describes me as "(presumably) normal".