----- Original Message ----- From: "Jinx" > > Then I call this code to read the switches on portb(4..7): > > > > setb rp0 > > mov trisb,#11110000b > > clrb rp0 > > Have you tried a delay here ? Could be some residual > charge or capacitance Yes, I thought about that so I put delays of up to 50 msec on both ends of the subroutine. I also tried clearing portb both before and after reconfiguring the port, even though this wouldn't work in my application because I need portb(0..3) to remain unglitched outputs, if at all possible. > Are internal pull-ups on ? I think nominally they are around > 27k, which might marginally balance the 20k pull-downs No, the internal pullups are off. Anyway, if balancing was the problem it shouldn't work when called at the beginning of the code, but it does. Interesting thing - if I run a simple program that configures portb as outputs but doesn't write anything to them, and then reconfigure as inputs and read the switches, I get all 1's. If I don't configure portb as outputs first but rather initially as inputs, it reads the switches fine. > enabled ?) or for some external reason the pins really do > always have '1' on them. Have you looked at them with a > 'scope or meter ? I will try this to see if they're staying high for some reason, but I doubt it. I have removed the switches and associated pull-ups from the circuit and replaced them with just 4.7k resistors from each pin to ground, and the same problem occurs. I get all 0's (no switches so they're all off) if I call the subroutine at the beginning, and all 1's if I run it in the main loop, even a simple loop that just configures portb as outputs, and then reconfigures it as inputs on 4..7 and reads the pins. I am starting to wonder if it has something to do with the read-modify-write characteristic of the ports. If so, I wonder if there is a software solution to get around this - seems like there must be. If you can, try doing this yourself and see if you get the same result. Simple circuit - just 4.7k resistors to ground from each portb pin. Write a program to initally configure portb as outputs, then reconfigure (4..7) as inputs, read the pins (should be all 0's), reconfigure as outputs, and loop. Output the result of the portb(4..7) on porta with LEDs. Bruce -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist