View previous topic :: View next topic |
Author |
Message |
AD76XYZ
Joined: 18 Jun 2012 Posts: 19
|
4X3 Keypad not working |
Posted: Sat Jun 30, 2012 3:51 am |
|
|
I have connected 16x2 LCD and 4x3 matrix keypad to portb (RB7-RB1). Only LCD is showing " Ready... " and nothing from keypad. I checked pins RB7-RB1 with logic probe but no activity at all, and it looks like pins are at high impedance state, because logic probe neither shows Hi nor Low.
Code: |
// I have define LCD pins as per requirment.
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define LCD_ENABLE_PIN PIN_C2
#define LCD_DATA4 PIN_C3
#define LCD_DATA5 PIN_C4
#define LCD_DATA6 PIN_C5
#define LCD_DATA7 PIN_C6
#include<lcd.c>
#include<kbd4x3.c>
#use delay(clock=4000000)
char k;
int i;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_4MHZ);
// TODO: USER CODE!!
lcd_init();
kbd_init();
lcd_putc("\fReady...\n");
while(1);
{
k=kbd_getc();
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
}
}
|
Kindly tell me where is the problem. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Sat Jun 30, 2012 5:04 am |
|
|
assuming this is REAL hardware and NOT an ISIS/proteus 'simulation'..
possible errors are...
1) faulty hardware..be sure the correct PIC pins are being used,proper pullups,etc. A schematic would help.
2) faulty keyboad driver..without seeing the driver I can't comment further, though I know the CCS ones work.
3) bad PIC. You might have blown it, try another.
4) incorrect PIC setup.without knowing the PIC(should be first line of code),no one knows if the init you have is correct for it.
The code you show is not complete and will not compile , so no one here can test for you
If this is a 'simulation', sorry, I can't help you. Knowing that Proteus is FULL of bugs,errors, faluty DRCs, I'm not about to fix ISIS so that it correctly works,life is way too short for that exercise in futility |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 30, 2012 10:48 pm |
|
|
Quote: | I checked pins RB7-RB1 with logic probe.
it looks like pins are at high impedance state
because logic probe neither shows Hi nor Low.
|
You need to have Port B pullups enabled for the keypad. You didn't
post your PIC or your list of connections between the PIC and the
keypad. If you have an older PIC such as the 16F877, then you
can do this:
Code: |
port_b_pullups(TRUE);
|
If you have a more modern PIC such as the 16F887, then you can do this:
Code: |
port_b_pullups(0xFF);
|
Actually the last line will work for both PICs.
If that doesn't fix it, then:
1. Post your PIC.
2. Post your #fuses.
3. Where does the kbd4x3.c driver file come from ? Is it the same as the CCS file, kbd.c ? Or is it the Flex keypad driver in the CCS Code Library forum ? Tell us where it comes from or post a link to it.
4. What's the manufacturer and part number of your keypad ?
5. Post a detailed list of the connections between the keypad pins
and the PIC pins. |
|
|
AD76XYZ
Joined: 18 Jun 2012 Posts: 19
|
Logic of storing in array |
Posted: Sun Jul 01, 2012 1:21 am |
|
|
Thanks for helping. Actually PIC's port B was damaged. I changed the PIC and now keypad is working fine with a same code.
I am making code lock project. I want to know how to take number from keypad and store in array. I have fixed four digit code and want to take four digit from keypad and want to store in array say dig_input[] and want to compare with digit[] array.
Please help. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jul 01, 2012 2:28 pm |
|
|
You've started two threads, one is now locked.
Look at my response there.
Mike |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sun Jul 01, 2012 2:33 pm |
|
|
You need to give some thought to how you want to fill that 4 digit array - do you want it to simply be "full" when the user enters 4 digits, do you want it to shift the digits through so the last 4 digits entered are the ones tested? Usually, you would have an "ENTER" key so they can tell it when to test the 4 digits. You also need to consider how to prevent someone from simply sitting there and entering digits until they find a combination that works (limit the number of trys they can do within a period of time or lockout). To make a lock effective, you need to give some thought up front to how you are going to address these issues because it will determine your basic code structure. My preference is to shift digits through the 4 digit array until "ENTER" is pressed. After the compare, be sure and clear the array so the next person doesn't simply have to press "ENTER" again.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 01, 2012 9:53 pm |
|
|
This thread has sample code which shows how to get a password from
a keypad:
http://www.ccsinfo.com/forum/viewtopic.php?t=45935
You have to write the remaining code which compares the password
entered by the user to a stored password. |
|
|
|