- This topic has 1 reply, 2 voices, and was last updated 10 years, 10 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › Keypad Interface Using C
Hi everyone..
I need c-program to scan the keypad ad send the result to first seriat port.
Here P1.0 to P1.3 should represent columns and
P2.0 to P 2.3 should represent rows.
This is where im stuck now.
# include <reg51.h> // Header for AT89C51
sbit R0=P2^0; // Row 1 of the Keypad
sbit R1=P2^1; // Row 2 of the Keypad
sbit R2=P2^2; // Row 3 of the Keypad
sbit R3=P2^3; // Row 4 of the Keypad
sbit C0=P1^0; // Column 1 of the Keypad
sbit C1=P1^1; // Column 2 of the Keypad
sbit C2=P1^2; // Column 3 of the Keypad
sbit C3=P1^3; // Column 4 of the Keypad
int row_read(); // Row Read Function Declaration
int col_read(); // Colum Read Function Declaration
void delay(int); // Dealy Function Declaration
void delay(int a)
{ int i;
for(i=0;i<a;i++); }
int row_read ()// Row Read Function Define
{
P2=0x0F; // Set The Higher Nibble High
if(R0==1)
{ return(1); }
else if(R1==1)
{ return(2); }
else if(R2==1)
{ return(3); }
else if(R3==1)
{ return(4); }
delay(10000); }
int col_read ()// Column Read Function Define
{
P1=0x0F; // Set The Lower Nibble High
if(C0==1)
{ return(1); }
else if(C1==1)
{ return(2); }
else if(C2==1)
{ return(3); }
else if(C3==1)
{ return(4); }
delay(10000);
}
main () { int j=0,i=0;
while(1)
Now here what should i write to call the rows and cloumns scanning functions + to get output..??
Hi Shan,
Please post the circuit diagram