Keypad error

Thread Starter

AFAS87

Joined Oct 9, 2008
23
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 ,,,




Rich (BB code):
#include<16f877a.h>                                          //Device
#fuses xt,nowdt,protect,noput,nolvp                 //Fuses
#device adc=10                                                //ADC 10-bit
#use delay (clock=4000000)                              //4.00 MHz
#use rs232 (Baud=9600)                                     //RS-232 parametres
                                                                     //(only for printf function)
#include <keypad.c>



main()
{
   
   
   
   byte key='\0';
   kbd_init();


   port_b_pullups (TRUE);
   delay_us(10);

   
   
   
   
while(1)
{
   
    key=kbd_getc();
        if(key!='\0')
            {output_high(pin_e0);
      
            delay_ms(5000);
                }

}}
 

Attachments

eng1ne

Joined Dec 4, 2009
97
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?
 

Thread Starter

AFAS87

Joined Oct 9, 2008
23
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...
 

eng1ne

Joined Dec 4, 2009
97
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.
 

Thread Starter

AFAS87

Joined Oct 9, 2008
23
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.
 

eng1ne

Joined Dec 4, 2009
97
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.
 

Thread Starter

AFAS87

Joined Oct 9, 2008
23
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.
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

AlexR

Joined Jan 16, 2008
732
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.
 

Thread Starter

AFAS87

Joined Oct 9, 2008
23
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
 

eng1ne

Joined Dec 4, 2009
97
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.
 
Top