/* main.c */ /* Read from a keypad and display the key pressed */ /* on an 7-segment display */ #pragma SMALL DB OE #include <reg51.h> unsigned char SetDisplay(unsigned char value){ unsigned char LookupTable[17] = { 0xC0, ... }; /* use code from previous lab */ /* fill in entries to table to handle A, B, C, D, E, F */ } /* Routine to scan the key pressed */ unsigned char key_scan() { unsigned char i, j, temp1, temp2; while( 1 ) /* keep waiting for a key to be pressed */ for(i=0; i<4; i++) { /* Set each row to 0 */ P1 = 0xff & ~(1<<i); /* Scan each column to see which key was pressed */ for (j=4; j<8; j++) { /* Code to determine the position of the key which was pressed */ /* return(position) */ } } } void main() { /* You can have a conversion table to convert the key position into a valid number or letter. The "*" and "#" symbols result in errors and map into postion 17 of the LookupTable */ unsigned char conv_table[] = { 1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, 17, 0, 17, 13 }; char num; while(1) { /*read input from user */ /* display corresponding number */ } }