Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help About scan 3x4 Keypad

Status
Not open for further replies.

TronicBrain

Member
I am tring to scan 3x4 keypad and I tried many ways but I did not success
So I need a sub routin that can scan 3x4 keypad without interrupt
I made search on the net but I did not finde what I need
Could you Please help me.
 
beginner said:
I am tring to scan 3x4 keypad and I tried many ways but I did not success
So I need a sub routin that can scan 3x4 keypad without interrupt
I made search on the net but I did not finde what I need
Could you Please help me.

One of my PIC tutorials at http://www.winpicprog.co.uk shows how to scan a keypad, it actually uses a 4x4 but shows the lines which need removing for a 3x4.
 
Thank you very much Nigel :)
It's really usefull PIC tutorials and I think I will get what I need :idea:
 
Code:
Define  LCD_DREG       PORTD 
Define  LCD_DBIT       4 
Define  LCD_RSREG      PORTE 
Define  LCD_RSBIT       0 
Define  LCD_EREG       PORTE 
Define  LCD_EBIT         1 

ADCON1 = 7          ' PORTA AND PORTE DIGITAL 
OPTION_REG.7 = 0   ' PORTB Pullups. 

TRISB = %11110000  ' PORTB 0-3 output, 4-7 input  
PORTB = 0 
TRISC = 0 
PORTC = 1 

'******************* 
keybuf var byte[4] 
keycnt var byte 
for keycnt = 0 to 4 
    keybuf[keycnt] = 0 
next 
'******************* 

key  var byte 
col  var byte 
row  var byte 
delay var byte 

delay = 0 

pause 100        
lcdout $fe,1,"4X4-KEYPAD DEMO",$fe,$c0,"2003 - by F.San" 

Main: 
    gosub Chk_KEYPAD 
    if PORTC = 0 then PORTC = 1 
    if delay = 100 then PORTC = PORTC << 1 
    delay  = delay + 1 
    pause 1 
goto Main 

Chk_KEYPAD: 
    for col = 0 to 3 
        PORTB = (dcd col) ^ $f    
        row = PORTB >> 4 
        if row != $f then   ' key pressed 
            key = (col * 4) + (ncd (row ^ $f)) 
            gosub DeBounce 
            gosub Got_KEY 
            key = 0 
        endif 
    next 
return    

DeBounce: 
    delay = 0 
    while (row != $f) and (delay < 20) 
        pause 10 
        delay = delay + 1 
    wend 
    delay = 0 
return 

Got_KEY: 
    'lcdout $fe,1,"4X4-KEYPAD DEMO",$fe,$c0,"BUTTON: ",#key 
    PORTC = key 

'******************* 
    if keycnt > 3 then 
       lcdout $fe,1 
       keycnt = 0 
    endif 
    keybuf[keycnt] = key 
    lcdout #keybuf[keycnt] 
    keycnt = keycnt + 1 
'******************* 
return 

end


if u are interested in basic
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top