Skip to content

Commit

Permalink
library additions
Browse files Browse the repository at this point in the history
  • Loading branch information
TG9541 committed Aug 5, 2017
1 parent 3bc84af commit cb2d9e5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/hw/pd8544.fs
Original file line number Diff line number Diff line change
@@ -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

36 changes: 36 additions & 0 deletions lib/hw/spi.fs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cb2d9e5

Please sign in to comment.