Hi,
Yes, if you don't care what's happening with PortB.4-7 then that should work.
If PortB.4-7 are outputs then your aproach won't work properly since you'll overwrite those bits with the value of Temp. That's the reason for first reading PortB and ANDing it with %11110001 so that we ONLY change the state of bits 1-3 when ORing Temp with X. If all bits except 1-3 are inputs then your aproach should work - which brings me to the next point...
I suspect the purpose with "keeping PortB.0 high" is to prevent it from tripping an interrupt? If so I don't think you need to worry about that.
When PortB.0 is setup as an input, it doesn't matter what you write to PortB.0 - it'll never actually "get to" the actual pin since the output driver is disabled. Look at the block diagram of the pin in the datasheet, this is for the 16F887 it may differ slightly from whatever device you're using:
The "interrupt path" is drawn in blue here. The output driver is circled in red. As you can see the output driver is enabled/disabled by D-type flip-flop which is controlled by writing to TRISB. So, even if you write '0' to PortB.0 it'll never reach the pin and cause an interrupt since that '0' won't "go thru" the output driver.
/Henrik.
Bookmarks