\ Program Name: f052-nokia-5510-lcd.fs \ This program runs standalone, no other files are needed. \ Date: Thu Mar 22 10:42:51 AEDT 2018 \ Copyright 2017 t.porter , licensed under the GPL \ For Mecrisp-Stellaris by Matthias Koch \ Chip: STM32F051 \ Board: STM32F0 Discovery Board \ Terminal: e4thcom, Copyright (C) 2013-2017 Manfred Mahlow (GPL'd) https://wiki.forth-ev.de/doku.php/en:projects:e4thcom \ Clock: 8 Mhz using the internal STM32F051 RC clock, unless otherwise stated \ All register names are CMSIS-SVD compliant \ Note: gpio a,b,c,d,e, and uart1 are enabled by Mecrisp-Stellaris core as default. \ \ This Program Does : Lights all pixels on a Nokia 5510 LCD panel \ Note I purchased 4 of these units from Bangood China in 2014, all had scratched displays even tho they came with \ a stick on screen protector. Conclusion, these are secondhand, pulled from used phones. 5 x 1.6 Inch LCD Module SCM \ Development With Backlight For Nokia 5110 (SKU078678) AU$15.45 \ By Comparason a brand new, flawless, 2x8 char blue Vishay OLED sisplay is $14. \ \ Based on the excellent 5110 youtube videos by Julian Ilet: https://www.youtube.com/watch?v=RAlZ1DHw03g \ ------------------------------------ Required Utilities -------------------------------------------------\ compiletoram \ compiletoflash \ Some terminal colors : esc 27 emit ; : red ( -- cursor color ) esc ." [31;1m" ; : green ( -- cursor color ) esc ." [32;1m" ; : yellow ( -- cursor color ) esc ." [33;1m" ; : blue ( -- cursor color ) esc ." [34;1m" ; : magenta ( -- cursor color ) esc ." [35;1m" ; : cyan ( -- cursor color ) esc ." [36;1m" ; : white ( -- cursor color ) esc ." [37;1m" ; : colors cr red ." red " green ." green " yellow ." yellow " blue ." blue " magenta ." magenta " cyan ." cyan " white cr ; \ GPIO MODEs %00 constant INPUT %01 constant OUTPUT %10 constant ALT-FUNCT %11 constant ANALOG \ Reset MCU : reset? key? if white reset cr then ; ( hit Enter key to reset MCU ) \ ------------------------------------ Required Bitfield Utilities ----------------------------------------\ \ bf(x) code by Manfred Mahlow \ Prints a Register Bitfield. Example: GPIOC_MODER_MODER9 BF@ . : BF@ ( bf-offs a-addr mask -- bits ) >r @ swap rshift r> and ; \ Prints the Hex value of a Register Bitfield. Example: GPIOC_MODER_MODER9 BF? : BF? ( bf-offs a-addr mask -- hex ) >r @ swap rshift r> and ." $" hex. ; \ Stores a binary number into a Register Bitfield. No range checking is done. Example: %11 GPIOC_MODER_MODER9 BF! : BF! ( bits bf-offs a-addr mask -- ) swap >r over lshift >r lshift r@ and r> r@ bic! r> bis! ; \ Used to test that Register contents have actually been changed. \ Continues if passed, halts terminal if failed. Note: not all Registers can be read after being written. \ Example: \ OUTPUT GPIOA_MODER_MODER4 BF! ( PA4 is MARKER ) \ OUTPUT GPIOA_MODER_MODER4 =assert \ \ --> OUTPUT GPIOA_MODER_MODER4 =assert FALSE, press any key to continue : =ASSERT ( bf-offs a-addr mask -- true/false ) >r @ swap rshift r> and = if green ." TRUE " white cr else red ." FALSE! " yellow ." press any key to continue " white key drop then cr ; \ -------------------------------------------------------------------------------------------------------\ \ ** PROGRAM STARTS HERE ** \ -------------------------------------------------------------------------------------------------------\ \ #r f052-nokia-5510-lcd.fs (#r instructs e4thcom terminal to upload f052-nokia-5510-lcd.fs to board) \ -------------------------------------------------------------------------------------------------------\ compiletoram \ compiletoflash \ 5110 Display note: PB2 - PB7 are FT or Fivevolt Tolerant \ --------------------------------------------------------- \ PIN NUMBER GPIO WIRE COLOR NOTES \ 1 RST PB2 ORANGE Reset, active LOW \ 2 CE PB3 YELLOW Chip Enable, active LOW \ 3 DC PB4 GREEN D=DATA, C=COMMAND (active low) \ 4 DATA PB5 BLUE \ 5 CLK PB6 PURPLE \ 6 VCC 3v GREY \ 7 LIGHT PB7 WHITE Active high \ 8 GND 0v BLACK \ LCD commands $21 CONSTANT EXT ( Lcd extended commands ) $B6 CONSTANT CON ( Lcd set contrast ) 4 CONSTANT COEF ( Lcd set temperature-coeff ) $14 CONSTANT BIAS ( Lcd bias mode ) $20 CONSTANT BASIC ( Lcd basic commands ) 9 CONSTANT ALLPIX ( Lcd all pixels on ) 8 CONSTANT CLEAR ( Lcd blank display ) $C CONSTANT NORM ( Lcd normal mode ) \ Memory Map : GPIOB_MODER_MODER7 14 $48000400 %11 ; ( Port x configuration bits y = 0..15 ) : GPIOB_MODER_MODER6 12 $48000400 %11 ; ( Port x configuration bits y = 0..15 ) : GPIOB_MODER_MODER5 10 $48000400 %11 ; ( Port x configuration bits y = 0..15 ) : GPIOB_MODER_MODER4 8 $48000400 %11 ; ( Port x configuration bits y = 0..15 ) : GPIOB_MODER_MODER3 6 $48000400 %11 ; ( Port x configuration bits y = 0..15 ) : GPIOB_MODER_MODER2 4 $48000400 %11 ; ( Port x configuration bits y = 0..15 ) : GPIOB_ODR_ODR7 7 $48000414 %1 ; ( Port output data y = 0..15 ) : GPIOB_ODR_ODR6 6 $48000414 %1 ; ( Port output data y = 0..15 ) : GPIOB_ODR_ODR5 5 $48000414 %1 ; ( Port output data y = 0..15 ) : GPIOB_ODR_ODR4 4 $48000414 %1 ; ( Port output data y = 0..15 ) : GPIOB_ODR_ODR3 3 $48000414 %1 ; ( Port output data y = 0..15 ) : GPIOB_ODR_ODR2 2 $48000414 %1 ; ( Port output data y = 0..15 ) : GPIOB_IDR_IDR7 7 $48000410 %1 ; ( Port input data y = 0..15 ) : GPIOB_IDR_IDR6 6 $48000410 %1 ; ( Port input data y = 0..15 ) : GPIOB_IDR_IDR5 5 $48000410 %1 ; ( Port input data y = 0..15 ) : GPIOB_IDR_IDR4 4 $48000410 %1 ; ( Port input data y = 0..15 ) : GPIOB_IDR_IDR3 3 $48000410 %1 ; ( Port input data y = 0..15 ) : GPIOB_IDR_IDR2 2 $48000410 %1 ; ( Port input data y = 0..15 ) \ Words : RST-HIGH ( PB2 ORANGE wire ) 1 GPIOB_ODR_ODR2 bf! ; : RST-LOW ( PB2 ORANGE wire ) 0 GPIOB_ODR_ODR2 bf! ; : CE->HIGH ( PB3 YELLOW wire ) 1 GPIOB_ODR_ODR3 bf! ; : CE->LOW ( PB3 YELLOW wire ) 0 GPIOB_ODR_ODR3 bf! ; : DC->HIGH ( PB4 GREEN wire ) 1 GPIOB_ODR_ODR4 bf! ; : DC->LOW ( PB4 GREEN wire ) 0 GPIOB_ODR_ODR4 bf! ; : DATA-HIGH ( PB5 BLUE wire ) 1 GPIOB_ODR_ODR5 bf! ; : DATA-LOW ( PB5 BLUE wire ) 0 GPIOB_ODR_ODR5 bf! ; : CLK-HIGH ( PB6 PURPLE wire ) 1 GPIOB_ODR_ODR6 bf! ; : CLK-LOW ( PB6 PURPLE wire ) 0 GPIOB_ODR_ODR6 bf! ; : BACKLIGHT-ON ( PB7 WHITE wire ) 1 GPIOB_ODR_ODR7 bf! ( This Backlight requires HIGH for ON, different to some other 5110 LCD's ) ; : BACKLIGHT-OFF ( PB7 WHITE wire ) 0 GPIOB_ODR_ODR7 bf! ; : delay 1000 0 do nop loop ; : lcd-reset ( lcd boot up, *required* about 1.7mS ) RST-LOW delay RST-HIGH ; : clockdata ( ? -- ) ( Creates a clock for each serialized bit ) if data-high else data-low then clk-high clk-low ; : >serialize ( c -- ) ( Serializes a byte, MSBit First, copied from Matthias Koch efm32hg322 LCD code ) dup 128 and clockdata dup 64 and clockdata dup 32 and clockdata dup 16 and clockdata dup 8 and clockdata dup 4 and clockdata dup 2 and clockdata 1 and clockdata ; : >CMD ( Adds preamble and postamble signals to a command byte, code based on Matthias Koch efm32hg322 LCD code ) CE->LOW DC->LOW >serialize CE->HIGH ; \ Micro init output GPIOB_MODER_MODER2 bf! ( RST is a OUTPUT ) output GPIOB_MODER_MODER3 bf! ( CE is a OUTPUT ) output GPIOB_MODER_MODER4 bf! ( DC is a OUTPUT ) output GPIOB_MODER_MODER5 bf! ( DIN is a OUTPUT ) output GPIOB_MODER_MODER6 bf! ( CLK is a OUTPUT ) output GPIOB_MODER_MODER7 bf! ( LIGHT is a OUTPUT ) lcd-reset \ LCD init ext >CMD con >CMD coef >CMD bias >CMD basic >CMD \ Main backlight-on allpix >cmd ( All the pixels should not turn on ) \ running 'clear >cmd' will clear the display