a custom copy/paste solution for any kinda matrix keypad... well max 8X8
http://www.picbasic.co.uk/forum/showthread.php?t=3250
Yeah i know it's code hungry... one day i'll work on it again... one day!
a custom copy/paste solution for any kinda matrix keypad... well max 8X8
http://www.picbasic.co.uk/forum/showthread.php?t=3250
Yeah i know it's code hungry... one day i'll work on it again... one day!
Last edited by mister_e; - 13th April 2006 at 14:30.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
mr-e,
thanks for the code, it looks very simple and easy to use, however, it must be a little too complicated for me because I am getting nowhere. Maybe you can find something stupid and obvious, but I cant find it.
here is your code modified to my use
I threw the "Hello" in there just to test that it programmed correctly and the LCD is functioning.'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2006 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 4/13/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
TRISB = %10000000
ADCON1 = %11111111 'all ports digital
INCLUDE "KeyPad.bas"
'
' Hardware connection
' ===================
DEFINE KEYPAD_ROW 4 ' 8 row
define KEYPAD_ROW_PORT PORTA ' on PORTA
DEFINE KEYPAD_ROW_BIT 0 ' <3:0>
DEFINE KEYPAD_COL 3 ' 3 col
DEFINE KEYPAD_COL_PORT PORTC ' on PORTC
DEFINE KEYPAD_COL_BIT 4 ' <7:4>
DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
define KEYPAD_AUTOREPEAT 0 ' use auto-repeat
'
' Serial Communication definition
' ===============================
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0)
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 6 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
'
' Variables definition
' ===================
myvar var byte
' ---------------------------------[Program Start]----------------------------------------------
main:
lcdout $fe, 1, "Hello"
pause 500
start:
@ READKEYPAD _myvar
lcdout $fe, 1, "Key=", DEC myvar
goto start
END
When I press any button, it still just says hello. So something in the button config aint workin.
I am using Microcode studio 2.3, PBP2.46, and MPASM.
I have my rows hooked up with 4.7k pullup resistors as you stated and they are pinned to RC4-6. I also have the columns hooked up with 4.7k series resistors (too high a value?) to RA0-3.
thanks again for posting your code.
In fact you MUST use some low value for column, let's say 100-300 ohms. 4.7K is way too high. The PIC don't detect the LOW level signal. In best case the LOW level will be 2.5 volts... too high for a LOW level signalRefer tosection 18.4 of your datasheet for that.
You can even remove the column resistor and plug it directly... it will work but it's not really recommended.
Another thing, you must disable analog comparator too on PORTA
About now?Code:ADCON1=$0F ' Disable AD converters CMCON =7 ' Disable analog comparator
PS: you can remove the DEFINE KEYPAD_AUTOREPEAT line. If you don't write it, the program will set it to off for you. This refer to that section of the include file
Code:@ ifndef KEYPAD_AUTOREPEAT ' If AutoRepeat is not DEFINE repeat Gosub readcol ' Wait until until KeyTemp=keymask ' Key is released @ endif
Last edited by mister_e; - 14th April 2006 at 05:02.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Thanks very much steve.
I have it running and the keys are being read. I tried using low value resistors on the columns but it didnt work, but low value resistors on the rows and it started reading.
One problem though, The first two rows are working perfect, but the second two rows will change values every time I press the button.
these columns.
The two affected rows are connected to the VREF pins on PORTA, is there a disable config for VREF? or is it default disabled?
one more question also while your peeking at this thread. is there a way to make the auto repeat work only on 2 buttons? Two buttons on my kepad are +- adjustments and all the others are command buttons. It would be great to make the +- buttons autorepeat.
Last edited by docwisdom; - 14th April 2006 at 22:52.
Did you modify your code and include those lines at the top?
Comparator voltage reference is suppose to be set to off by default if you refer to the CVRCON POR. AND when you set ADCON1 to 0F, you set VREF- to Vss, VREF+ to VDD... so i can't understand why it doesn't work.Code:ADCON1=$0F ' Disable AD converters CMCON =7 ' Disable analog comparator
The first thing spring to mind is to set the AUTOREPEAT to ON then read the MyVar value and if it's not one of your two keys... redo the keypad scan until it change.one more question also while your peeking at this thread. is there a way to make the auto repeat work only on 2 buttons? Two buttons on my kepad are +- adjustments and all the others are command buttons. It would be great to make the +- buttons autorepeat
PS: you're right, i did a mistake, low value resistor must be on ROWs, not colums... DOH!
Last edited by mister_e; - 15th April 2006 at 11:21.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
we have operation. thanks very much steve.
it was the ADCON1 register. Do you have any resources to better explain registers and their settings. when I read about them in datasheets is all just a totally different language to me.
I have yet to implement the autorepeat. Ill post again with its results
I got my desired repeat with a simple loop comand.
thanks for all your help steve, its been invaluable.
If you feel so inclined, would you mind looking over my code and schematic to check for any changes that could be made for efficiency and design?
thanks
-brian
Bookmarks