Problem in HEX keypad inderfacing

Thread Starter

bobparihar

Joined Jul 31, 2014
93
iam about to interface a 4x4 hex keypad with pic16f877a
here is my code

Code:
#include"lcd.h"      //lcd header file( working properly with both string and numbers)
void main()
{
unsigned int ar[]={0xE7,0xD7,0xB7,0x77,0xEB,0xDB,0xBB,0x7B,0xED,0xDD,0xBD,0x7D,0xEE,0xDE,0xBE,0x7E};      //scanning code for (4x4)keypad

unsigned int a,b,c,i;
init();
TRISD=0;                        // keypad connected to portd
   while(1)
     {
       PORTD=0x0F;                                            // initially 0F
     while(PORTD==0x0F);                             /*wait for any key to pressed( here PORTD status supposed be 0F untill any button is pressed, but it changes by default as shown in simulation in proteus below. That is why  the code below doesent work properly*/

// but in 8051 the status of any port does changes only when the button is pressed and the code further work properly

       a=PORTD;                                            

       PORTD=0xF0;

       b=PORTD;
       c=a|b;
       for(i=0;i<16;i++)
         {
           if (ar[I]==c)
           num(i);
         }
     }
}
This code has been tested with 8051 and has being properly working..provided the syntax changed for 8051 programing e.g. P2 instead of PORTD... etc.

as u see in the snapshot yellow dots are there instead of red or blue

whats wrong could anybody explain??
here is the snapshot of simulation at the early stage when no key is being pressed.
 

Attachments

Last edited by a moderator:

yuanan00157

Joined Oct 20, 2014
4
dear
bobparihar:


I do not understand the code

Code:
if (ar==c)
is the pointer type constant .Is it same to the code
Code:
 if(ar[I]==c)
And,i am not good at PIC series MCU ,and are you sure the electric current input is more strong to current output ?
And you can try like this :
Code:
#include"lcd.h" //lcd header file( working properly with both string and numbers)
void main()
{
unsigned int ar[]={0xE7,0xD7,0xB7,0x77,0xEB,0xDB,0xBB,0x7B,0xED,0xDD,0xBD,0x7D,0xEE,0xDE,0xBE,0x7E}; //scanning code for (4x4)keypad

unsigned int a,b,c,i;
init();
[COLOR=#ff0000]//[/COLOR]TRISD=0; // keypad connected to portd
while(1)
{
[COLOR=#ff0000]TRISD=0x0f;[/COLOR]
PORTD=0x0F; // initially 0F
while(PORTD==0x0F); /*wait for any key to pressed( here PORTD status supposed be 0F untill any button is pressed, but it changes by default as shown in simulation in proteus below. That is why the code below doesent work properly*/

// but in 8051 the status of any port does changes only when the button is pressed and the code further work properly

a=PORTD;
[COLOR=#ff0000]TRISD=0xf0;[/COLOR]
PORTD=0xF0;

b=PORTD;
c=a|b;
for(i=0;i<16;i++)
{
if (ar[i]==c)
num(i);
}
}
}
My english is so so ,please never mind .
 
Last edited by a moderator:

yuanan00157

Joined Oct 20, 2014
4
dear
bobparihar:

I do not understand the code "if (ar==c)". "ar" is the pointer type constant .Is it same to the code "if(ar==c)"?
And,i am not good at PIC series MCU ,and are you sure the electric current input is more strong to current output ?
And you can try like this :
------------------------------------------------------------------------------------------------------------
#include"lcd.h" //lcd header file( working properly with both string and numbers)
void main()
{
unsigned int ar[]={0xE7,0xD7,0xB7,0x77,0xEB,0xDB,0xBB,0x7B,0xED,0xDD,0xBD,0x7D,0xEE,0xDE,0xBE,0x7E}; //scanning code for (4x4)keypad

unsigned int a,b,c,i;
init();
//TRISD=0; // keypad connected to portd
while(1)
{
TRISD=0x0f;
PORTD=0x0F; // initially 0F
while(PORTD==0x0F); /*wait for any key to pressed( here PORTD status supposed be 0F untill any button is pressed, but it changes by default as shown in simulation in proteus below. That is why the code below doesent work properly*/

// but in 8051 the status of any port does changes only when the button is pressed and the code further work properly

a=PORTD;
TRISD=0xf0;
PORTD=0xF0;

b=PORTD;
c=a|b;
for(i=0;i<16;i++)
{
if (ar==c)
num(i);
}
}
}
---------------------------------------------------------------------------------------------

My english is so so ,please never mind .
my god !--it cannot show the word on the follow snapshot !
 

Attachments

MrChips

Joined Oct 2, 2009
30,708
Trying to show

Code:
ar[I] = c;
gets interpreted as italics formatting on a bulletin board.

Use code tags when posting code.
 
Last edited:

JWHassler

Joined Sep 25, 2013
306
iam about to interface a 4x4 hex keypad with pic16f877a
here is my code

Code:
#include"lcd.h"      //lcd header file( working properly with both string and numbers)
void main()
{
unsigned int ar[]={0xE7,0xD7,0xB7,0x77,0xEB,0xDB,0xBB,0x7B,0xED,0xDD,0xBD,0x7D,0xEE,0xDE,0xBE,0x7E};      //scanning code for (4x4)keypad

unsigned int a,b,c,i;
init();
TRISD=0;                        // keypad connected to portd
   while(1)
     {
       PORTD=0x0F;                                            // initially 0F
     while(PORTD==0x0F);                             /*wait for any key to pressed( here PORTD status supposed be 0F untill any button is pressed, but it changes by default as shown in simulation in proteus below. That is why  the code below doesent work properly*/

// but in 8051 the status of any port does changes only when the button is pressed and the code further work properly

       a=PORTD;                                          

       PORTD=0xF0;

       b=PORTD;
       c=a|b;
       for(i=0;i<16;i++)
         {
           if (ar[I]==c)
           num(i);
         }
     }
}
This code has been tested with 8051 and has being properly working..provided the syntax changed for 8051 programing e.g. P2 instead of PORTD... etc.

as u see in the snapshot yellow dots are there instead of red or blue

whats wrong could anybody explain??
here is the snapshot of simulation at the early stage when no key is being pressed.
I don't know much about PICs, but....
Does Port D have any peripherals (ADC, timer etc) enabled by default that would make some of the higher-order pins non-zero?
Also: how does PortD[3:0] become non-zero when all outputs to the matrix (PortD[7:4]) are zeros?
 
Top