/************************************************************************
*Program to scan a keypad on P1 and output the pressed kay value to P0 *
*P1.0 - P1.3 rows P1.4 - P1.7 columns *
*Process key flag = 4OH
************************************************************************/
#include <stdio.h>
#include <reg51.h>
int index;
int id;
int num;
sbit P1four = P1^4;
sbit P1five = P1^5;
sbit P1six = P1^6;
sbit P1seven = P1^7;
int cscan (void);
void main (void){
if (IE0 == 1){
index = 0;
while (index == 0){
P1 = ~1;
id = cscan;
P1 = ~2;
id = cscan;
P1 = ~3;
id = cscan;
}
IE0 = 0;
}
}
int cscan (void){
if (P1four == 0){
index = 1;
return (num);
}
num ++;
if (P1five == 0){
index = 1;
return (num);
}
num ++;
if (P1six == 0){
index = 1;
return (num);
};
num ++;
if (P1seven == 0){
index = 1;
return (num);
}
num ++;
return (num);
}
|