Skip to content

STM8 eForth Board Character IO

Thomas edited this page Jan 21, 2018 · 2 revisions

LED & Pushbutton Character I/O

Many cheap STM8 boards feature 7S-LED displays and keys. STM8 eForth supports these through vectored I/O as I/O devices. The behavior is similar to a I/O redirection in PC operating systems.

Board Keys Character Input

Keys are read as a bit pattern by the word BKEY (typically implemented in boardcore.inc), and then translated to ASCII characters by a simple mapping.

The word ?KEYB does a simple translation of the key bit-field value to ASCII codes. The translation is defined by BKEYCHAR in boardcore.inc.

As an example, the W1209 thermostat boardcore.inc maps the 3 keys as follows:

Key ?KEYB BKEY
"SET" "A" (0x41) 0x01
"+" "B" (0x42) 0x02
"-" "D" (0x44) 0x04

Pressing multiple keys leads to an ASCII code corresponding to the value of the bit-field (e.g. "SET" and "-" result in the code 0x45 (ASCII "E").

Character Output on a 7S-LED Display

LED displays appear as right-aligned digit groups (e.g. boards W1219 2x 3-digits, or W1401 3x 2-digits) that each work similar to the display of a pocket calculator:

  • CR moves the cursor to the first (leftmost, upper) 3-digit group without blanking it
  • SPACE after another printable character moves the cursor to the next group, and blanks it
  • . is rendered as DP without shifting characters to the left
  • , is rendered as a blank

Emitting more than the characters of a group won't spill into the next group (23..,5 is rendered as 3. 5).

Character Output and LED Patterns

The I/O word E7S sends an ASCII char to the LED pattern buffer, and on the lower level the word P7S can be used to display an 8bit LED pattern:

\ display 0º on the 7S-LED display (48 is ASCII for "0")
48 E7S $63 P7S

Vectored I/O

Using vectored I/O it's possible to redirect console I/O to the 7S-LED display:

' E7S 'EMIT !

However, the 3 digits are just enough for showing ok (the EMIT vector can be restored with ' TX! 'EMIT !).

On supported boards with 7S-LED displays (e.g. W1209, W1219, or W1401) the background task displays data on the 7S-LED display: E7S is used through vectored I/O.

This makes displaying measured data very simple. The following code displays different data (all scaled to a range of 0..99) on the 3x2 digit 7S-LED groups of the board W1401:

: timer TIM 655 / ;
: ain 5 ADC! ADC@ 100 1023 */ ;
: show timer . ain . BKEY . CR ;
' show bg !

The word show displays the values scaled to 0..99 from the BG timer, the sensor analog input, and the board key bitmap BKEY followed by a CR (new line). When the word show runs in the background, it displays the ticker on the left yellow 7S-LED group, ain on the middle red LEDs, and the board key bitmap on the right yellow group.

In a background task the ?KEY vector is assigned to ?KEYB for reading board keys in the same way as ?RX does in the foreground task for reading characters from the serial interface.

When ?KEYB is used in a background task it performs key repetition (with initial delay). This makes implementing simple "+/- editors" with "hold to change" easy. The code in W1209 pulse generator provides an example.

Clone this wiki locally