LCD + keyboard matrix minimal I/O


Closed Thread
Results 1 to 6 of 6
  1. #1

    Default LCD + keyboard matrix minimal I/O

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    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 ?

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rf solution
    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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson
    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

  6. #6
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. Keyboard Matrix with a Twist
    By k3v1nP in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th October 2008, 10:51
  4. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  5. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts