stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 282

Day 282 of 365 · Expert · Month 10: Bits and data

Text with STR()

STR() packs up to six ASCII characters into one number: text on LED displays in string mode, how the characters are laid out and which errors come with umlauts and long words.

Lesson 16 min Week 41

What you learn today

  • Pack up to six ASCII characters
  • Text on displays
  • Limits of STR

A display reading “101.3” tells your colleague nothing if he does not know what is being measured. “OK” or “MAX” is understood by everyone. IC10 has no strings – but it can pack up to six letters into one number.

STR()

STR("OK") is replaced by a number when the code is loaded, just like HASH(). Every character takes 8 bits, the first character sits at the very top:

TextBytesNumber
STR("A")6565
STR("OK")79, 7579 · 256 + 75 = 20299
STR("MAX")77, 65, 885063000

Six characters are 48 bits and therefore fit into the 53 bits of a register. A seventh no longer fits.

Text on the display

An LED display shows Setting as text when its Mode is set to DisplayMode.String (10). The game reads the number back into characters byte by byte:

sbn DISP HASH("Status") Mode DisplayMode.String
sbn DISP HASH("Status") Setting STR("OK")

Since STR() is just a number, you can use it in define, move and select like any other constant. That way a chip chooses between ready-made texts:

move text TX_OK
slt tmp press P_MIN
select text tmp TX_MIN text      # too low

Limits of STR

ErrorCause
InvalidStringLength (28)more than six characters
InvalidStringNull (29)empty text STR("")
InvalidStringNonAscii (30)characters outside ASCII, such as umlauts
Warning

STR("KÜHL") cannot be loaded – the Ü is not an ASCII character. Write “KUEHL”, just as with device names.

Note

The preprocessor replaces STR() when loading. It cannot turn a register into text. How to insert digits into a text at run time is shown in Saturday's project – with ins, because every character is simply an 8-bit field.

Exercise

Task

Show the state of the room “Raum” as text on the display “Status”:

  • the display is in mode DisplayMode.String
  • “OK” between 80 and 120 kPa
  • “MIN” below 80 kPa, “MAX” above 120 kPa
  • “ERROR” when the sensor is missing

Hints

Hint 1

The mode is set by sbn DISP HASH("Status") Mode DisplayMode.String.

Hint 2

Start with move text TX_OK and overwrite with select.

Hint 3

The sensor failure comes last so it overwrites everything else.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere