From cb2d9e5e10d1b5c4fe9c0eeaa2b3c2dc5474b911 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 5 Aug 2017 14:01:19 +0200 Subject: [PATCH] library additions --- lib/hw/pd8544.fs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/hw/spi.fs | 36 +++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 lib/hw/pd8544.fs create mode 100644 lib/hw/spi.fs diff --git a/lib/hw/pd8544.fs b/lib/hw/pd8544.fs new file mode 100644 index 0000000..f9252bb --- /dev/null +++ b/lib/hw/pd8544.fs @@ -0,0 +1,63 @@ +\ STM8S103 PD8544 "Nokia 3110 LCD" +\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md + +#require hw/spi.fs +#include pd8544ctrl.fs + +NVM +\ send c through SPI, discard input +: LCDout ( c -- ) + 0 LCDdis + SPI + 1 LCDdis + drop +; + +\ set horizontal cursor to c ( 0..83 ) +: LCDx ( c -- ) + 0 LCDdat + $80 + LCDout + 1 LCDdat +; + +\ set vertical cursor to c ( 0..5 ) +: LCDy ( c -- ) + 0 LCDdat + $40 + LCDout + 1 LCDdat +; + +\ set cursor to (0,0) +: LCDhome ( -- ) + 0 LCDx 0 LCDy +; + +\ fill LCD with pattern c (use y auto increment) +: LCDfill ( c -- ) + LCDhome + 503 for + dup LCDout + next drop +; + +\ init ports, SPI, PD8544 with Vop c (0..127) +: LCDinit ( c -- ) + PD8544ctrl + SPIon + 0 LCDdat + $21 LCDout \ instructions extended + $14 LCDout \ bias 4 + $80 + LCDout \ Vop, e.g. 60 + $20 LCDout \ instructions normal + $0C LCDout \ display conf ($08:blank,$09:on,$0C:normal,$0D:inv) + 1 LCDdat + 0 LCDfill +; + +\ copy n chars starting at a to PD8544 +: LCDcpy ( a n -- ) + for dup C@ LCDout 1+ next drop +; + +RAM + diff --git a/lib/hw/spi.fs b/lib/hw/spi.fs new file mode 100644 index 0000000..3c168b2 --- /dev/null +++ b/lib/hw/spi.fs @@ -0,0 +1,36 @@ +\ STM8S103 SPI +\ derived from al177/stm8ef/HC12/boardcore.inc +\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md + +\ Example: +\ SPIon +\ $AA SPI . +\ SPIoff + +#require RAMmark +RAMmark +#include regs_spi.fs + +NVM + +\ Init and enable SPI +: SPIon ( -- ) + $14 SPI_CR1 C! \ master, CLK/8, CPOL=CPHA=0, MSB first + $01 SPI_CR2 C! \ no NSS, FD, no CRC + $54 SPI_CR1 C! \ enable SPI +; + +\ disable SPI +: SPIoff ( -- ) + 0 SPI_CR1 C! \ disable SPI +; + +\ Perform SPI byte cycle with result c +: SPI ( c -- c) + [ $E601 , $C752 , \ LD A,(1,X) LD SPI_DR,A + $0472 , $0352 , $03FB , \ BTJF SPI_SR,#1,SPITXE_WAIT + $7201 , $5203 , $FBC6 , \ BTJF SPI_SR,#0,SPIRXNE_WAIT + $5204 , $E701 , ] \ LD A,SPI_DR LD (1,X),A +; + +RAMdrop