How to add more ports

If you like the 16C84 and the cheap programmer and are too stubborn to spend any money on the proper programmer for the larger PICs, then like me, you need some ways to cheat the port limitations of the 16C84. The answer to this is serial.
No, I know there's no UART in the 16C84 - I'm talking about synchronous serial.

Muchos outputs

Enter the 74HC595. It is an 8 bit shift register with latch. Connect the 3 pins - data (SER pin 14), clock (SCK pin 11) and latch (RCK pin 12) to the PIC. The only limit to daisy chaining as many of these together as you need is the time available to shift all the data out and the memory to keep track of what each port is doing.
Click here for a code fragment of how to control the latches.

Muchos inputs

With one more input pin, you can scan some keys. Have a second chain of registers with the data and clock lines connected the same as before, drive the latch via a 330R from the clock line and 1n to ground (they will then happen roughly together). Connect the buttons to the outputs of the registers and diode-OR the other side of the buttons onto the input pin. As you ripple a logic 1 through the registers, shift incoming data into a memory location to give the status of all the buttons.
As the latch is derived, the other latch signal for the outputs is untouched.
Alternatively you could use a register that doesn't have the latches.




an557.pdf some nifty port usage. How to scan a keypad and multiplex a 7 segment, 4 digit display.