----- Original Message ----- From: "Maarten Hofman" Maarten - thanks for the response. > > I am using a 16F716 with all portb pins tied to ground through 20k > > resistors. I have also tied portb(4..7) to Vcc through switches and 1k > > resistors. I use portb(4..7) to address a mux and portb(0..3) to drive > > relays through a buffer. > > Please make the circuit a little bit more clear. Where are the > resistors? Which MUX? It doesn't really matter which mux - if you imagine each portb pin tied to ground thru a 20k resistor, and portb(4..7) tied to +5v through a switch and a 1k resistor. I have tried this with such a basic circuit and have the same problem as the full-blown app. What I want to do is start out with portb configured for output on all pins, execute some code, switch portb(4..7) to inputs, read the switch settings, and then switch back to all outputs on portb. The switch reading code is a subroutine - if I call it only once at the very beginning of my code it reads the switches properly. If I call it each time I go through my main program loop, I always get 1111 on portb(4..7) regardless of the switch settings. > > Here is what I have tried so far (sorry for the parallax): > > And you should be. Unfortunately I can't help with the code, as I am > not entirely sure what the instructions do exactly. If they do what I > think they do, it should work fine, however, they might do something > else. MPLAB compatible code is a wiser choice. I know, I have to make the switch to MPLAB code one of these days. At any rate, the instructions do what you think they do - they are pretty straightforward. Here is what the pgm does: Switch to register page 1 Configure portb for all outputs Switch back to register page 0 Execute some code Switch to reg pg 1 Configure portb for outputs(0..3) and inputs(4..7) Back to reg pg 0 Read portb(4..7) Switch to reg pg 1 Configure portb for all outputs Back to reg pg 0 > Given that the 16F716 has an 8-bit analog to digital converter, I > would recommend hooking all the switches up to that: you're using > resistors anyway. Give each switch a different resistor value, use the > AD converter to sample the result and there you have your switch > status, using only 1 port. I am using porta for other things - I have no extra ports so I am trying to use portb(4..7) for dual duty. Bruce -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist