PICAXE 08M2 via I2C PCF8574 8-Bit I/O Port Expander driving a 20x4 LCD

radiosparks

Member
This is a DEMO of a PICAXE 08M2 using a PCF8574 I2C 8-Bit I/O Port Expander driving a standard 20x4 Blue LCD display.

This code is part of a library that will be used for a future build (or re-build) of a QRSS transmitter. The transmitter frequency will be created from a SI5351 I2C configurable clock generator using a serial interface.

The small device in front of the blue LCD is a 128x64 OLED I2C 0.96 inch white display. Uses a SSD1315 controller chip. My poor old eyes have some difficulty in reading the display, so, I opted for the larger LCD display. This also uses less code as no fonts need to be stored in valuable memory space.

The code is based on a Hippy snippet: https://picaxeforum.co.uk/threads/using-arduino-iic-i2c-serial-3-2-lcd-2004-module-display.21872/post-212958
I'm posting the code as various modules as my project grows, but, I'm thinking I'll outgrow the 08M2 and need more memory space.

Code:
'    /*****************************************************************/
'   /* PICAXE 08M2+ via I2C PCF8574 Port Expander driving a 20x4 LCD */
'  /*  DEMO Edit Code - rhb.20230717                                */
' /*   Jewel of the PICAXE code mined from the Forum               */
'/*****************************************************************/

#PICAXE 08M2

Symbol LCD_ADDR    = $4E

Symbol bitRS      = bit8
Symbol bitWR      = bit9
Symbol bitE       = bit10
Symbol bitBKL     = bit11
Symbol bitD4      = bit12
Symbol bitD5      = bit13
Symbol bitD6      = bit14
Symbol bitD7      = bit15

Symbol i          = b27
Symbol j          = b26

#DEFINE LOGO      "radioSPARKS   VE3XRM"
#DEFINE MESSAGE_0 "*VFO A 10.138.70 USB"
#DEFINE MESSAGE_1 " VFO B 21.094.60 USB"
#DEFINE MESSAGE_2 " MC 31  7.038.70 USB"

#MACRO PRINT( string )
    j = 0
    do
        lookup j, ( string, 0 ), b0
        if b0 <> 0 then
            Gosub SendB0AsDataByte
        end if
        j = j + 1
    loop until b0 = 0
#ENDMACRO

INIT_DISPLAY:

  HI2CSetup I2CMASTER, LCD_ADDR, I2CFAST, I2CBYTE

  b0 = $33 : Gosub SendB0AsInitByte
  b0 = $33 : Gosub SendB0AsInitByte
  b0 = $32 : Gosub SendB0AsInitByte
  b0 = $28 : Gosub SendB0AsCommandByte
  b0 = $0C : Gosub SendB0AsCommandByte
  b0 = $06 : Gosub SendB0AsCommandByte
  b0 = $01 : Gosub SendB0AsCommandByte

  Pause 2

MAIN:

; LINE ONE
  b0 = $80 : Gosub SendB0AsCommandByte ; %1000 0000
      PRINT(LOGO)
 
; LINE TWO 
  b0 = $C0 : Gosub SendB0AsCommandByte ; %1100 0000
    PRINT(MESSAGE_0)
    

; LINE THREE
  b0 = $94 : Gosub SendB0AsCommandByte ; %1001 0100
      PRINT(MESSAGE_1)
 
; LINE FOUR
  b0 = $D4 : Gosub SendB0AsCommandByte ; %1101 0100
      PRINT(MESSAGE_2)
 
  Do : Loop

SendB0AsInitByte:

  Pause 15

  bitWR = 0         ; Keep WR signal low
 bitBKL = 1

SendB0AsCommandByte:

  bitRS = 0         ; Send byte as a command

SendB0AsDataByte:

  bitD4 = bit4      ; Send msb first
  bitD5 = bit5
  bitD6 = bit6
  bitD7 = bit7

  bitE  = 1
  b2    = b1        ; b2 holds msb with E set
  bitE  = 0         ; b1 holds msb with E clear

  HI2cOut b1, ( b2, b1 )

  bitD4 = bit0      ; Send lsb second
  bitD5 = bit1
  bitD6 = bit2
  bitD7 = bit3

  bitE  = 1
  b2    = b1        ; b2 holds lsb with E set
  bitE  = 0         ; b1 holds lsb with E clear

  HI2cOut b1, ( b2, b1 )

  bitRS = 1         ; Send data byte next time
 
Return

'/* EOF */
25894
 
Top