Skip to content

Instantly share code, notes, and snippets.

@henkjanc
Created May 15, 2021 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henkjanc/76b35c71f911804f196fd788a0121a20 to your computer and use it in GitHub Desktop.
Save henkjanc/76b35c71f911804f196fd788a0121a20 to your computer and use it in GitHub Desktop.
A IC2 version of the ulisp display listing
; transcript of http://www.ulisp.com/show?2B6A
; I2C version of the ulisp display listing
(defvar EN #b00000100)
(defvar ~EN #b11111011)
(defvar RS #x01)
(defvar LCDADDR #x3F); Or use #x27. You can check with the i2c-scanner the correct address
(defvar LCDMODE #x08)
(defvar LCDFUNCSET #x20)
(defvar LCDCONTRL #x08)
(defvar LCDCURSON #x02)
(defvar LCDCURSOFF #x00)
(defvar LCDSETADDR #x80)
(defvar LCDCLR #x01)
(defvar LCDHOME #x02)
(defun exp-write (value)
(with-i2c (stream LCDADDR)
(write-byte (logior value LCDMODE) stream))
)
(defun pulse-enable (data)
(exp-write (logand (logior data EN) #xff))
(exp-write (logand data ~EN #xff)))
(defun write4bits(value)
(exp-write value)
(pulse-enable value))
; write either command or data
(defun send (value mode)
(let ((hi (logand value #xf0))
(lo (logand (ash value 4) #xf0)))
(write4bits (logior hi mode))
(write4bits (logior lo mode))))
(defun cmd (value)
(send value 0))
(defun write (value)
(send value RS))
(defun display (setting)
(cmd (logior LCDCONTRL setting)))
(defun clear ()
(cmd LCDCLR))
(defun home ()
(cmd LCDHOME))
(defun cursor (pos)
(cmd (logior LCDSETADDR pos) ))
(defun colrow (col row)
(+ col (nth row (list #x0 #x40 #x14 #x54))))
(defun ini ()
(delay 50)
(exp-write LCDMODE)
(delay 1000)
; we start in 8bit mode, try to set 4 bit mode
(cmd #x33)
; second try
(cmd #x33)
; third go
(cmd #x33)
; finally, set to 4-bit interface
(cmd #x32)
(cmd #x0e)
(cmd #x01))
(defun str (s)
(dotimes (i (length s))
(write (char-code (char s i)))))
(defun main ()
(ini)
(home)
(str "Hello")
(cursor (colrow 10 1))
(str "World!"))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment