PDA

View Full Version : LCD + keyboard matrix minimal I/O



RFsolution
- 20th June 2006, 23:40
Hi

I want to connect a 4x2 keyboard (4 collom, 2rows) and 16x2 LCD
(4 bits + RS + E) and 4 leds

So normally 6+6+4 I/O's, but i remember that someone found a solution to
free up some pins by using some togheter

Can someone help with an example to read the keyboard, write to the LCD
and set the LED's with a minimum of IOs
I want to use an 16F876 or 877

Thanks to all

Melanie
- 21st June 2006, 06:17
I'd never mux an LCD, so that remains at six, unless you want to add external logic, in which case you can get that down to two, but you will lose the LCDOUT command (which has a lot of built-in functionality) and have to use SHIFTOUT instead (which doesn't) so I wouldn't recommend it. You can of course use a Serial LCD which would then require just one pin...

You can hang two LED's on each PIC pin. So you can get that down to two.

By adding six external Resistors to your 2 x 4 Keypad you can read your entire Keypad using just one ADC pin.

So, I make 6+2+1 = 9 pins (recommended), or of you want to be brave with the LCD then it's 2+2+1 = 5 pins, or with a Serial LCD it would be 1+2+1 = 4 pins.

RFsolution
- 21st June 2006, 12:22
Hi Mel

thanks for your reply

Well I want to keet the lcdout command so thats (6)
I was thinking if the 4 collom outputs could not be shared with D4-D7 from the lcd
so if you scan the keyboards collomns, you dont access the LCD

Your ADC idea might be a good solution, if I dont use all AD's

any example code for that ?

Jerson
- 21st June 2006, 13:08
I was thinking if the 4 collom outputs could not be shared with D4-D7 from the lcd

I think you are on the right track. I see no problem if you use the LCD with 6 ports. Of these, you may use the 4 data lines as row outputs to the keyboard and use the RS line of the lcd switched to input to be a column when you scan the keyboard. You will need just one more line to make it a 4x2 matrix. Obviously, you will need to do a bit of juggling in the code to change modes when needed.

So, I think you can get by with a 6+1 lines to acheive what you want and NO ADC stuff is used yet.

Jerson

RFsolution
- 21st June 2006, 13:15
I think you are on the right track. I see no problem if you use the LCD with 6 ports. Of these, you may use the 4 data lines as row outputs to the keyboard and use the RS line of the lcd switched to input to be a column when you scan the keyboard. You will need just one more line to make it a 4x2 matrix. Obviously, you will need to do a bit of juggling in the code to change modes when needed.

So, I think you can get by with a 6+1 lines to acheive what you want and NO ADC stuff is used yet.

Jerson

Thanks Jerson,

Looking fwd if someone could make a smal example to
get the keyboard value and send something to the LCD
so I can have a look

thanks to all who took a look to this message

ErnieM
- 21st June 2006, 19:49
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/appmod/LcdTerminal.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