Skip to content

Instantly share code, notes, and snippets.

@bademux
Forked from TG9541/ws2812.fs
Created May 3, 2020 12:57
Show Gist options
  • Save bademux/12ce9b9f34be77b57a9e7dc579ac8d26 to your computer and use it in GitHub Desktop.
Save bademux/12ce9b9f34be77b57a9e7dc579ac8d26 to your computer and use it in GitHub Desktop.
STM8 eForth WS2812 demo with tested timing
\ A STM8 eForth WS2812 demo with tested timing
\ 8 x WS2812B on PCB with 470µF capacitor at 5V supply
\ 3.3V MINDEV: PB4 with 1K pull-up to 5V works well
\res MCU: STM8S103
\res export PB_DDR PB_ODR PB_CR1
#require ]B!
#require ]CB
NVM
\ transfer memory area a0.. a1 to a chain of WS2812
: WS2812 ( a1 a0 -- )
DO [
$1601 , \ LDW Y,(1,SP)
$90F6 , \ LD A,(Y)
$88 C, \ PUSH A
$A608 , \ LD A,#8
HERE \ 0$:
] [ 1 PB_ODR 4 ]B! [
$0901 , \ RLC (1,SP)
$9D C, \ NOP
$9D C, \ NOP
] [ PB_ODR 4 ]CB [
$9D C, \ NOP
$9D C, \ NOP
$9D C, \ NOP
$9D C, \ NOP
] [ 0 PB_ODR 4 ]B! [
$9D C, \ NOP
$4A C, \ DEC A
$4D C, \ TNZ A
$26 C, \ JRNE ...
HERE - 1- C, \ ... 0$
$84 C, \ POP A
]
LOOP ;
: init ( -- )
[ 0 PB_ODR 4 ]B!
[ 1 PB_DDR 4 ]B!
[ 1 PB_CR1 4 ]B! ;
RAM
\\ Example
8 3 * CONSTANT #mem \ memory for 8 x WS2812
VARIABLE wsmem #mem 2- ALLOT
\ simple test
: test ( n -- )
init
255 FOR
wsmem #mem I FILL
wsmem #mem + wsmem WS2812
DUP FOR ( wait ) NEXT
NEXT DROP ;
\ e.g. 10000 test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment