I've been using the 6 or 7 lines from a PIC to both control an LCD and read back 4 buttons. Nothing real fancy, I just coppied the published design for the Parallax LCD Terminal AppMod. I've since bought several of their devices for use in test fixturing and proto development, as these are so very handy to get human readable alphanumerics and push button input together.
The good part is all the standard PBP LCD commands work well with this set-up.
http://www.parallax.com/dl/docs/prod...cdTerminal.pdf, see the last page for schematic.
(Guessing offhand), E is enable, so leave it alone, as long as PBP set it it's correct. RW is read/write, if you don't define it PBP doesn't use it so you can hard-wire it for write only and save a pin. RS can be re-used when the LCD isn't using it. (Please re-check these details as they are from a distant memory)
So also using RW and RS as inputs you have 6 buttons. For an extra 2 I/O pins you get your 8 push buttons. So, instead of 7 lines for LCD and 8 lines for the buttons, you only need 9 total for both.
If you hunt thru Microchip's site they have some really clever ways to get lots of functions on very few pins.
I use the following code to read switches (remember, I only have 4 switches):
read_inputs:
' scan to find debounced buttons pressed
' calling code responsible for approx 5 ms wait between calls
temp = TRISB ' save port data directions
TRISB = TRISB | button_mask ' make LCD bus inputs
fresh_buttons = button_mask & PORTB ' get current button state
TRISB = temp ' restore port data directions
If fresh_buttons = raw_buttons Then
' button pattern stable
scans = scans + 1
If scans >= 10 Then ' we have new stable buttons
buttons = raw_buttons ' present the newly stable buttons
Endif
Else
' buttons not stable
raw_buttons = fresh_buttons ' establish new pattern
scans = 0 ' restart count
buttons = 0 ' no buttons down if not stable
Endif
Return
Bookmarks