News:

;) This forum is the property of Proton software developers

Main Menu

Serial LCD Backpack using 16F690 for Hitachi 44780 display

Started by JackB, Sep 28, 2025, 11:50 PM

Previous topic - Next topic

JackB

Hello everyone,

For any hobbyist who's looking to build an affordable LCD project.

here's some code to share about the popular Hitachi HD44780 alphanumeric LCD display
it's working from 300 ~ 19200 baud with minimum part count to keep cost down.
complete project parts cost so far around $10. (pcb foot print 41x17mm)

the code that I used are 1) serial sender (12F683) and the backpack (16F690)

enjoy.


'-----------------------------------------------------------------------------
'  Project : Serial Sender 12F683
'  Name    : Serial LCD 300-19200.bas  for Hitachi HD44780
'  File    : "D:\Positron Code\12F683\Serial LCD\Serial LCD 300-19200.bas"
'  Date    : 9/28/2025
'  Notes   : Serial send
'          : 298 words used of 2048
'-----------------------------------------------------------------------------
Device = 12F683
Declare Xtal = 8
Config  INTOSCIO, WDT_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOD_OFF, IESO_OFF, FCMEN_OFF

Dim LCD As GPIO.0
Dim BaudR As Word
' 300=3313  600=1646  1200=813  2400=396  4800=188  9600=84  14400=49  19200=32
BaudR = 32
TRISIO = %00001000
OSCCON = $70
SerOut LCD, BaudR,[254,1] ' Clear LCD
DelayMS 40                ' LCD clear delay
Do
    SerOut LCD, BaudR,[254,128,"1234567890abcdef"]   ' Line 1, 16 Characters
    SerOut LCD, BaudR,[254,192,"1234567890abcdef"]   ' Line 2, 16 Characters
    DelayMS 1000
    SerOut LCD, BaudR,[255,0] ' Backlight Off
    DelayMS 100
    SerOut LCD, BaudR,[255,8] ' Backlight On
    DelayMS 2000
    SerOut LCD, BaudR,[254,1] ' Clear LCD
    DelayMS 2000
Loop


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Project : Backpack
' Name    : 16F690 LCD BACKPACK for Hitachi HD44780 
' Date    : Sep 28-2025
' Note    : 383 words used  of 4096
' Notes   : Serin  Baud Rate 300 ~ 19200
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Device = 16F690
Declare Xtal = 8
Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, IESO_OFF, FCMEN_OFF

DEFINE OSC 8        ' Core is running at 8MHz
ANSEL = 0           ' Set all pins digital
ANSELH = 0          ' Set all pins digital

TRISA = 0 : TRISB = %00100000 : TRISC = 0
PORTA = 0 : PORTB = 0 : PORTC = 0
OSCCON = $70 

Dim En As PORTB.4 : Low En
Dim RS As PORTB.6 : Low RS
Dim B1 As Byte : B1 = 0

' 300=3313  600=1646  1200=813  2400=396  4800=188  9600=84 14400=49 19200=32
Dim BaudR As Word : BaudR = 32

High PORTA.0              ' Backlight ON
GoSub LCDINIT             ' initialise LCD

'Serin
main:
    SerIn PORTB.5,BaudR,3,main,[B1]
If B1 < 253 Then     ' Characters
        PORTC = B1
        High En : DelayUS 5 : Low En
GoTo main
ElseIf B1 = 254 Then  ' LCD Command
Low RS           
        SerIn PORTB.5,BaudR,3,main,[B1]
PORTC = B1   ' output the data
        High En : DelayUS 5 : Low En
High RS           ' character mode
GoTo main         
ElseIf B1 = 255 Then 
        SerIn PORTB.5,BaudR,3,main,[B1]
        If B1 = 0 Then
            Low PORTA.0   ' Back Light OFF
        EndIf
        If B1 = 8 Then
            High PORTA.0  ' Back Light ON
        EndIf
    GoTo main             ' loop back to top
    EndIf

LCDINIT:   ' Standard LCD Module Initialisation
PORTC = %00000001   ' 2, Clear Display
    High En : DelayUS 300 : Low En ' Send data
    DelayMS 4
PORTC = %00000010   ' 4, Return Home
    High En : DelayUS 300 : Low En
    DelayMS 4
PORTC = %00111000      ' 1, 8 bit, 2 line, 5x8 Characters
    High En : DelayUS 300 : Low En
    DelayMS 4
' PORTC = %00001100   ' Display on, no cursor, no blink
PORTC = %00001110   ' 1, Display on, cursor, blink
    High En : DelayUS 300 : Low En
    DelayMS 4
PORTC = %00000110   ' 1, Entry mode
    High En : DelayUS 300 : Low En
    DelayMS 4
    High RS          ' character mode
Return