Wednesday, November 12, 2008

#include

int readKeyPad (void);
void displayKey (int key);
void main(void){
int key;
TRISA=0x00;
TRISB=0x0f;
TRISC=0x00;

while(1){
key = readKeyPad();
displayKey(key);
}
}




int readKeyPad (void){
int temp;
PORTB=0x70;
temp=PORTB&0x0F;


switch(temp){
case 7 :return 1;
case 11: return 2;
case 13: return 3;
case 14: return 0x0A;
}
PORTB=0xB0;
temp=PORTB&0x0F;

switch(temp){
case 7 :return 4;
case 11: return 5;
case 13: return 6;
case 14: return 0x0B;
}
PORTB=0xD0;
temp=PORTB&0x0F;

switch(temp){
case 7 :return 7;
case 11: return 8;
case 13: return 9;
case 14: return 0x0C;
}
PORTB=0xE0;
temp=PORTB&0x0F;

switch(temp){
case 7 :return 0;
case 11: return 0;
case 13: return 0;
case 14: return 0x0D;
}
}
void displayKey (int key){

unsigned char disp[]={0x7e,0x0c,0xb6,0x9e,0xcc,0xda,0xfa,0x0e,0xfe,0xce,0xee,0xf8,0x72,0xbc};
PORTA=0xfe;
PORTC=disp[key];
}

Posted by dear benji at 9:20 PM