LCD HD44780

The LCD HD44780 is the lingua franca amongst the display modules found around microcontrollers. They need only 4 data bits and 3 control bit to work. Gerald Wodni published a LCD driver module on TheForth.net which works with amforth as well.

The basic driver module needs only a few adjustments basically moving the IMMEDIATE from within the definitions to rigth after the finishing semicolon.

\ Demo for using the library with Mecrisp on an MSP430G2553
\ (c)copyright 2017 by Gerald Wodni<gerald.wodni@gmail.com>
\ adapted for amforth on the same platform by Matthias Trute

\ Wiring:
\ LCD    uC
\ D4  -- P2.0
\ D5  -- P2.1
\ D6  -- P2.2
\ D7  -- P2.3
\ RS  -- P2.4
\ E   -- P2.5

\ RW  -- GND

\ #require 1-ms.frt
\ #require ms.frt

\ Ports
$29 constant P2OUT
$2A constant P2DIR

: init-ports
   $3F P2OUT c!
   $3F P2DIR c! ;

\ from bitnames.frt, modified
: c-or! ( bm addr  -- )
  dup c@ rot or swap c! ;
: c-and! ( bm addr -- )
  dup c@ rot invert and swap c! ;

: lcd-mode-data ( -- )
  $10 P2OUT c-or! ;

: lcd-mode-cmd ( -- )
  $10 P2OUT c-and! ;

: lcd-nibble ( x -- )
  $F P2OUT     c-and!  \ clear data
  $F and P2OUT c-or!   \ set data
  1ms $20 P2OUT c-and! \ pulse E
  1ms $20 P2OUT c-or!
  1ms ;

\ used in lib:
: 0<> 0= 0= ;
\ from the-forth.net
\ #require lcd-hd44780.4th
\ swap-dragon image (3 by 2 custom chars)
create d0 $00 c, $02 c, $03 c, $07 c, $06 c, $00 c, $00 c, $0C c,
create d1 $00 c, $00 c, $00 c, $00 c, $11 c, $11 c, $0A c, $1B c,
create d2 $00 c, $08 c, $18 c, $1C c, $0C c, $00 c, $00 c, $0C c,
create d3 $1F c, $1D c, $18 c, $10 c, $00 c, $00 c, $00 c, $00 c,
create d4 $1B c, $1F c, $1F c, $0E c, $0A c, $0A c, $1B c, $00 c,
create d5 $1F c, $17 c, $03 c, $01 c, $00 c, $00 c, $00 c, $00 c,

: demo
   init-ports \ set ports
   2 lcd-init \ 2 line lcd
   d0 0 lcd-char \ transmit dragon custom chars
   d1 1 lcd-char
   d2 2 lcd-char
   d3 3 lcd-char
   d4 4 lcd-char
   d5 5 lcd-char
   lcd" theforth.net   "
   0 lcd-emit 1 lcd-emit 2 lcd-emit
   $40 lcd-ddram \ 2nd line
   lcd" amforthMSP430"
   3 lcd-emit 4 lcd-emit 5 lcd-emit ;

Calling the demo command displays some text and a nice swap dragon

../../_images/LCD-HD44780.png