Skip to content

Instantly share code, notes, and snippets.

@VK6TT
Last active January 29, 2018 05:49
Show Gist options
  • Save VK6TT/c866e99af9e8305be4857226a69aa9cb to your computer and use it in GitHub Desktop.
Save VK6TT/c866e99af9e8305be4857226a69aa9cb to your computer and use it in GitHub Desktop.
STM8 eforth - Displaying number on W1209 3 digit display
\ to display a number on the 3 character display of the W1209 board
\ formatted xx.x ie one decimal place
\ using extract and digit ie existing words
: Clrdisplay 32 E7S 32 E7S 32 E7S ;
: DIGIT [ $CC C, $88F1 , OVERT
: EXTRACT [ $CC C, $88FE , OVERT
: .dp 46 E7S ;
: Clrdisplay 32 E7S 32 E7S 32 E7S ;
: .V ( n1 --- )
10 extract swap \ units n1/10
10 extract swap \ ( units tens 100's --- )
digit
clrdisplay
E7S E7S .dp E7S
;
\ however, if we factor and write our own words we can do this
: Clrdisplay 32 E7S 32 E7S 32 E7S ;
: .dp 46 E7S ;
: Digit 48 + ;
: #E7S digit E7S ;
: .V ( n1 --- )
10 /mod \ units n1/10
10 /mod \ ( units tens 100's --- )
clrdisplay
#E7S #E7S .dp #E7S
;
\ although Digit looks pedantic, so the following is my final code
\ : Clrdisplay 32 E7S 32 E7S 32 E7S ; \ not needed if we always emit 3 characters to display
: .dp 46 E7S ;
: #E7S 48 + E7S ; \ convert to single number to ascii and display
: .V ( n1 --- )
10 /mod \ units n1/10
10 /mod \ ( units tens 100's --- )
#E7S #E7S .dp #E7S
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment