I2C PCF8574 4X4 Keypad routine


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

    Default I2C PCF8574 4X4 Keypad routine

    Hi all

    I was wondering if someone made some code to use a 4X4 or any other matrix keypad by I2C using an IO expander PCF8574 ?

    I found some code examples on 4X4 keypad routines like Mister_E etc...

    To avoid waisting IO's on the PIC I2C might be a nice solution.

    Anyone ?

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    RFsolution, Here ia a snipit of code I wrote back somewhere in 2003. I hope this helps....



    I2CWRITE SDA,SCL,UNIT0,[%11110000] 'ALL COLLUM LINEs LOW
    AGAIN:
    GOSUB READKBD
    GOTO AGAIN


    '************************************************* ********************
    READKBD: 'READ DIGITAL INPUTS FROM KEYBOARD
    '************************************************* ********************
    KEYDOWN = 1
    I2CREAD SDA,SCL,UNIT0,[KEYPRESS] 'LOOK FOR SWITCHES DOWN
    KEYPRESS = KEYPRESS >> 4
    IF KEYPRESS < 15 THEN 'KEY NOW BEING PRESSED
    IF KEYFLG = 1 THEN 'KEY ALREADY BEEN FLAGED & PROCESSED
    GOTO DONEKEY
    ENDIF
    INCDEC = 1 'INCREMENT DEBOUNCE COUNTER
    IF DEBOUNCE = 65535 THEN '16 Ms. THRU ROUTINE TO KEY
    FOR JUNK = 0 TO 3 'CYCLE THRU COLLUMS
    I2CWRITE SDA,SCL,UNIT0,[~(DCD JUNK)] 'ONE LINE LOW @ A TIME
    I2CREAD SDA,SCL,UNIT0,[KEYPRESS] 'LOOK FOR SWITCHES DOWN
    KEYPRESS = KEYPRESS >> 4
    IF KEYPRESS < 15 THEN MAP 'IF SWITCH IS PRESSED THEN
    NEXT
    I2CWRITE SDA,SCL,UNIT0,[%11110000] 'ALL COLLUM LINEs LOW
    GOTO DONEKEY
    MAP: KEYFLG = 1 ' Set Debounce flag
    KEYPRESS = NCD((~KEYPRESS) & 15)
    KEYPRESS = KEYPRESS + (JUNK * 4)
    LOOKUP KEYPRESS,[0,49,52,55,42,50,53,56,48,51,54,57,35],INKEY ' Map of the keypad legends
    LCDOUT $FE,$80
    PAUSEUS 100
    LCDOUT DEC2 KEYPRESS,"=",INKEY
    I2CWRITE SDA,SCL,UNIT0,[%11110000] 'ALL COLLUM LINEs LOW
    ENDIF
    ELSE
    IF DEBOUNCE > 0 THEN
    INCDEC = 0 'DECREMENT DEBOUNCE COUNTER
    ELSE
    KEYFLG = 0 ' No key pressed, so Reset debounce flag
    KEYDOWN = 0 ' No key pressed, so Reset key Debounce flag
    ENDIF
    ENDIF
    DONEKEY:
    RETURN


    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You could still use 1 Analog pin and few resistor.. kind of R-2R network.

    You could refer to tip #5,6 and #7 of the Microchip Tips and trick DS40040B
    http://ww1.microchip.com/downloads/e...doc/40040b.pdf
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. 4x4 keypad Help
    By aaliyah1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th October 2010, 16:34
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Another I2C Slave Routine Problem
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 05:50
  5. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33

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