1 Attachment(s)
Re: Matrix Keypad routine
I made a simple schematic for testing my remote control stalk near the steering wheel, from Renault.
I use "KeyPad_2.bas" , addapted to my hardware :
Code:
;
; Default settings
; ================
KB_ROW = 2 ; 2 ROW keypad
KB_ROW_PORT = PORTB ; Keypad ROW on PORTB
KB_ROW_BIT = 0 ; ROW0 = PORTB.0
KB_COL = 3 ; 3 COL keypad
KB_COL_PORT = PORTA ; Keypad Col on PORTA
KB_COL_BIT = 0 ; COL0 = PORTA.0
DebounceDelay = 0x41 ; debounce delay 41mSec
SINGLE_SCAN = 0 ; Scan ;till a key is pressed
KEYPAD_AUTOREPEAT = 1
The code it's verry simple :
Code:
@ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_OFF, LVP_OFF
Define OSC 4 ' 4MHz
CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode
OPTION_REG.7=1
include "c:\pbp\MYKEY.BAS" ' see http://www.picbasic.co.uk/forum/showthread.php?t=3250
main:
gosub keypadscan
gosub check
goto main
check:
select case key
CASE 1
portb.2 = 1
pause 5000
portb.2 = 0
case 2
portb.3 = 1
pause 5000
portb.3 = 0
case 3
portb.4 = 1
pause 5000
portb.4 = 0
case 4
portb.5 = 1
pause 5000
portb.5 = 0
case 5
portb.6 = 1
pause 5000
portb.6 = 0
case 6 ; track +
portb.7 = 1
pause 5000
portb.7 = 0
end select
Return
But....
Allways LED's on PortB.2 and PortB.3 are ON ! What I am doing wrong ?!? Thanks in advance for reply !
Re: Matrix Keypad routine
Problem solved...by moving ALL rows and columns to PortB ...
Code:
; Default settings
; ================
KB_ROW = 4 ; 4 ROW keypad
KB_ROW_PORT = PORTB ; Keypad ROW on PORTB
KB_ROW_BIT = 0 ; ROW0 = PORTB.0
KB_COL = 4 ; 4 COL keypad
KB_COL_PORT = PORTB ; Keypad Col on PORTB
KB_COL_BIT = 4 ; COL0 = PORTB.4
DebounceDelay = 0x200 ; debounce delay 200mSec
SINGLE_SCAN = 0 ; Scan ;till a key is pressed
Re: Matrix Keypad routine
Hi Guys ,
Well this keyboard matrix routine has been here a while and works well.
but if you need to place a 1 row or column port pin on another port out of sequence then you have a problem.
I face this as i changed from 16f1947 to 18f67k22 on the pcb , where the 16f1947 has portF.0 , and 18f67k22 does not
as you guessed a row pin was on Portf.0
PORTF.0 -3 was row ,portb 0-3 was column , so no problem with the column port , but row0 wont work on an non existent port
so the new row0 port was connected to a spare pin at portG.4
PortG.4 TRES direction was set to output prior to keypad.bas include used , but could have been set in in the keypad.bas section of code after the asm that sets the TRES for the colume and row ports assigned
I used the port offset value to point portG.4 , when it was selecting row0 , and set the POrtG.4 =1 prior as per steves comments
the offset value 12 is worked out 12 port locations past portF0
i also did not care if portF.0 TRES were set to output as per steves routine , but if this was an issue , removing the ASM code that sets the TRES in keypad.bas and do it as per normal would have been ok
I hope this helps someone that has a similar problem
cheers
Sheldon
Code section prior to change
=====================
Code:
ScanKeypad:
key=0 ; no key is press
row=0 ; begin scan @ ROW0
col=0 ; and COL0
kb_row_PORT=kb_row_PORT | InitialState ; set all ROW bits to 1 using bitwise OR
repeat
ROWBIT=ROW+KB_ROW_BIT ; point to a ROW bit
kb_row_PORT.0[RowBit]=0 ; clear actual ROW bit
after code change
==============
Code:
ScanKeypad:
key=0 ; no key is press
row=0 ; begin scan @ ROW0
col=0 ; and COL0
PORTG.4 = 1 ; Setup row-0 = 1
kb_row_PORT=kb_row_PORT | InitialState ; set all ROW bits to 1 using bitwise OR
repeat
if row = 0 then
Rowbit = 12 ; offset amount for row 0 from PortF.0 to point to PortG.4
else
ROWBIT=ROW+KB_ROW_BIT ; point to a ROW bit
endif
kb_row_PORT.0[RowBit]=0 ; clear actual ROW bit
Re: Need help desperately!!!
handy key fifo for this routine to keep 5 key strokes deep
Code:
if key >0 then
for Key_count = 4 to 1 step - 1
Key_value(Key_count) = Key_value( Key_count - 1)
next Key_count
Key_Value(0) = Key
endif
Re: Need help desperately!!!
How can I use this include for something like this ???
Code:
main:
@ READKEYPAD _myvar
gosub check
goto main
check:
select case myvar
case 1
porta.0 = 1 ; WHILE CASE 1 PORTA.0 = 1, THEN PORTA.0 = 0
Thanks !
Re: Matrix Keypad routine
Code:
CASE 1
Porta.0 = 1
WHILE myVar = 1
@ READKEYPAD _myvar
WEND
PortA.0 = 0
/Henrik.
1 Attachment(s)
Re: Matrix Keypad routine
Thank You!
LE : But don't work.
Press button 1 of matrix ; led 1 = OFF ; end pressing button 1 ; led 1 = ON untill press ANOTHER button ...say button 2.
But pressing button 2 don't turn ON led2 ; just another press and release of button 2 turn correspondent led (2) ON.
Re: Matrix Keypad routine
In your first post you indicated that you wanted PortA.0 high while the myVar was equal to 1 - is that not what's happening with the code?
How do you want it to work and what does the code look like?
1 Attachment(s)
Re: Matrix Keypad routine
Thanks for support , Mr.Henrik !
What I want :
- porta.x = ON while correspondent button.x is pressed.
How work :
- press button x ; do nothing ; release button x - porta.x=ON ; remain ON while press ANOTHER button(say y) ...But this new button(y) don't turn correspondent porta.y ON ; just turn OFF previous porta.x ; only after the release of the second press turn on correspondent porta.y...
Re: Matrix Keypad routine
Hi,
1) The documentations for the keypad routine says that myVar should be a BYTE, you have it declared as a WORD. Don't think it matters but ....
2) There's no RETURN at the end of the Check subroutine.
3) The routine has some sort of AutoRepeat feature, I don't know if that is perhaps messing with you - I've never used the routine myself.
4) The filename for the INCLUDE file says Keypad1, have you modifed it in any way?
5) Do you have your LED's wired as in the schematic? Ie PortA.1 = 1 does actually turn on the LED?
Which device?
/Henrik.
Re: Matrix Keypad routine
1.I (re) declared myVar as byte .
2.I added Return at the end of check.
3.I use this in my keypad include :
" SINGLE_SCAN = 0 ; Scan ;till a key is pressed
KEYPAD_AUTOREPEAT = 1 "
4.No, just portb allocation
5.Yes.
No change in how the code work ...
Thanks again !
LE : "SINGLE_SCAN" must be set to "1" for acting like I wish ...
Thanks ! Regards !
1 Attachment(s)
Re: Matrix Keypad routine
HI
ABOUT THE ROUTINE WRITTEN BY MR MISTER_E.
I NEED HELP HOW TO MAKE THE NUMBERS ARE IN SERIES EXAMPLES 12345566
AND THEN PRESS THE BUTTON # SEND VIA SERIAL A SEQUECIA.
Code:
#CONFIG
__config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF & _WRT_OFF
#ENDCONFIG
DEFINE OSC 4
TRISA=%00000011
TRISB=%00000000
TRISC=%11111110
ADCON0=%11000000
ADCON1=%00000111
INCLUDE "KeyPad2.bas"
'
' Hardware connection
' ===================
DEFINE KEYPAD_ROW 4
DEFINE KEYPAD_ROW_PORT PORTC
DEFINE KEYPAD_ROW_BIT 0
DEFINE KEYPAD_COL 3
DEFINE KEYPAD_COL_PORT PORTC
DEFINE KEYPAD_COL_BIT 4
DEFINE KEYPAD_DEBOUNCEMS 200 'debounce delay = 200 mSec
define KEYPAD_AUTOREPEAT 1 'use auto-repeat
' LCD Display
' -----------
' Adjust these to suit your chosen LCD pinout
'
'----DEFINIR LCD--------------------------------------------------------------
DEFINE LCD_DREG PORTB ' LCD data port
DEFINE LCD_DBIT 4 ' LCD data starting bit
DEFINE LCD_RSREG PORTB ' LCD register select port
DEFINE LCD_RSBIT 2 ' LCD register select bit
DEFINE LCD_EREG PORTB ' LCD enable port
DEFINE LCD_EBIT 3 ' LCD enable bit
DEFINE LCD_BITS 4 ' LCD data bus size
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 5000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
mykey VAR BYTE
myvar var byte
array var byte[5]
index var byte
i var byte
word_v var word
LCDOUT $FE,1, " FONTE DIGITAL "
PAUSE 1000
LCDOUT $FE,1
' ---------------------------------[Program Start]----------------------------------------------
start:
@ READKEYPAD _myvar
gosub lcddisp
goto start
lcddisp:
LCDOUT $FE,$C0,DEC4 myvar
pause 60
return
end
Re: Matrix Keypad routine
You may add the keypresses to an array using an index and then send the array over the serial port.
Not tested but you get the idea:
Code:
string var byte[9]
index1 var byte
start:
For index1=0 to 8
@ READKEYPAD _myvar
string[index1]=myvar
next index1
if myvar="#" then hserout [STR string\8]
goto start
Ioannis