Close
0%
0%

Smart Response PE Full Keyboard Decode

Main.C code to easily decode any button press by using Switch-Case statements.

Similar projects worth following
0 followers
User "serisman" back in 9/2018 posted code to repurpose the surplus Smart Response PE units.
http://community.arduboy.com/t/smart-response-xe-re-purposed-into-arduboy/6094/337

Of interest to application programmers is the lower-level keyboard code which appeared here:
http://github.com/serisman/Smart-Response-PE/tree/master/lib/keypad

The above code collectively manages the keyboard events but makes application programming more complex than necessary for simple application usage. Rather than deal with the primitive state of the keyboard, I implemented a higher-level abstraction where each key represents a single unique number and rolled this into a traditional C-style SWITCH-CASE statement that the programmer can utilize as a base template for keyboard entry projects. All buttons of the PE device are available to the user.

Traditional C-style implementation for any program using Smart Response PE

// Name: main.c
// Project: C:\Users\Ray\Documents\Workarea\SMART_PE\Keyboard Template
// Author: Stephen Erisman <github@serisman.com>
// Creation Date: 2018-09-21
// License: MIT

#include "Arduino.h"
#include "hal.h"
#include "util.h"
#include "string_utils.h"
#include "clock.h"
#include "display.h"
#include "keypad.h"

#define FPS                 30u

char __xdata str_buf[12];
uint32_t Results = 0;

void setup() {
oscillator_32mhz();
clock_init();
ENABLE_INTERRUPTS;
display_init();
display_set_frame_rate(FPS);
}

void loop() {
  // Wait until its time to render our next frame
  if (!display_next_frame())
    return;

  keypad_poll();
  // Display Hello World!
  display_set_cursor(0,0); // line 1 of 5
  display_print("Hello World! v251114");

  if (keypad_any_pressed()) {
    // Display the name of any currently pressed buttons
    for (uint8_t col=0; col<4; col++) {
      for (uint8_t row=0; row<8; row++) {
        uint8_t mask = util_bit_to_mask[row];
        if (keypad_pressed(col, mask)) {
          // display_set_cursor(3,25);
          // display_print(keypad_get_button_name(col, mask));
          // display_print(" pressed! == ");
  Results = (uint8_t)(row * 5 + col);
  u32_to_str(str_buf, Results);
  // display_print(str_buf);
        }
      }
    }

display_set_cursor(0, 10); // line 2 of 5
switch (Results)
{
case 0: // Enter
display_print("Enter Key");
break;
case 1: // Lf arrow 
display_print("Check Mark");
break;
case 2: // Rt arrow
display_print("Cancel Key");
break;
case 3: // del/Backspace
display_print("Backspace");
break;
case 5: // ?
display_print("? Mark");
break;
case 6: // A/1
display_print("Digit 1");
break;
case 7: // B/2
display_print("Digit 2");
break;
case 8: // C/3
display_print("Digit 3");
break;
case 10: // Home
display_print("Home");
break;
case 11: // D/4
display_print("Digit 4");
break;
case 12: // E/5
display_print("Digit 5");
break;
case 13: // F/6
display_print("Digit 6");
break;
case 15: // Up
display_print("Up Key");
break;
case 16: // G/7
display_print("Digit 7");
break;
case 17: // H/8
display_print("Digit 8");
break;
case 18: // I/9
display_print("Digit 9");
break;
case 20: // Down
display_print("Down Key");
break;
case 21: // +/-
display_print("Change Sign");
break;
case 22: // J/0
display_print("Digit 0");
break;
case 23: // x-y/.
display_print("Decimal Point");
break;
case 35: // Power
display_print("Power On/Off");
break;
default:
break;
}
    //display_set_cursor(12,33);
display_set_cursor(0,0);
  }
  // Paint the screen buffer to the LCD
  display_paint(true);
}

// LCD Notes

/* DISPLAY FORMAT standard font (medium) is represented as 5 lines with 21 characters per line
//    000000000111111111122
//    123456789012345678901
display_set_cursor(0,0); display_print("01020304050607080910.");
display_set_cursor(0,10); display_print("01020304050607080910.");
display_set_cursor(0,20); display_print("01020304050607080910.");
display_set_cursor(0,30); display_print("01020304050607080910.");
display_set_cursor(0,40); display_print("01020304050607080910.");

display_paint(true);
*/

PE Keyboard Template.zip

Must Use SDCC to compile. Binary uploaded using TI CC Debugger or equiv. See the batch file Go.bat which will build the executable.

x-zip-compressed - 120.91 kB - 12/10/2025 at 15:51

Download

  • 1
    Building the binary

    The compiler SDCC is used to compile and link the binary.

    I have provided 5 batch files which will assist:

    Check.bat, Clean.bat, Compile.bat, and Link.bat with the wrapper Go.bat which will complete the entire process.  Please note that GO.BAT also completes the necessary conversion of the binary for use by CC Debugger:

    Mandatory after linking: packihx main.ihx >KeyPadTest.hex

View all instructions

Enjoy this project?

Share

Discussions

Does this project spark your interest?

Become a member to follow this project and never miss any updates