Keypad error

Discussion in 'Embedded Systems and Microcontrollers' started by AFAS87, Jan 30, 2010.

  1. AFAS87

    Thread Starter Member

    Oct 9, 2008
    23
    0
    hi,,,,
    i have a project which includes PIC and keypad with LCD.
    i have connected the keypad directly to PORT B of the pic.

    in simulation... every things goes good...

    but as i connected the keypad to the PIC practically... the keypad didnt work,

    my keypad is that 4x3 with 8 pins... 7 pins for 4 rows and 3 coloumn and one is called COM....

    any one has an idea...

    attached the simulation and the code..

    thanks ,,,




    Code ( (Unknown Language)):
    1. #include<16f877a.h>                                          //Device
    2. #fuses xt,nowdt,protect,noput,nolvp                 //Fuses
    3. #device adc=10                                                //ADC 10-bit
    4. #use delay (clock=4000000)                              //4.00 MHz
    5. #use rs232 (Baud=9600)                                     //RS-232 parametres
    6.                                                                      //(only for printf function)
    7. #include <keypad.c>
    8.  
    9.  
    10.  
    11. main()
    12. {
    13.    
    14.    
    15.    
    16.    byte key='\0';
    17.    kbd_init();
    18.  
    19.  
    20.    port_b_pullups (TRUE);
    21.    delay_us(10);
    22.  
    23.    
    24.    
    25.    
    26.    
    27. while(1)
    28. {
    29.    
    30.     key=kbd_getc();
    31.         if(key!='\0')
    32.             {output_high(pin_e0);
    33.      
    34.             delay_ms(5000);
    35.                 }
    36.  
    37. }}
    38.  
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Can you describe how it misbehaves?

    hgmjr
     
  3. eng1ne

    Member

    Dec 4, 2009
    97
    3
    You will have to be more specific.

    The keypad didn't work? How do you know? If that is the problem, get a keypad that does.

    But, one would suspect it isn't the keypad that isn't working, but your code. Which compiler are you using?
     
  4. AFAS87

    Thread Starter Member

    Oct 9, 2008
    23
    0
    thank your for your attention...
    i mean that the keypad doesnt work with the PIC..
    the keypad itself works... i test it by ohmmeter.

    i use ccs compiler...
     
  5. eng1ne

    Member

    Dec 4, 2009
    97
    3
    How doesn't the keypad work with the Pic? Is it simply that pin E0 does not go high?

    When you say 'it doesn't work with the Pic' it is still not very specific. The more vague you are, the more difficulty we will have in assisting you.
     
  6. AFAS87

    Thread Starter Member

    Oct 9, 2008
    23
    0
    ok...pin E0 will go high if any key is pressed... i tried that but with no result.
    i pressed a key and pin e0 never went high...

    is there any error in my code.?
    the last pin of the keypad, inkey or COM , what is that for?
    and i wonder if there is any other way to connect this keypad with the PIC, like using encoder,

    thank u again.
     
  7. eng1ne

    Member

    Dec 4, 2009
    97
    3
    I think the problem may be with your actual circuit.

    The simulation program you use connects the COM pin automatically and so you don't have to connect it to simulate it. Right click on your keypad in the simulator, and edit properties. Select the button 'Hidden Pins' to see where the simulator connects it to.

    The common pin should be connected to 0 V or ground.
     
  8. AFAS87

    Thread Starter Member

    Oct 9, 2008
    23
    0
    thanks...
    also i wanna ask if there it is necessary to connect pull up resistors, or just include them in the code where i use port B.
     
  9. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Pullups on the 4 lines going to the microcontroller is probably a good idea. Some microcontrollers have internal weak pullup that can be enabled or disabled.

    hgmjr
     
  10. eng1ne

    Member

    Dec 4, 2009
    97
    3
    Yes, you've enabled them anyway.

    Did it work?
     
  11. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    First off, what is happening inside the keypad.c file? Without that listing we are working in the dark.

    The second thing that strikes me is that you are using #include to add the keypad.c file. This is not the normal way to do it. You usually just add it to the list of source files in the IDE and let the linker take care of everything.

    I also don't see any setup commands for your ports. They either happen in the keypad.c file (as I say, we can't tell) or they don't happen at all in which case nothing will work until you set up your portB.
     
  12. AFAS87

    Thread Starter Member

    Oct 9, 2008
    23
    0
    no it didnt work...
    i tried many times such that iam so bored..

    may you help me with a tested code or with a schematic for a project that was actually tested ...
    thank you all
     
  13. eng1ne

    Member

    Dec 4, 2009
    97
    3
    Alex pointed a few things of note.

    You haven't for instance, set up the ADC.

    Don't let all this get you dispondent however. I am a big supporter of mistakes; without them we would not learn half as well. You've learnt what the COM pin is for for example.

    You obviously have the enthusiasm, and quite a bit of know-how to set it practically.

    I learnt using www.gooligum.com.au tutorials. I thought they were excellent. They talk you through using the CCS compiler. Read through them and make some of the circuits they suggest. They also deal with keypads.

    Perhaps knock this project on the head until you have done the tutorials, then come back and try again.
     
Loading...