Main Page

COMATOS KeyPad Driver:


Keypad is a very useful tool for many microcontroller related programs. This version of COMATOS contains a build-in 16-key keypad driver. With this feature, the user will no longer need to implement a separate debounce press state machine and keypad search function inside the program. (This program is still in its testing phase, there are no guarantees that it is going to work for every program).


The keypad driver in COMATOS has a debounce press state machine and a keypad mapping functions. Because the debounce press state machine is a real-time operation (detect a button press every 30ms), the easiest way is to use the first task in OS as the debounce press state machine. Once the keypad driver determines the location of the key press, the driver will then determine the key press from a mapping array located in comatos8515.h file and store the value as character in a buffer. All the keys on the keypad serve the same function as the represented symbols except for keys A thru D.

Key A: Enter Key
Key B: No Function
Key C: No Function
Key D: Clear the buffer

















The keypad driver is designed to work for the above keypad scheme


Keypad Function calls:

  1. OSKeyPadInit(void): This command will initialize all the necessary constants for the keypad, such as designating keypad detection as the first task, and initializing debounce time and state. Only call this command when keypad is required for certain tasks.
  2. OSKeyPadDebounce(void): This function call is responsible for the 4 state debounce press scheme introduced earlier in the DMC tutorial. The OS will execute this function every 30ms once keypad driver is initialized.
  3. OSKeyPad_Read(void): Since the 4 by 4 keypad is composed of four vertical and four horizontal wires crossing each other, one can use a simple upper and lower nimble detection algorithm to determine the location of the key press. Once the location is determined, an 8-bit binary number is produced and the keypad driver will use the 8-bit binary number to identify the corresponding character.
  4. OSKeyPadWriteBuffer(char Key): A string of characters are often required rather than a single key. A buffer is used for such occasion. Every time a key is pressed, the corresponding character will automatically be loaded into the buffer. The buffer will stop taking more characters if the enter key ‘A’ is pressed, or the buffer is full (usually, the buffer can accept up to 32 characters).
  5. OSKeyPadClearBuffer(void): If the user makes a mistake, a delete key is available for the user to change the input. When the delete key ‘D’ is pressed, the OS will call this function to erase the ENTIRE buffer, not just the previous key press.
  6. OSGetKeyReady(unsigned char x): This function ensures that if the keypad driver is being used by one task, other tasks will not have access to the driver until the current task is finished.
  7. OSGetKeyCommand(char *data): This function serves two purposes. First, it translates the character buffer into a string. Second, it unlocks the keypad driver so that other tasks can have access to it.


Out of the seven keypad functions, the user should only use OSKeyPadInit, OSGetKeyReady, and OSGetKeyCommand; the rest of the functions are not available to the user. A example of how to use the keypad driver is given here. A complete listing of the keypad driver code is located below.

Keypad Drive Code



Main Page





Questions? Contact Nick Liu