Any tips on getting a i2c 16x2 lcd working?


+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,749
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Any tips on getting a i2c 16x2 lcd working?

    Hi I have a need to use an i2c lcd based on the PCF8574. I'm using George Towler's routines I2CPrintSoftCommand.Inc

    I have it running in a VSM OK.

    The board is a Amicus18 at 64mhz and that works ok as seen using the USART

    Declare SDA_Pin = PORTC.1
    Declare SCL_Pin = PORTC.0

    And as the Amicus board is 3.3v the LCD is connected to 3.3v and Grnd

    I have tried 2 LCD i2c modules one with A0-A2 linked and another with them open

    I have tried "I2CPrint_Part_address = $00" and "I2CPrint_Part_address = $0E"

    I have tried
    Declare Slow_Bus On
    Declare Hbus_Bitrate 100

    And
    Declare Slow_Bus Off
    Declare Hbus_Bitrate 400


    But nothings shows.

    Played with the contrast Zero luck

    Any Ideas?

    Code below

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2020 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/05/2020                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    
    
    
    
    
        Include "Amicus18.inc"                          ' Configure the compiler to use the Amicus18 hardware (18F25K20, 64MHz)
        
            ' Define I2C bus ports
        Declare SDA_Pin = PORTC.1 
        Declare SCL_Pin = PORTC.0 
        Declare Slow_Bus On
        Declare Hbus_Bitrate 100
        
        
    '*****************************************************************************************************************
    '*  Name    : I2CPrintSoftCommand.inc                                                                            *
    '*  Purpose : allow Proton Print commands to access the standard 1602 LCD via I2C backpack board                 * 
    '*  Author  : George Towler                                                                                      *
    '*  Notice  : I claim no copyright but maybe Barak does                                                          *
    '*  Date    : 25/01/2017                                                                                         *
    '*  Compiler: 3.5.9.0                                                                                            *
    '*  Version : 0.11.0                                                                                              *
    '*  Notes   : see http://www.protonbasic.co.uk/showthread.php/62478-%93Print%94-command-for-SPI-Alfa-numeric-LCD *                                                  
    '*          :     post #6   Barak shows how to replace Proton commands and how to deal with control (FE$) bytes  *                                                                                                                               
    '*****************************************************************************************************************
    'History 0.11.0 - Backlight_State initialised and Clear added
    '        0.10.0 - reworked 3 way OR's, removed need to save and restore system variables 
    '        0.9.0 - reduced the number of system variables protected
    '        0.8.0 - Oh dear, yet another typo corrected
    '        0.7.0 - Oh dear, typo corrected (PP7H_temp = PP7 > PP7H_temp = PP7H   PP7H = PP7_Temp > PP7H = PP7H_Temp)
    '        0.6.0 - Once again, Melbreak For President. Saved And restored System variables
    '        0.5.0 - Melbreak For President. Raise rev number to keep .bas an .inc in sync
    '        0.4.0 - HORRIBLE kludge to hide double char error, I still have no idea why this happens. Also no idea 
    '                what I've broken as a result of this "fix"! 
    '        0.3.1 - Fixed first char swallowed. Double char error discovered and demonstrated in test data
    '        0.3.0 - Backlight controlled by $FE Commands - $FE 03 on, $FE 04 off
    '        0.2.0 - code rehashed as include file with unique names - see I2CPrintCommand_Demo.bas for usage 
    '        0.1.2 - added conditional compilation of data masking to allow for backpack data on high or low nbble
    '        0.1.1 - made control bits sybolic to allow for backpacks with different bit configurations
    '        0.1.0 - first posted
    
    
    ' New layout shamelessly stolen from Proton_Reversed_Print.zip, which is an excellent example of command 
    ' replacement and tight code. 
    
    
      #Disable Print                              
    
    
      ;***************************************************************************************************************
      ; Configure items to suit your LCD and I2C hardware, I2CPrint_DataOnHighBits remmed if data is on low bits     *
      ;                                                                                                              *
      Symbol I2CPrint_Part_address    = $00         ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW  where W=0           *
      Symbol I2CPrint_InitForLCDLines = $28         ' $28 for two lines                                              *
      Symbol I2CPrint_RS              = %00000001   '                                                                *
      Symbol I2CPrint_RW              = %00000010   '                                                                *
      Symbol I2CPrint_E               = %00000100   '                                                                *
      Symbol I2CPrint_BackLight       = %00001000   '                                                                *
      $define I2CPrint_DataOnHighBits               '                                                                *
      ;***************************************************************************************************************
      ;
      ;  Example of Backpack with control bits on the low order nibble, I2CPrint_DataOnHighBits would be remmed
      ;  Symbol I2CPrint_RS             = %01000000
      ;  Symbol I2CPrint_RW             = %00100000
      ;  Symbol I2CPrint_E              = %00010000
      ;  Symbol I2CPrint_BackLight      = %10000000
      ;  A0=D0  A1=D1  A2=D2  A3=D3  A4=E  A5=RW  A6=RS  A7=I2CPrint_BackLight
      ;
      Symbol I2CPrint_RS_E           = I2CPrint_RS | I2CPrint_E
      Symbol I2CPrint_Control        = %01000000                         
      Symbol I2CPrint_Address        = I2CPrint_Control + I2CPrint_Part_address
    
    
      $ifdef I2CPrint_DataOnHighBits
        Symbol I2CPrint_Init1          = %00110000 
        Symbol I2CPrint_Init1_E        = %00110000 | I2CPrint_E
        Symbol I2CPrint_Init2          = %00110000  
        Symbol I2CPrint_Init2_E        = %00110000 | I2CPrint_E
        Symbol I2CPrint_Init3          = %00100000 
        Symbol I2CPrint_Init3_E        = %00100000 | I2CPrint_E
      $else
        Symbol I2CPrint_Init1          = %00000011  
        Symbol I2CPrint_Init1_E        = %00000011 | I2CPrint_E
        Symbol I2CPrint_Init2          = %00000011  
        Symbol I2CPrint_Init2_E        = %00000011 | I2CPrint_E
        Symbol I2CPrint_Init3          = %00000010  
        Symbol I2CPrint_Init3_E        = %00000010 | I2CPrint_E
      $endif
    
    
      Dim BPF As Byte System
      Symbol I2CPrint_tComOrData = BPF.0
      Symbol I2CPrint_tInitialised = BPF.1  
    
    
      Dim I2CPrint_PrintStore As Byte
      Dim I2CPrint_PrintData As Byte
      Dim I2CPrint_HighData As Byte
      Dim I2CPrint_LowData As Byte
      Dim I2CPrint_dummy As Byte
      Dim I2CPrint_RSFlag As Byte  
      Dim Backlight_State As Byte = 0
    
    
      Clear                                              ; Melbreak suggested this 
      GoTo I2CPrintCommand_End
    
    
      @Print                                             ; assembler Print redirect
      Wreg_Byte I2CPrint_PrintStore                      ; save the W Register
    
    
      If I2CPrint_tInitialised = 0 Then                  ; Has LCD been inititalised?
        BusOut I2CPrint_Address, [I2CPrint_Init1_E]      ; E hi and send command nibble 0011 (3)    
        BusOut I2CPrint_Address, [I2CPrint_Init1]        ; E lo     
        DelayMS 20
        BusOut I2CPrint_Address, [I2CPrint_Init2_E]      ; E hi and send command nibble 0011 (3)    
        BusOut I2CPrint_Address, [I2CPrint_Init2]        ; E lo     
        DelayMS 20
        BusOut I2CPrint_Address, [I2CPrint_Init3_E]      ; E hi and send command nibble 0010 (2)    
        BusOut I2CPrint_Address, [I2CPrint_Init3]        ; E lo     
        DelayMS 20
        I2CPrint_PrintData = I2CPrint_InitForLCDLines     ; 4 bit mode and n lines 
        GoSub I2CPrint_SendControl
        I2CPrint_PrintData = $0C                          ; enable display, cursor and blink off
        GoSub I2CPrint_SendControl
        I2CPrint_PrintData = $06                          ; move cursor after each write 
        GoSub I2CPrint_SendControl                    
        I2CPrint_PrintData = $80                          ; goto column 1 line 1 
        GoSub I2CPrint_SendControl
        Set I2CPrint_tInitialised                         ; Indicate that the LCD is initialised
      EndIf
    
    
      I2CPrint_PrintData = I2CPrint_PrintStore
      If I2CPrint_PrintData = 0xFE Then                   ; it is a command header
        I2CPrint_RSFlag = 0                               ; clear a flag so we know the next byte will be a command
      Else
        If I2CPrint_RSFlag = 0 Then                       ; this is a command byte
          If I2CPrint_PrintData = 03 Then
            Backlight_State = I2CPrint_BackLight  
          ElseIf I2CPrint_PrintData = 04 Then
            Backlight_State = 0  
          Else
            GoSub I2CPrint_SendControl
          End If
        Else
          GoSub I2CPrint_SendData
        EndIf
        I2CPrint_RSFlag = 1                               ; set the flag so the next byte will be send as Data
      EndIf                                     
    
    
      Byte_Wreg I2CPrint_PrintStore                       ; restore the W register
      Return
    
    
    ' ****************************************************************************
    ' **                             S U B R O U T I N E S                      **
    ' ****************************************************************************
    
    
    I2CPrint_SendData:
      $ifdef I2CPrint_DataOnHighBits
        I2CPrint_HighData = I2CPrint_PrintData & %11110000            ; mask LSBs
        I2CPrint_LowData = I2CPrint_PrintData << 4                    ; shift left
      $else
        I2CPrint_LowData = I2CPrint_PrintData & %00001111             ; mask MSBs
        I2CPrint_HighData = I2CPrint_PrintData >> 4                   ; shift Right
      $endif
    
    
      I2CPrint_dummy = I2CPrint_RS_E | I2CPrint_HighData              ; data and e hi
      I2CPrint_dummy = I2CPrint_dummy | Backlight_State               ; data and e hi
      BusOut I2CPrint_Address, [I2CPrint_dummy]             
      I2CPrint_dummy = I2CPrint_RS | I2CPrint_HighData                ; data and e lo
      I2CPrint_dummy = I2CPrint_dummy | Backlight_State               ; data and e lo
      BusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_RS | Backlight_State                  ; data and e hi
      BusOut I2CPrint_Address, [I2CPrint_dummy]                       ; Delay, RS on throughout
      I2CPrint_dummy = I2CPrint_RS_E | I2CPrint_LowData               ; data and e hi
      I2CPrint_dummy = I2CPrint_dummy | Backlight_State               ; data and e hi
      BusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_RS | I2CPrint_LowData                 ; data and e lo
      I2CPrint_dummy = I2CPrint_dummy | Backlight_State               ; data and e lo
      BusOut I2CPrint_Address, [I2CPrint_dummy]         
      Return
    
    
    I2CPrint_SendControl:
      $ifdef I2CPrint_DataOnHighBits
        I2CPrint_HighData = I2CPrint_PrintData & %11110000            ; mask LSBs
        I2CPrint_LowData = I2CPrint_PrintData << 4                    ; shift left
      $else
        I2CPrint_LowData = I2CPrint_PrintData & %00001111             ; mask MSBs
        I2CPrint_HighData = I2CPrint_PrintData >> 4                   ; shift Right
      $endif
    
    
      I2CPrint_dummy = I2CPrint_E | I2CPrint_HighData                 ; data and e hi
      I2CPrint_dummy = I2CPrint_dummy | Backlight_State               ; data and e hi
      BusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_HighData | Backlight_State            ; data and e lo
      BusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = Backlight_State                                ; 
      BusOut I2CPrint_Address, [I2CPrint_dummy]                       ; Delay, Backlight on throughout
      I2CPrint_dummy = I2CPrint_E | I2CPrint_LowData                  ; data and e hi
      I2CPrint_dummy = I2CPrint_dummy | Backlight_State               ; data and e hi
      BusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_LowData | Backlight_State             ; data and e lo
      BusOut I2CPrint_Address, [I2CPrint_dummy]         
      DelayMS 20
      Return
    
    
    I2CPrintCommand_End:
    
    
        DelayMS 100
        
        Cls
        Print $FE, 3                                          ' backlight on On Next Call To Print
        
        
        
        
        While 1 = 1
            Cls
            DelayMS 500
            Print At 1,1, "Test Test"
            Print At 2,1, "Test Test"
            HRSOut "Test",13,10
        Wend
    Tim

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    195
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Any tips on getting a i2c 16x2 lcd working?

    It works for me on a 16F877A, but I had to cut down the nested subroutine calls.
    I don't have an idea about 18Fxxx family.
    Anyway it might need a little optimization.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,749
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Re: Any tips on getting a i2c 16x2 lcd working?

    Not sure on the supply voltage now. Putting 5v in and adjusting the contrast makes the grid visible. However not keen to put the lines to the pic on as there may be pull ups on the LCD board that will fry the 18F25K20

    Tim
    Tim

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    195
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Any tips on getting a i2c 16x2 lcd working?

    I'm using 5V, which is the normal to supply that backpack board. All of my circuit works at 5V.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,749
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Re: Any tips on getting a i2c 16x2 lcd working?

    Ok its working now.

    I needed 5v and to change the value in I2CPrint_Control to %01110000
    I2CPrint_Control = %01110000

    I was informed of that by a friend.

    Also contrast is critical. The A0-A2 needs to be right as well.

    Ordered a 18F25k22 and will mod the board to run on 5v

    Tim
    Tim

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,353
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Any tips on getting a i2c 16x2 lcd working?

    I seem to remember you could buy 3.3v 16x2 alpha modules.

    Edit In fact I have one if you want to borrow till you can source one.

    The problem with the backpacks you can buy is that there is so much variation.
    George.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. error in lcd 16x2
    By Josť in forum Proton Plus Compiler v3
    Replies: 19
    Last Post: 25th February 2020, 13:05
  2. DS2408 and LCD 16x2
    By Shaman in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 10th March 2015, 18:44
  3. I2C PCF8574P with lcd 16x2 hitachi 44780
    By pascalbianca in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 15th October 2014, 09:11
  4. 8 bit 16x2 LCD Code for 16F84A
    By Jessica in forum Absolute Beginners Section
    Replies: 11
    Last Post: 1st September 2014, 16:51
  5. [SOLVED !] Alpha 16x2 LCD
    By rrakke in forum Wish List / Product Feedback
    Replies: 0
    Last Post: 18th March 2003, 13:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts