Code for interfacing 4x4 keypad to a microcontroller

Status
Not open for further replies.

babatundeawe

Full Member level 5
Joined
Apr 12, 2007
Messages
244
Helped
16
Reputation
32
Reaction score
12
Trophy points
1,298
Location
Nigeria
Activity points
2,738
pls i need help on interfacing a 4x4 keypad to a microcontroller (PIC). and also easy and understandable code will be appreciated. thanks
 

read keypad in proton picbasic

This code is written in proton picbasic.

Code:
        Device = 16F877

' Define program variables
		Dim Col     as     Byte            		' Keypad column
		Dim Row     as     Byte            		' Keypad row
		Dim Key     as     Byte            		' Key value

        Delayms 100               				' Wait for LCD to start
        PORTB_PULLUPS = ON        				' Enable PORTB pullups
        ALL_DIGITAL = True						' Set ports to digital mode
        Print Cls, "Press any key"  			' Display sign on message

Loop:   Gosub Getkey            				' Get a key from the keypad
        Print Cls, #Key     					' Display ASCII key number
        Goto Loop               				' Do it forever


' Subroutine to get a key from keypad
Getkey:
        Delayms 50                				' Debounce

Getkeyu:
        ' Wait for all keys up
        PORTB = 0               				' All output pins low
        TRISB = $F0             				' Bottom 4 pins out, top 4 pins in
        If (PORTB >> 4) <> $0F Then Getkeyu    	' If any keys down, loop

        Delayms 50                				' Debounce

Getkeyp:
        ' Wait for keypress
        For Col = 0 to 3        				' 4 columns in keypad
                PORTB = 0       				' All output pins low
                TRISB = (Dcd Col) ^ $FF 		' Set one column pin to output
                Row = PORTB >> 4        		' Read row
                If Row <> $0F Then Gotkey       ' If any keydown, exit
        Next
        Goto Getkeyp            				' No keys down, go look again

Gotkey: ' Change row and column to key number 1 - 16
        Key = (Col * 4) + (Ncd (Row ^ $0F))
        Return                  				' Subroutine over

Label:
        End

The idea is to scan each row by triggering the column one at a time.

Here is the diagram.

 
Re: mcu and 4x4 keypad


pls i will appreciate it if i can get to learn more picbasic. the syntax its very basic and straightforward can u pls help on how to learn and program using this language. thanks for you upload i really appreciate it.
 
Last edited by a moderator:

Re: mcu and 4x4 keypad

good day sir'!

can you give me a source code to read the input form my 4x4 keypad to my PIC UPRC,. it is zilog
thanks :grin:
 

Re: read keypad in proton picbasic

hello can you please post a similar program for msp430g2231
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…