Page 454 - Programming Microcontrollers in C
P. 454
Keyboard 439
break;
case 4: r=1;
break;
case 2: r=2;
break;
case 1: r=3;
break;
default: r=4;
}
switch(*p & 0xf0)
{
case 0x10: c=0;
break;
case 0x20: c=1;
break;
case 0x40: c=2;
break;
case 0x80: c=3;
break;
default: c=4;
}
if(r==4||c==4)
break; /* got a multiple key hit, skip it*/
*p++=keys[r][c];
}
*p=’\0';
data=savedata;
}
Lastly, after the character is read from the array and stored into
the array, the loop is continued. When the loop is terminated, a null
character is written to the next entry in the array. This character is a
string terminator and the data can be used as such with any of the
input/output functions. In the initialization routine, two values of
pointers to the array a[] were saved. The value saved in data has
been corrupted by now and it is necessary to restore it to its original
value by assigning savedata to data.
Next, we have to test the code above. The following program
tests the keyboard initialization and isr routines. To use these
routines, you must first adjust the code in the program handler()
and recompile it. This code must be linked to the following program.
The address of the routine kb_isr() must be placed in the specified
location in the vector table found with the handler() function.

