[SOLVED !] LCD driven by PCF8574


Closed Thread
Results 1 to 7 of 7

Thread: LCD driven by PCF857428 days old

  1. #1
    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 LCD driven by PCF8574

    Hello forum,

    I'm struggling to find the reason why my 16F877A doesn't drive the display correctly.
    I tried to set up with the code found on the wiki. That's working on the simulator and the PCF address seems to be 0x0e, but when I try to use on the hardware I can't get anything working.
    The I2C scan. by arduino sketch, reports to find a device on 0x27, so this puzzling me.
    I wrote a scanner, but it's not giving anything positive

    Code:
    Device = 16F877A
    Declare Xtal = 20
    Config FOSC_HS, WDTE_OFF, PWRTE_OFF, BOREN_ON, LVP_OFF, CPD_OFF, _
    WRT_OFF, DEBUG_OFF, CP_OFF
    Declare Slow_Bus On
    Declare SCL_Pin PORTC.3
    Declare SDA_Pin PORTC.4
    Declare Hbus_Bitrate 100
    Declare Hserial_Baud 57600          ' baud rate 57600
    
    Dim PP4 As Byte System
    Dim cnt As Byte
    
    HSerOut ["Press G to start", 13,10]
    hold_on:
    If cnt ="g" Then showme
    HSerIn 100, hold_on, [cnt]
    showme:
    HSerOut ["STARTED", 13,10]
    For cnt = 0 To 128
      HSerOut ["."]
      BStart                             ' Send a Start condition
      BusOut cnt
      If PP4.0 = 0 Then                   ' Has Ack been received OK ?
        HSerOut ["***Bus Found at ", Dec cnt, Rep 32\8, Hex cnt, 13, 10]
      End If
      BStop                              ' Send a Stop condition
      DelayMS 10
    Next cnt
      HSerOut ["Scan completed", 13,10]
    Stop
    Running on the simulation will report the address 0x4e and 0x4f. Whereas the program works as expected.
    Running this will give me all addresses as valid. If I run it whit HBusOut it will give me none. I put 4k7 pullups.
    I don't even understand whether the MCU might be faulty.

    Testing on the arduino the device is working flawlessly.
    Last edited by keytapper; 3rd May 2020 at 09:19.

  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
    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: LCD driven by PCF8574

    I wrote some code that used the cheapo alpha LCD I2C backpack, it's may be in Wiki, called something like "Replace Print command ...........". The code uses PCF8574 or PCF8574A.
    George.

  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
    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: LCD driven by PCF8574

    Exactly that, George.
    Apparently it works fine with VSM. That's why I concluded my project. But as I loaded on the MCU, nothing comes from there. I just suspect the test is affected how the hardware is laid out. I setup on a breadboard, so I'm starting to doubt that the clock is rather flickering and so the timing on I2C might be awful.
    Anyways as I tried on an Arduino UNO, I didn't faced any flaw.

    So for test I'll arrange a slower clock, just see If is really that the primer cause. Even I doubt as much as the serial is running at 57600 baud flawlessly.

    One more note.
    It's my intent to convert HBusOut to a simpler SPI operation, so I'd swap the PCF8574 to a 74xx595. In addition to give a new interface to share with the folks.

    PS
    How to change the IC address on your code, George, to the real hardware. VSM differs from the real HW PCF8574. I already had similar case during simulations.
    Last edited by keytapper; 3rd May 2020 at 13:56.

  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
    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: LCD driven by PCF8574

    I setup on a breadboard,
    I as sooo over breadboard, it is just so unreliable. Probably my own fault cause I used to buy the cheapest which suck even harder than decent ones. I built a couple of boards with the i/o brought out to a SIL connector. So now I just have to make a daughter board to test new stuff, kindda like Mickroe Click.

    A bunch of different people have ran that code. AFAIK with success.
    George.

  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
    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: LCD driven by PCF8574

    I've managed a little breakout for the crystal and the capacitors, so it comes a bit more reliable.
    I beg a pardon, but the address might not match the real world. I still don't get the idea what I should give as the backpack interface says that is 0x27. Can you give me a clue?
    I've slightly modify the include so that will offer another option.

    Code:
      $ifndef I2CPrint_Part_address
       $define I2CPrint_Part_address = $0e
      $endif
    That will change the symbol to a define, otherwise it won't be computed.

    Not to mention the same manner might let switch from software to hardware management.So this will allow the user to choose whatever address and mode (s)he will need.

    About breadboard, I confess that I'm playing electronics like Lego, so few things will become a real end-user objects. But I have to admit that many cheapo are only deserving the title of scrap. Their clips aren't fully closed and small component leads are difficult to catch a good contact. In addition to that there will be many other side effects like capacitance and noises. It's just a game, so I allow many compromises.
    For the latest prototype I had to switch the assembly to a different board, the first prototype was awfully sucking and difficult to have a reasonable result.

  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
    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: LCD driven by PCF8574

    There's an oversight on the previous snippet.

    Code:
    $ifndef I2CPrint_Part_address
        $define I2CPrint_Part_address $0e
     $endif
    The equal sign will cause an error.

    Currently the hardware started to work, perhaps it's my good star shed me a light. I have not find the way to catch what is the current address for the interface.
    As the scanning result is reporting four addresses.

    Finally I tested and I'm glad to post the snippet for whose needs some help
    Code:
    #Disable Print
    Device = 16F877A
    Declare Xtal = 20
    Config FOSC_HS, WDTE_OFF, PWRTE_OFF, BOREN_ON, LVP_OFF, CPD_OFF, _
    WRT_OFF, DEBUG_OFF, CP_OFF
    Declare Slow_Bus On
    Declare SCL_Pin PORTC.3
    Declare SDA_Pin PORTC.4
    Declare Hbus_Bitrate 100
    Declare Hserial_Baud 57600          ' baud rate 57600
    $define BacklightOn Print $FE,3
    $define BacklightOff Print $FE,4
    Dim PP4 As Byte System
    Dim cnt As Byte
    Dim pntr As Byte
    Dim reslt[16] As Byte
    Dim Address As Byte
    Dim PrintData As Byte
    Dim HighData As Byte
    Dim LowData As Byte
    Dim dummy As Byte
    Dim RSFlag As Byte
    
    Symbol InitForLCDLines $28            ' $28 for two lines
    Symbol LCD_RS         000001
    Symbol LCD_RW         000010
    Symbol LCD_E          000100
    Symbol BackLight      001000
    ;**********************************************************************************
    
    Symbol BackLight_RS   BackLight | LCD_RS
    Symbol BackLight_E    BackLight | LCD_E
    Symbol BackLight_RS_E BackLight | LCD_RS | LCD_E
    Symbol Init1          110000 | BackLight
    Symbol Init1_E        110000 | BackLight | LCD_E
    Symbol Init2          110000 | BackLight
    Symbol Init2_E        110000 | BackLight | LCD_E
    Symbol Init3          100000 | BackLight
    Symbol Init3_E        100000 | BackLight | LCD_E
    Symbol Control        000000
    
    OPTION_REG = 128
    TRISB = 1
    
    While PORTB.0 = 1
      HSerOut ["."]
      DelayMS 250
    Wend
      HSerOut [13,10]
      Clear reslt
      Clear pntr
    For cnt = 0 To 128
      HBStart                             ' Send a Start condition
      HBusOut cnt
      If PP4.0 = 0 Then                   ' Has Ack been received OK ?
        HSerOut ["***Bus Found at ", Dec cnt, Rep 32\8, Hex cnt, 13, 10]
        reslt[pntr] = cnt
        Inc pntr
      End If
      HBStop                              ' Send a Stop condition
      DelayMS 10
    Next cnt
      HSerOut ["Scan completed", 13,10]
      HSerOut ["Found ", Dec pntr," Devices", 13,10]
      If pntr = 0 Then Stop
      Dec pntr
      For cnt = 0 To pntr
      HSerOut ["Now testing ", Dec reslt[cnt], 13,10]
        Address = reslt[cnt]
        GoSub PrintInit
        BacklightOn
        Print "testing OK"
        Print At 2,4, "Address = ", Hex Address
        DelayMS 3000
        BacklightOff
      Next cnt
    End
    
    ' ****************************************************************************
    ' **                             S U B R O U T I N E S                      **
    ' ****************************************************************************
    
    SendData:
      HighData = PrintData & 110000  ' mask LSBs
      LowData = PrintData << 4          ' shift left
      dummy = BackLight_RS_E | HighData ' data and e hi
      HBusOut Address, [dummy]
      dummy = BackLight_RS | HighData   ' data and e lo
      HBusOut Address, [dummy]
      HBusOut Address, [BackLight_RS]   ' Delay, Backlight and RS on throughout
      dummy = BackLight_RS_E | LowData  ' data and e hi
      HBusOut Address, [dummy]
      dummy = BackLight_RS | LowData    ' data and e lo
      HBusOut Address, [dummy]
      Return
    
    
    SendControl:
      HighData = PrintData & 110000  ' mask LSBs
      LowData = PrintData << 4          ' shift left
      dummy = BackLight_E | HighData    ' data and e hi
      HBusOut Address, [dummy]
      dummy = BackLight | HighData      ' data and e lo
      HBusOut Address, [dummy]
      HBusOut Address, [BackLight]      ' Delay, Backlight on throughout
      dummy = BackLight_E | LowData     ' data and e hi
      HBusOut Address, [dummy]
      dummy = BackLight | LowData       ' data and e lo
      HBusOut Address, [dummy]
      DelayMS 20
      Return
    
    PrintInit:
      HBusOut Address, [Init1_E]       ' E hi and send command nibble 0011 (3)
      HBusOut Address, [Init1]         ' E lo
      DelayMS 20
      HBusOut Address, [Init2_E]       ' E hi and send command nibble 0011 (3)
      HBusOut Address, [Init2]         ' E lo
      DelayMS 20
      HBusOut Address, [Init3_E]       ' E hi and send command nibble 0010 (2)
      HBusOut Address, [Init3]         ' E lo
      DelayMS 20
      PrintData = InitForLCDLines      ' 4 bit mode and n lines
      GoSub SendControl
      PrintData = $0C                  ' enable disblay, cursor and blink off
      GoSub SendControl
      PrintData = $06                  ' move cursor after each write
      GoSub SendControl
      PrintData = $80                  ' goto column 1 line 1
      GoSub SendControl
      Return
    
    LCD_WriteData:                      ' prepare to write a data byte
    @Print                              ' assembler Print redirect
    Wreg_Byte PrintData                 ' load LCDByte to W Register
      If PrintData = 0xFE Then          ' it is a command header
        RSFlag = 0                      ' clear a flag so we know the next byte will be a command
      Else
        If RSFlag = 0 Then              ' this is a command byte
          GoSub SendControl
        Else
          GoSub SendData
        EndIf
        RSFlag = 1                      ' set the flag so the next byte will be send as Data
      EndIf
      Return
    So the display Currently responds on the two addresses. Strangely the numbering is different from the result and the real world.

    For the input button it might need debounce techniques.

    Again many thanks to George and its precious work.

  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.

  13. #7
    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: LCD driven by PCF8574

    Your problem with I2C address is pretty clear in the source I provided
    Symbol I2CPrint_Part_address = $0E ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW where W=0 *
    The address $0E is described as part address because the full address is made up of the logic level of A0,A1 and A2 and the part address.

    The bits are combined here
    Symbol I2CPrint_Address = I2CPrint_Control + I2CPrint_Part_address
    I had a quick look and couldn't anything like a define, I2CPrint_Part_Address being tested for anything. Perhaps you're looking at a fork of the code I posted.

    The version using the MSSP (I2CPrintHardCommand) was ver 0.10.00 and the bit bang (I2CPrintSoftCommand) was 0.11.0

    Unfortunately there are a great many variations on the basic backpack (order of bits, hi/lo nibble, address bits etc.) thus the code appears to be unnecessarily complex.
    George.

  14. 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. Pic18f25k20 + module i2c (pcf8574)
    By Jenny96 in forum Amicus 18
    Replies: 8
    Last Post: 3rd October 2019, 23:59
  2. [SOLVED !] How to ensure that the PCF8574 functions properly?
    By wirecut in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 1st December 2015, 07:17
  3. I2C problem with PCF8574
    By gingpeakin in forum Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C / Master and Slave modes
    Replies: 3
    Last Post: 18th April 2015, 00:32
  4. mister e and pcf8574
    By BIDOUILLE in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 20th March 2006, 20:42
  5. [SOLVED !] Proteus model of PCF8574 missing
    By SKiD[CZE] in forum Labcenter Proteus VSM
    Replies: 0
    Last Post: 24th January 2005, 23:13

Posting Permissions

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