TACHYON
[~
{ ROLLING ODOMETER LCD DIGITS
Simulate the rolling odometer digits on a serial LCD display
tested at 9600, 38400, 57600, 115,200 baud
The serial codes suit my EcoLCD serial LCDs which are a superset of the SEETRONs
youtube video @9600 baud @38,400 baud @115,200 baud
}
\ Create an inverted serial out to suit the RS232 level display used in testing (otherwise just use SEROUT )
pub SEROUTI ( dataByte pin -- \ send data byte to pin at rate set with SERBAUD )
MASK DUP OUTCLR \ ensure pin is an output (very first time perhaps)
SWAP 2* $3FF XOR \ Include start bit (0), then invert all
baudcnt @ DELTA \ setup delay and wait
9 FOR WAITCNT SHROUT NEXT \ data bits
DROP WAITCNT OUTCLR \ final stop bit with output idling low (RS232 logic)
;
\ Create the LCD output word and redirection control
pub LCDEMIT ( ch -- )
DUP 1 SEROUTI $0C = IF 2 ms THEN \ emit and delay if it's a CLS command
;
\ redirects all character output to the LCD
pub LCD ' LCDEMIT uemit W! ;
\ Create the bitmap fonts for the 8 programmble characters including spacing and rollover from 9 to 0
TABLE font
%01110 | %10001 | %10011 | %10101 | %11001 | %10001 | %01110 | 0 | 0 | 0 | \ 0
%00100 | %01100 | %00100 | %00100 | %00100 | %00100 | %01110 | 0 | 0 | 0 | \ 1
%01110 | %10001 | %00001 | %00010 | %00100 | %01000 | %11111 | 0 | 0 | 0 | \ 2
%11111 | %00010 | %00100 | %00010 | %00001 | %10001 | %01110 | 0 | 0 | 0 | \ 3
%00010 | %00110 | %01010 | %10010 | %11111 | %00010 | %00010 | 0 | 0 | 0 | \ 4
%11111 | %10000 | %11110 | %00001 | %00001 | %10001 | %01110 | 0 | 0 | 0 | \ 5
%00110 | %01000 | %10000 | %11110 | %10001 | %10001 | %01110 | 0 | 0 | 0 | \ 6
%11111 | %10001 | %00001 | %00010 | %00100 | %00100 | %00100 | 0 | 0 | 0 | \ 7
%01110 | %10001 | %10001 | %01110 | %10001 | %10001 | %01110 | 0 | 0 | 0 | \ 8
%01110 | %10001 | %10001 | %01111 | %00001 | %00010 | %01100 | 0 | 0 | 0 | \ 9
%01110 | %10001 | %10011 | %10101 | %11001 | %10001 | %01110 | 0 | 0 | 0 | \ 0
\ draw a programmable character from memory - issue a "DEFINE CUSTOM CHARACTER" command $1B $44 index l0 .. l7
pub DRAW ( addr index -- )
LCD $1B EMIT "D" EMIT EMIT 8 TYPE CON
;
#52 "@" + == @odometer \ The position on the display where we want the eight odometer digits
\ Initialize the display
pub !ODOMETER
LCD CLS 4 EMIT ^T EMIT $0F EMIT \ Clear LCD, no cursor 4, full backlight ^T $0F
\ 12345678901234567890
." LCD ROLLING DIGIT "
CR ." ODOMETER "
^P EMIT @odometer EMIT \ position the cursor where the 8 digits go
8 0 DO $1C EMIT 7 I - EMIT LOOP CON \ force LCD codes 0-7 as raw characters
;
BYTE roll,rollflg
\ Print the number on the screen without the lsb digit, instead using that as the roll control
pub O \ quick test shortcut
pub .ODOMETER ( n*10 -- )
#10 U/MOD
SWAP roll C! \ rolling control
rollflg C~~ \ init rolling control
LCD ^P EMIT @odometer EMIT
0 8 ADO
#10 U/MOD ( digit rem )
OVER
#10 * font + \ lookup digit in font table
rollflg C@ IF roll C@ + THEN I DRAW \ add in roll if needed
( digit rem )
SWAP 9 <> IF rollflg C~ THEN \ done rolling?
LOOP
DROP
;
\ just an endless counting loop - terminates with an ESC from the console
pub DEMO ( start -- )
1
pub DEMO2 ( start delay -- )
SWAP !ODOMETER BEGIN DUP .ODOMETER 1+ OVER us ESC? UNTIL
2DROP
;
]~
END
!ODOMETER
\ #999998900 DEMO \ test full 8-digit wrap
#99800 DEMO