Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with Keypad interfacing using PIC16F887

Status
Not open for further replies.

zia.newversion

Member level 5
Joined
Mar 28, 2010
Messages
83
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Pakistan
Activity points
2,188
Alright pals. Here is my code.
Code:
char keypadPort at PORTD;
unsigned char keyPress;
unsigned char keyValue;

void main() {

     Keypad_Init();
     keyPress = 0x00;
     keyValue = 0x00;
     
     do
       keyPress = Keypad_Key_Click();
     while (keyPress != 0);
     
     switch(keyPress)
     {
      case 1:        keyValue = 0x01;   break;
      case 2:        keyValue = 0x02;   break;
      case 3:        keyValue = 0x03;   break;
      case 4:        keyValue = 0x04;   break;
      case 5:        keyValue = 0x05;   break;
      case 6:        keyValue = 0x06;   break;
      case 7:        keyValue = 0x07;   break;
      case 8:        keyValue = 0x08;   break;
      case 9:        keyValue = 0x09;   break;
      case 10:       keyValue = 0x0A;   break;
      case 11:       keyValue = 0x00;   break;
      case 12:       keyValue = 0x0C;   break;
      }
      
      PORTB = keyValue;
}

I am using MikroC for PIC IDE and the keypad library included in the package.

Here is the circuit diagram that I am using in Labcenter Proteus 7.6 for simulation of my code.


**broken link removed**


But this circuit is not working. I am at loss as to where the problem lies, the code or the connections. If someone knows please help me out. I shall be greatly thankful!
 

dear friend

just init the portb as output and pullups enable and try

regards

ml
 
Hi ML
I have no idea about pullups.

I just tried adding

TRISB = 0x00;

in the beginning of the code.

It is still not working. I have got the left most LED glowing and the rest do not glow even when I press a button on the keypad.
 

Assuming that the key reading is working OK:

Your LEDs are connected on the MSB part of the port, from RB4 to RB7, and you are sending the key value on the LSB part.

You change every keyvalue to;

keyValue = 0x10;
keyValue = 0x20;
keyValue = 0x30;
...
...
keyValue = 0xC0;

So the LEDs on RB4 to RB7 will receive the correct data.
 
Not sure about the above post. I didn't get what you were trying to say. But of course, since my brain is so worked up these days, I sometimes do not understand simple things...
Maybe I shall understand when I read it tomorrow. :p

Anyway, thanks all. I worked very hard on this and then I solved the problem. Actually, the button and keypad libraries were too intelligent for me to understand. So I did it manually. First in assembly and then in C... Both worked fine.

The problem was the practical factor mechanical debounce which has been included in the Proteus Models for buttons and keypads. It was making the keypad generate multiple readings. So the keypad-scan loop was running a number of times and giving wrong O/P. It lasts typically for 10~20ms. So included a delay after each read, so that it doesn't go back to re-reading the rows.

For any pal who has the same problem and comes looking for a drop from agua-la-vide, :) I am giving my code and diagram here.

Assembly Code:
[See the attachment.]
C Code:
[I was just experimenting. So I didn't save the code in C.]
Hex file:
[See the attachment]
Proteus Design:
[See the attachment]
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top