-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |