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:
| Text | Bytes | Number |
|---|---|---|
STR("A") | 65 | 65 |
STR("OK") | 79, 75 | 79 · 256 + 75 = 20299 |
STR("MAX") | 77, 65, 88 | 5063000 |
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
| Error | Cause |
|---|---|
InvalidStringLength (28) | more than six characters |
InvalidStringNull (29) | empty text STR("") |
InvalidStringNonAscii (30) | characters outside ASCII, such as umlauts |
STR("KÜHL") cannot be loaded – the Ü is not an ASCII character. Write “KUEHL”, just as with device names.
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