Bob Parihar
Member
iam about to interface a 4x4 hex keypad with pic16f877a
here is my 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==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.
here is my 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==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.