I2C lcd ( arduino ) with PICBASIC, help - Page 2


Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 93
  1. #41
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Hi Steve,
    I am back again on this LCD ...
    I have repaired the programmer and so I had the occasion to test the program.
    > Back light does not come on at all .
    > nothing is displayed on the LCD
    If you have something more to suggest, I am ready to go on .
    Thanks
    Regards,
    Ambrogio

  2. #42
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    Hi Steve,
    I am back again on this LCD ...
    I have repaired the programmer and so I had the occasion to test the program.
    > Back light does not come on at all .
    > nothing is displayed on the LCD
    If you have something more to suggest, I am ready to go on .
    Thanks
    Regards,
    Ambrogio
    Not good news then!

    I need to refresh my memory. Post the full code you are using please.

  3. #43
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    here it is:

    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL
    DEFINE I2C_SLOW 1
    SDA VAR PORTD.2 ; I2C Data pin
    SCL VAR PORTD.3 ; I2C Clock Pin
    LCD_Addr CON 78
    'LCD_BuffSize CON 30
    'LCD_Buff VAR BYTE[LCD_BuffSize]
    'LCD_BuffAddr CON EXT : @LCD_BuffAddr = _LCD_Buff
    'LCD_BuffLen VAR WORD ; Length of data in buffer
    LCD_Data VAR BYTE ; Data to Send to LCD
    LCD_Byte VAR BYTE ; Nibbles to Send
    LCD_RS VAR LCD_Byte.0 ; Register Select bit
    LCD_RW VAR LCD_Byte.1 ; Read/Write bit
    LCD_E VAR LCD_Byte.2 ; Enable bit
    LCD_BackLight VAR LCD_Byte.3 ; Backlight 0=ON
    LCD_WriteMode VAR BYTE ; 1=LowNibble, 2=HighNibble, 3=Both
    LCD_CommandMode VAR BIT ; Indicates next byte is a command
    LCD_Byte2 VAR BYTE ; Same nibble without E bit
    LCD_Idx VAR BYTE
    testmode var byte



    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 250 ; LCD Power-on delay
    LCD_Backlight = 1 ; Backlight OFF
    LCD_RW = 0 ; Write to LCD
    LCD_RS = 0 ; Command Register

    LCD_WriteMode = 1 ;-- Low Nibbles only
    LCD_Data = 3 ; Reset 3 times
    gosub LCD_Write_
    PAUSEUS 6000
    gosub LCD_Write_
    PAUSEUS 1000
    gosub LCD_Write_
    PAUSEUS 1000

    LCD_Data = 2 ; Start 4-bit mode
    gosub LCD_Write_
    PAUSEUS 1000

    LCD_WriteMode = 3 ;-- Both Nibbles
    LCD_Data = $28
    gosub LCD_Write_ ; Function Set, 4-bit, 2-line, 5x7
    LCD_Data = $0C
    gosub LCD_Write_ ; Display ON
    LCD_Data = $01
    gosub LCD_Write_ ; Clear Screen
    PAUSE 2
    LCD_Data = $06
    gosub LCD_Write_ ; Entry Mode

    PAUSE 2 ; Let command finish
    LCD_RS = 1 ' this is data
    goto main

    LCD_WRITE_:
    LCD_E = 1
    IF LCD_WriteMode.1 = 1 THEN ; Write High Nibble
    LCD_Byte = (LCD_Byte & $0F) | (LCD_Data & $F0)
    LCD_Byte2 = LCD_Byte & $FB
    I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
    ENDIF

    IF LCD_WriteMode.0 = 1 THEN ; Write Low Nibble
    LCD_Byte = (LCD_Byte & $0F) | ((LCD_Data << 4 )& $F0)
    LCD_Byte2 = LCD_Byte & $FB
    I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
    ENDIF
    return



    Main:
    LCD_Data = "T"
    gosub LCD_Write_
    LCD_Data = "e"
    gosub LCD_Write_
    LCD_Data = "s"
    gosub LCD_Write_
    LCD_Data = "t"
    gosub LCD_Write_
    goto main

  4. #44
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Please use code tags as it is easier for me to read.

  5. #45
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    here it is:
    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    DEFINE I2C_SLOW 1
    SDA         VAR PORTD.2       ; I2C Data pin
    SCL         VAR PORTD.3       ; I2C Clock Pin
    LCD_Addr CON 78
    'LCD_BuffSize    CON 30
    'LCD_Buff        VAR BYTE[LCD_BuffSize]
    'LCD_BuffAddr    CON EXT : @LCD_BuffAddr = _LCD_Buff
    'LCD_BuffLen     VAR WORD        ; Length of data in buffer
    LCD_Data        VAR BYTE        ; Data to Send to LCD
    LCD_Byte        VAR BYTE        ; Nibbles to Send
    LCD_RS          VAR LCD_Byte.0  ; Register Select bit
    LCD_RW          VAR LCD_Byte.1  ; Read/Write bit
    LCD_E           VAR LCD_Byte.2  ; Enable bit
    LCD_BackLight   VAR LCD_Byte.3  ; Backlight 0=ON
    LCD_WriteMode   VAR BYTE        ; 1=LowNibble, 2=HighNibble, 3=Both
    LCD_CommandMode VAR BIT         ; Indicates next byte is a command
    LCD_Byte2       VAR BYTE        ; Same nibble without E bit
    LCD_Idx         VAR BYTE
    testmode        var byte
    
    
    
    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 250             ; LCD Power-on delay
    LCD_Backlight = 1     ; Backlight OFF
    LCD_RW = 0            ; Write to LCD
    LCD_RS = 0            ; Command Register
    
    LCD_WriteMode = 1     ;-- Low Nibbles only
    LCD_Data = 3          ; Reset 3 times
    gosub LCD_Write_
    PAUSEUS 6000
    gosub LCD_Write_
    PAUSEUS 1000
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_Data = 2          ; Start 4-bit mode
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_WriteMode = 3     ;-- Both Nibbles
    LCD_Data = $28
    gosub LCD_Write_      ; Function Set, 4-bit, 2-line, 5x7
    LCD_Data = $0C
    gosub LCD_Write_      ; Display ON
    LCD_Data = $01
    gosub LCD_Write_      ; Clear Screen
    PAUSE 2
    LCD_Data = $06 
    gosub LCD_Write_      ; Entry Mode
                           
    PAUSE 2               ; Let command finish
    LCD_RS = 1   ' this is data
    goto main
    
    LCD_WRITE_:
       LCD_E = 1
       IF LCD_WriteMode.1 = 1 THEN                             ; Write High Nibble
         LCD_Byte = (LCD_Byte & $0F) | (LCD_Data  & $F0)
         LCD_Byte2 = LCD_Byte & $FB    
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
      
       IF LCD_WriteMode.0 = 1 THEN                             ; Write Low Nibble
         LCD_Byte = (LCD_Byte & $0F) | ((LCD_Data << 4 )& $F0)
         LCD_Byte2 = LCD_Byte & $FB
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
    return
    
    
    
    Main:
    LCD_Data = "T"
    gosub LCD_Write_ 
    LCD_Data = "e" 
    gosub LCD_Write_
    LCD_Data = "s" 
    gosub LCD_Write_ 
    LCD_Data = "t" 
    gosub LCD_Write_ 
    goto main
    Need to add pauseus!

    Code:
    Main:
    LCD_Data = "T"
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "e" 
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "s" 
    gosub LCD_Write_: PAUSEUS 50 
    LCD_Data = "t" 
    gosub LCD_Write_: PAUSEUS 50 
    goto main

  6. #46
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    And to test backlight is working try

    Code:
    Main:
    LCD_Backlight = 0
    LCD_Data = "T"
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "e" 
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "s" 
    gosub LCD_Write_: PAUSEUS 50 
    LCD_Data = "t" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    LCD_Backlight = 1
    LCD_Data = "-" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    goto main

  7. #47
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Steve,
    I uploaded the two codes you have sent to me and checked them one at the time :
    > backlight is still not working
    > lcd show nothing
    Thanks
    Ambrogio

  8. #48
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Is the address correct? It is 78 in the code.

    Try your code from post #24 as this did control the backlight.
    Last edited by EarlyBird2; - 10th July 2014 at 22:11.

  9. #49
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Steve,
    this code still works well:
    Thanks ,Ambrogio

    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL
    DEFINE I2C_SLOW 1
    C VAR portd.3 ' S_CLOCK
    D VAR portd.2 ' S_DATA
    ADDR VAR BYTE
    ADDR = %01001110 ' dec 78 , hex 4E
    CMD VAR BYTE
    LCD_CMD VAR BYTE
    E VAR LCD_CMD.BIT2
    RS VAR LCD_CMD.BIT0
    E=0:RS=0
    LCD_CMD = 0
    PAUSE 1000

    MAIN:

    I2CWRITE D, C, ADDR, [%00000000] ' bck_lt= off
    PAUSE 200
    I2CWRITE D, C, ADDR, [%00001000] ' bck_lt=on
    PAUSE 200

    GOTO MAIN

  10. #50
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    Steve,
    this code still works well:
    Thanks ,Ambrogio

    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    DEFINE I2C_SLOW 1
    C VAR portd.3 ' S_CLOCK 
    D VAR portd.2 ' S_DATA
    ADDR VAR BYTE 
    ADDR = %01001110 ' dec 78 , hex 4E
    CMD VAR BYTE
    LCD_CMD VAR BYTE 
    E VAR LCD_CMD.BIT2 
    RS VAR LCD_CMD.BIT0
    E=0:RS=0
    LCD_CMD = 0
    PAUSE 1000 
    
    MAIN:
    
    I2CWRITE D, C, ADDR, [%00000000] ' bck_lt= off
    PAUSE 200
    I2CWRITE D, C, ADDR, [%00001000] ' bck_lt=on
    PAUSE 200
    
    GOTO MAIN
    This works because you can see the backlight turn on and off. This tells me the LCD is working and the address is correct. Unfortunately that has eliminated the obvious. I will dig deeper into Darrel's code as I can not see anything that would stop it working.

  11. #51
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by EarlyBird2 View Post
    This works because you can see the backlight turn on and off. This tells me the LCD is working and the address is correct. Unfortunately that has eliminated the obvious. I will dig deeper into Darrel's code as I can not see anything that would stop it working.
    I have studied the HD44780 and PCF8574 datasheets and compared them to Darell's code and found as expected that his code follows the datasheets precisely. I compared the code


    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    DEFINE I2C_SLOW 1
    C VAR portd.3 ' S_CLOCK 
    D VAR portd.2 ' S_DATA
    ADDR VAR BYTE 
    ADDR = %01001110 ' dec 78 , hex 4E
    CMD VAR BYTE
    LCD_CMD VAR BYTE 
    E VAR LCD_CMD.BIT2 
    RS VAR LCD_CMD.BIT0
    E=0:RS=0
    LCD_CMD = 0
    PAUSE 1000 
    
    MAIN:
    
    I2CWRITE D, C, ADDR, [%00000000] ' bck_lt= off
    PAUSE 200
    I2CWRITE D, C, ADDR, [%00001000] ' bck_lt=on
    PAUSE 200
    
    GOTO MAIN
    with Darrel's and noticed the I2C_SLOW definition is not included in his code. I then looked at I2CWRITE in the manual and noticed that PAUSE 10 is used to allow time for the transfer to complete again this is not included in Darrel's code.

    What does this indicate is the question?

    I compared PBP2.5 and pbp3 manuals and the I2CWRITE instruction is the same. I wondered if the pause in PBP3 is not needed as the compiler takes care of the I2C being busy.

    One step at a time.
    First remove the I2C_SLOW and test
    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    'DEFINE I2C_SLOW 1
    SDA         VAR PORTD.2       ; I2C Data pin
    SCL         VAR PORTD.3       ; I2C Clock Pin
    LCD_Addr CON 78
    'LCD_BuffSize    CON 30
    'LCD_Buff        VAR BYTE[LCD_BuffSize]
    'LCD_BuffAddr    CON EXT : @LCD_BuffAddr = _LCD_Buff
    'LCD_BuffLen     VAR WORD        ; Length of data in buffer
    LCD_Data        VAR BYTE        ; Data to Send to LCD
    LCD_Byte        VAR BYTE        ; Nibbles to Send
    LCD_RS          VAR LCD_Byte.0  ; Register Select bit
    LCD_RW          VAR LCD_Byte.1  ; Read/Write bit
    LCD_E           VAR LCD_Byte.2  ; Enable bit
    LCD_BackLight   VAR LCD_Byte.3  ; Backlight 0=ON
    LCD_WriteMode   VAR BYTE        ; 1=LowNibble, 2=HighNibble, 3=Both
    LCD_CommandMode VAR BIT         ; Indicates next byte is a command
    LCD_Byte2       VAR BYTE        ; Same nibble without E bit
    LCD_Idx         VAR BYTE
    testmode        var byte
    
    
    
    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 250             ; LCD Power-on delay
    LCD_Backlight = 1     ; Backlight OFF
    LCD_RW = 0            ; Write to LCD
    LCD_RS = 0            ; Command Register
    
    LCD_WriteMode = 1     ;-- Low Nibbles only
    LCD_Data = 3          ; Reset 3 times
    gosub LCD_Write_
    PAUSEUS 6000
    gosub LCD_Write_
    PAUSEUS 1000
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_Data = 2          ; Start 4-bit mode
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_WriteMode = 3     ;-- Both Nibbles
    LCD_Data = $28
    gosub LCD_Write_      ; Function Set, 4-bit, 2-line, 5x7
    LCD_Data = $0C
    gosub LCD_Write_      ; Display ON
    LCD_Data = $01
    gosub LCD_Write_      ; Clear Screen
    PAUSE 2
    LCD_Data = $06 
    gosub LCD_Write_      ; Entry Mode
                           
    PAUSE 2               ; Let command finish
    LCD_RS = 1   ' this is data
    goto main
    
    LCD_WRITE_:
       LCD_E = 1
       IF LCD_WriteMode.1 = 1 THEN                             ; Write High Nibble
         LCD_Byte = (LCD_Byte & $0F) | (LCD_Data  & $F0)
         LCD_Byte2 = LCD_Byte & $FB    
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
      
       IF LCD_WriteMode.0 = 1 THEN                             ; Write Low Nibble
         LCD_Byte = (LCD_Byte & $0F) | ((LCD_Data << 4 )& $F0)
         LCD_Byte2 = LCD_Byte & $FB
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
    return
    
    Main:
    LCD_Backlight = 0
    LCD_Data = "T"
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "e" 
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "s" 
    gosub LCD_Write_: PAUSEUS 50 
    LCD_Data = "t" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    LCD_Backlight = 1
    LCD_Data = "-" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    goto main
    Then add pause 10 delays
    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    'DEFINE I2C_SLOW 1
    SDA         VAR PORTD.2       ; I2C Data pin
    SCL         VAR PORTD.3       ; I2C Clock Pin
    LCD_Addr CON 78
    'LCD_BuffSize    CON 30
    'LCD_Buff        VAR BYTE[LCD_BuffSize]
    'LCD_BuffAddr    CON EXT : @LCD_BuffAddr = _LCD_Buff
    'LCD_BuffLen     VAR WORD        ; Length of data in buffer
    LCD_Data        VAR BYTE        ; Data to Send to LCD
    LCD_Byte        VAR BYTE        ; Nibbles to Send
    LCD_RS          VAR LCD_Byte.0  ; Register Select bit
    LCD_RW          VAR LCD_Byte.1  ; Read/Write bit
    LCD_E           VAR LCD_Byte.2  ; Enable bit
    LCD_BackLight   VAR LCD_Byte.3  ; Backlight 0=ON
    LCD_WriteMode   VAR BYTE        ; 1=LowNibble, 2=HighNibble, 3=Both
    LCD_CommandMode VAR BIT         ; Indicates next byte is a command
    LCD_Byte2       VAR BYTE        ; Same nibble without E bit
    LCD_Idx         VAR BYTE
    testmode        var byte
    
    
    
    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 250             ; LCD Power-on delay
    LCD_Backlight = 1     ; Backlight OFF
    LCD_RW = 0            ; Write to LCD
    LCD_RS = 0            ; Command Register
    
    LCD_WriteMode = 1     ;-- Low Nibbles only
    LCD_Data = 3          ; Reset 3 times
    gosub LCD_Write_
    PAUSEUS 6000
    gosub LCD_Write_
    PAUSEUS 1000
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_Data = 2          ; Start 4-bit mode
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_WriteMode = 3     ;-- Both Nibbles
    LCD_Data = $28
    gosub LCD_Write_      ; Function Set, 4-bit, 2-line, 5x7
    LCD_Data = $0C
    gosub LCD_Write_      ; Display ON
    LCD_Data = $01
    gosub LCD_Write_      ; Clear Screen
    PAUSE 2
    LCD_Data = $06 
    gosub LCD_Write_      ; Entry Mode
                           
    PAUSE 2               ; Let command finish
    LCD_RS = 1   ' this is data
    goto main
    
    LCD_WRITE_:
       LCD_E = 1
       IF LCD_WriteMode.1 = 1 THEN                             ; Write High Nibble
         LCD_Byte = (LCD_Byte & $0F) | (LCD_Data  & $F0)
         LCD_Byte2 = LCD_Byte & $FB    
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte]
         PAUSE 10
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte2]
         PAUSE 10
       ENDIF
      
       IF LCD_WriteMode.0 = 1 THEN                             ; Write Low Nibble
         LCD_Byte = (LCD_Byte & $0F) | ((LCD_Data << 4 )& $F0)
         LCD_Byte2 = LCD_Byte & $FB
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte]
         PAUSE 10
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte2]
         PAUSE 10
      ENDIF
    return
    
    Main:
    LCD_Backlight = 0
    LCD_Data = "T"
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "e" 
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "s" 
    gosub LCD_Write_: PAUSEUS 50 
    LCD_Data = "t" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    LCD_Backlight = 1
    LCD_Data = "-" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    goto main
    and let me know the outcome.

    I will continue looking for answers.

  12. #52
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Hi Steve,
    no change using both codes.
    I still have no backlight and no text.
    I appreciate your assistance on this matter: thanks a lot.
    I am not skilled enough to go deeper in those kind of codes ...
    Regards,
    Ambrogio

  13. #53
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Can I make one suggestion?
    First connect few led on output of PCF8574, and control them. So you are sure that I2C communication woks.
    Second connect LCD to PIC directly, get timing and control right.
    Then just combine that two.

  14. #54
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Try again
    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    DEFINE I2C_SLOW 1
    SDA         VAR PORTD.2       ; I2C Data pin
    SCL         VAR PORTD.3       ; I2C Clock Pin
    LCD_Addr CON 78
    'LCD_BuffSize    CON 30
    'LCD_Buff        VAR BYTE[LCD_BuffSize]
    'LCD_BuffAddr    CON EXT : @LCD_BuffAddr = _LCD_Buff
    'LCD_BuffLen     VAR WORD        ; Length of data in buffer
    LCD_Data        VAR BYTE        ; Data to Send to LCD
    LCD_Byte        VAR BYTE        ; Nibbles to Send
    LCD_RS          VAR LCD_Byte.0  ; Register Select bit
    LCD_RW          VAR LCD_Byte.1  ; Read/Write bit
    LCD_E           VAR LCD_Byte.2  ; Enable bit
    LCD_BackLight   VAR LCD_Byte.3  ; Backlight 0=ON
    LCD_WriteMode   VAR BYTE        ; 1=LowNibble, 2=HighNibble, 3=Both
    LCD_CommandMode VAR BIT         ; Indicates next byte is a command
    LCD_Byte2       VAR BYTE        ; Same nibble without E bit
    LCD_Idx         VAR BYTE
    testmode        var byte
    
    
    
    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 1000            ; LCD Power-on delay
    LCD_Backlight = 1     ; Backlight OFF
    LCD_RW = 0            ; Write to LCD
    LCD_RS = 0            ; Command Register
    
    LCD_WriteMode = 1     ;-- Low Nibbles only
    LCD_Data = 3          ; Reset 3 times
    gosub LCD_Write
    PAUSEUS 6000
    gosub LCD_Write
    PAUSEUS 1000
    gosub LCD_Write
    PAUSEUS 1000
    
    LCD_Data = 2          ; Start 4-bit mode
    gosub LCD_Write
    PAUSEUS 1000
    
    LCD_WriteMode = 3     ;-- Both Nibbles
    LCD_Data = $28
    gosub LCD_Write      ; Function Set, 4-bit, 2-line, 5x7
    LCD_Data = $0C
    gosub LCD_Write      ; Display ON
    LCD_Data = $01
    gosub LCD_Write      ; Clear Screen
    PAUSE 2
    LCD_Data = $06 
    gosub LCD_Write      ; Entry Mode
                           
    PAUSE 2               ; Let command finish
    LCD_RS = 1   ' this is data
    goto main
    
    LCD_WRITE:
          LCD_E = 1
       IF LCD_WriteMode.1 = 1 THEN                             ; Write High Nibble
         LCD_Byte = (LCD_Byte & $0F) | (LCD_Data  & $F0)
         LCD_Byte2 = LCD_Byte & $FB    
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
      
       IF LCD_WriteMode.0 = 1 THEN                             ; Write Low Nibble
         LCD_Byte = (LCD_Byte & $0F) | ((LCD_Data << 4 )& $F0)
         LCD_Byte2 = LCD_Byte & $FB
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
    return
    
    Main:
    
    I2CWRITE SDA,SCL, LCD_Addr, [%00000000] ' bck_lt= off
    PAUSE 200
    I2CWRITE SDA,SCL, LCD_Addr, [%00001000] ' bck_lt=on
    PAUSE 200
    
    LCD_Data = "T"
    gosub LCD_Write: PAUSEUS 50
    LCD_Data = "e" 
    gosub LCD_Write: PAUSEUS 50
    LCD_Data = "s" 
    gosub LCD_Write: PAUSEUS 50 
    LCD_Data = "t" 
    gosub LCD_Write: PAUSEUS 50 
    LCD_Data = "-" 
    gosub LCD_Write: PAUSEUS 50 
    pause 500
    goto Main
    Last edited by EarlyBird2; - 12th July 2014 at 22:24.

  15. #55
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    The problem could be with the delay on power up not being long enough for the LCD to initialise before the PIC starts.

    Adjust this line and test

    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 1000 ; LCD Power-on delay

    and please let me know the result.

  16. #56
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Dear Steve:

    Your suggested test gave me the response on the lack of operation. ( see the attached).
    The pcf has P0, P5 and P6 not working. This is the reason of the trouble.
    I will no longer buy components on Ebay expecially if chinese. That is very bad.
    I have no words to express my state. I want to apologize .
    Thanks for the help given to me since the beginning.
    Will try to buy another expander board: do you know some reliable seller in Europe ?
    Regards,
    Ambrogio
    Attached Images Attached Images  

  17. #57
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    Dear Steve:

    Your suggested test gave me the response on the lack of operation. ( see the attached).
    The pcf has P0, P5 and P6 not working. This is the reason of the trouble.
    I will no longer buy components on Ebay expecially if chinese. That is very bad.
    I have no words to express my state. I want to apologize .
    Thanks for the help given to me since the beginning.
    Will try to buy another expander board: do you know some reliable seller in Europe ?
    Regards,
    Ambrogio
    No problem and no need to apologise. Could you do some more testing on this board?
    Check the voltages on the P0 to P7 pins when this program is running.

    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    DEFINE I2C_SLOW 1
    C VAR portd.3 ' S_CLOCK 
    D VAR portd.2 ' S_DATA
    ADDR VAR BYTE 
    ADDR = %01001110 ' dec 78 , hex 4E
    CMD VAR BYTE
    LCD_CMD VAR BYTE 
    E VAR LCD_CMD.BIT2 
    RS VAR LCD_CMD.BIT0
    E=0:RS=0
    LCD_CMD = 0
    PAUSE 1000 
    
    MAIN:
    
    I2CWRITE D, C, ADDR, [%00000000] ' port off
    PAUSE 200
    I2CWRITE D, C, ADDR, [%11111111] ' port on
    PAUSE 200
    
    GOTO MAIN
    If all pins change then the PCF8574 chip is good indicating that the fault is either bad soldering or bad PCB track. It is possible to solder jumper wire direct to pins for a temporary repair.

  18. #58
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    are you sure the new board has 8574t on it not a 8574A ?
    that might make a world of difference

  19. #59
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    =richard;127791]are you sure the new board has 8574t on it not a 8574A ?
    that might make a world of difference
    It is definitely a 8574T as shown in #36 and copied below.

    [

  20. #60
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    is that the current device or the one that got zapped ?
    I found a 8574a in my junk box and fed your code into it (no lcd) and it seems ok (address is $78 for a version)
    the attached pcf8574a.txt file is really a salea logic data/setting file and should be renamed to pcf8574a.logicdata , if you don't have a salea logic analyser you can download the software from salea logic and view the complete data
    Attached Images Attached Images  
    Attached Files Attached Files

  21. #61
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Steve,
    I did run the program:
    P0, P5 and P6 do not toggle: they are always at 0vdc as seen by the scope.
    I did check the tracks : there is good continuity between each pin of the PCF and the display pins.
    I assume the pcf is gone or the module has been sent with a broken pcf.
    As you have seen in the photos, I have changed the contrast pot because it was shorting the 5 vdc to ground , I fit a new one with a "crossed" pins.
    Will order a new board from a reliable seller ... I am searching for it here.
    Thanks for all.
    Ambrogio

  22. #62
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by richard View Post
    is that the current device or the one that got zapped ?
    I found a 8574a in my junk box and fed your code into it (no lcd) and it seems ok (address is $78 for a version)
    the attached pcf8574a.txt file is really a salea logic data/setting file and should be renamed to pcf8574a.logicdata , if you don't have a salea logic analyser you can download the software from salea logic and view the complete data
    It is the current device.

    The PCF8574 and PCF8574A are identical, except for the different fixed portion of the slave address. The address used is 78 which fits with it being a PCF8574T and you use $78 which again fits with yours being a PCF8574AT.

  23. #63
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Thanks Richard,
    I confirm that the address is OK since I can get some pins toggling correctly.
    the PCF has definitively some "broken" port pins.
    I still have the suspect that this is a fake board: It has the contrast pot error ... and now it has this issue !
    Thanks a lot
    Ambrogio
    iw2fvo

  24. #64
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    Steve,
    I did run the program:
    P0, P5 and P6 do not toggle: they are always at 0vdc as seen by the scope.
    I did check the tracks : there is good continuity between each pin of the PCF and the display pins.
    I assume the pcf is gone or the module has been sent with a broken pcf.
    As you have seen in the photos, I have changed the contrast pot because it was shorting the 5 vdc to ground , I fit a new one with a "crossed" pins.
    Will order a new board from a reliable seller ... I am searching for it here.
    Thanks for all.
    Ambrogio
    Well done it is the PCF!
    I am surprised I thought the PCF was the least likely cause the PCB track or soldering fault was the most likely cause.

  25. #65
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help


  26. #66
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help


  27. #67
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    I have tested this code and it works!

    Code:
    DEFINE OSC 40 ' 10 MHz XTAL AND X 4 INTERNAL PLL 
    'DEFINE I2C_SLOW 1
    SDA         VAR PORTD.2       ; I2C Data pin
    SCL         VAR PORTD.3       ; I2C Clock Pin
    LCD_Addr CON 78
    'LCD_BuffSize    CON 30
    'LCD_Buff        VAR BYTE[LCD_BuffSize]
    'LCD_BuffAddr    CON EXT : @LCD_BuffAddr = _LCD_Buff
    'LCD_BuffLen     VAR WORD        ; Length of data in buffer
    LCD_Data        VAR BYTE        ; Data to Send to LCD
    LCD_Byte        VAR BYTE        ; Nibbles to Send
    LCD_RS          VAR LCD_Byte.0  ; Register Select bit
    LCD_RW          VAR LCD_Byte.1  ; Read/Write bit
    LCD_E           VAR LCD_Byte.2  ; Enable bit
    LCD_BackLight   VAR LCD_Byte.3  ; Backlight 0=ON
    LCD_WriteMode   VAR BYTE        ; 1=LowNibble, 2=HighNibble, 3=Both
    LCD_CommandMode VAR BIT         ; Indicates next byte is a command
    LCD_Byte2       VAR BYTE        ; Same nibble without E bit
    LCD_Idx         VAR BYTE
    testmode        var byte
    
    
    
    ;----[Initialize the LCD]-------------------------------------------------------
    PAUSE 250             ; LCD Power-on delay
    LCD_Backlight = 1     ; Backlight OFF
    LCD_RW = 0            ; Write to LCD
    LCD_RS = 0            ; Command Register
    
    LCD_WriteMode = 1     ;-- Low Nibbles only
    LCD_Data = 3          ; Reset 3 times
    gosub LCD_Write_
    PAUSEUS 6000
    gosub LCD_Write_
    PAUSEUS 1000
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_Data = 2          ; Start 4-bit mode
    gosub LCD_Write_
    PAUSEUS 1000
    
    LCD_WriteMode = 3     ;-- Both Nibbles
    LCD_Data = $28
    gosub LCD_Write_      ; Function Set, 4-bit, 2-line, 5x7
    LCD_Data = $0C
    gosub LCD_Write_      ; Display ON
    LCD_Data = $01
    gosub LCD_Write_      ; Clear Screen
    PAUSE 2
    LCD_Data = $06 
    gosub LCD_Write_      ; Entry Mode
                           
    PAUSE 2               ; Let command finish
    LCD_RS = 1   ' this is data
    goto main
    
    LCD_WRITE_:
       LCD_E = 1
       IF LCD_WriteMode.1 = 1 THEN                             ; Write High Nibble
         LCD_Byte = (LCD_Byte & $0F) | (LCD_Data  & $F0)
         LCD_Byte2 = LCD_Byte & $FB    
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
      
       IF LCD_WriteMode.0 = 1 THEN                             ; Write Low Nibble
         LCD_Byte = (LCD_Byte & $0F) | ((LCD_Data << 4 )& $F0)
         LCD_Byte2 = LCD_Byte & $FB
         I2CWRITE SDA,SCL, LCD_Addr,[LCD_Byte, LCD_Byte2]
       ENDIF
    return
    
    Main:
    LCD_Backlight = 0
    LCD_Data = "T"
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "e" 
    gosub LCD_Write_: PAUSEUS 50
    LCD_Data = "s" 
    gosub LCD_Write_: PAUSEUS 50 
    LCD_Data = "t" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    LCD_Backlight = 1
    LCD_Data = "-" 
    gosub LCD_Write_: PAUSEUS 50 
    pause 500
    goto main

  28. #68
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    I am not a good programmer and I would like to convert the PBP program that is normally used now to EASY control the I2C display.
    At the moment I am using this piece of code:

    INS CON 254 ' $FE: INSTRUCTION COMMAND MODE
    CLR CON 1 ' CLEAR LCD , GOTO FIRST LINE, FIRST CHARACTER
    DG CON 223 ' DEG SYMBOL °
    LINE1 CON 128 ' $80: GOTO LINE 1
    LINE2 CON 192 ' $C0: GOTO LINE 2
    LINE3 CON 148 ' $94: GOTO LINE 3
    LINE4 CON 212 ' $D4: GOTO LINE 4

    And then I do the the following to write my own data on it:

    LCDOUT INS, LINE2, " V=", DEC2 VLT/10, ".", DEC1 VLT

    How could I translate the above in I2C enviroment for displaying ?

    Thanks for the assistance
    Regards,
    Ambrogio
    IW2FVO
    How to do this as neatly as possible are the next steps.

  29. #69
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    the ext modifier should help
    lcdb VAR BYTE[22]

    ASM
    lcd_cmd = _lcdb
    lcd_buff = _lcdb+2

    ENDASM
    these must be after the asm code

    lcd_cmd var byte EXT
    lcd_buff var byte EXT




    lcdb[0]=$fe
    lcdb[1]= your lcd command eg 1 $80 $c0

    use arraywrite to load lcd_buff (max 20 chrs)

    then you can pass
    lcd_cmd to your lcd write code if you need to send a cmd with your lcd string
    or pass lcd_buff if no cmd required

    ps don't forget to add a dely after a cmd to give the lcd time to act

    ps ps
    the asm names are case sensitive


    left a bit out

    lcd_cmd var byte EXT
    lcd_buff var byte EXT

    not sure if it needs to be try it and see

    lcd_cmd var byte[2] EXT
    lcd_buff var byte[20] EXT
    Last edited by richard; - 17th July 2014 at 08:53. Reason: typo's

  30. #70
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by richard View Post
    the ext modifier should help
    lcdb VAR BYTE[22]

    ASM
    lcd_cmd = _lcdb
    lcd_buff = _lcdb+2

    ENDASM

    lcdb[0]=$fe
    lcdb[1]= your lcd command eg 1 $80 $c0

    use arraywrite to load lcd_buff (max 20 chrs)

    then you can pass
    lcd_cmd to your lcd write code if you need to send a cmd with your lcd string
    or pass lcd_buff if no cmd required

    ps don't forget to add a dely after a cmd to give the lcd time to act

    ps ps
    the asm names are case sensitive


    left a bit out

    lcd_cmd var byte EXT
    lcd_buff var byte EXT

    not sure if it needs to be try it and see

    lcd_cmd var byte[2] EXT
    lcd_buff var byte[20] EXT
    Steve,
    the point is that I do not have PBP_3.
    My pbp is 2.50 B.
    No arraywrite or read, no usercommand ... are available to me .
    Thanks
    Ambrogio
    Ambrogio is using pbp2.5 and I am even older on 2.46.

  31. #71
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    without arraywrite that's a lot of code

  32. #72
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by richard View Post
    without arraywrite that's a lot of code
    and a lot more fun!

    I am only along for the ride and to keep my brain ticking over.

  33. #73
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    does 2.5 have the dig command

  34. #74
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    The DIG modifier has been there forever....
    Dave Purola,
    N8NTA
    EN82fn

  35. #75
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Steve,
    it is a very good new !
    I am looking to place an order for a couple of new extender boards. The point is the lead time .
    I will let you know.
    I appreciate your assistance.
    Regards,
    Ambrogio

  36. #76
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Thanks to all of you for the assistance.
    What is the dig modifier please ?
    Thnaks
    Ambrogio

  37. #77
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    From manual:
    DIG returns the value of a decimal digit. Input the digit number (0 – 9, with 0 being the rightmost digit). DIG returns the value of the decimal digit that you specified. DIG is commonly used to distill BCD digits from numeric values and to isolate single digits for display on seven-segment LCD.
    B0 = 123 ' Set B0 to 123
    B1 = B0 DIG 2 ' Sets B1 to 1 (digit 2 of 123)

  38. #78
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Quote Originally Posted by iw2fvo View Post
    Steve,
    it is a very good new !
    I am looking to place an order for a couple of new extender boards. The point is the lead time .
    I will let you know.
    I appreciate your assistance.
    Regards,
    Ambrogio
    No next day delivery in Italy?

    I ordered my LCD and backpack for £9.30 including next day delivery, details in #66.

    The test program is not very useful as it only tests the LCD is working. I will add commands so that the screen can be cleared and the cursor can be positioned anywhere on the screen.

  39. #79
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    That is clear to me now.
    Thanks
    Ambrogio

  40. #80
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C lcd ( arduino ) with PICBASIC, help

    Ambrogio

    I am working on the program by adding commands as you can see in the picture.

    Name:  DSCN0246[1].jpg
Views: 1752
Size:  99.7 KB

    Let me know when you are ready.

Similar Threads

  1. Interfacing with Arduino I2C LCD
    By norohs in forum Documentation
    Replies: 47
    Last Post: - 30th May 2017, 18:53
  2. I2c ext eeprom picbasic
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th July 2011, 22:00
  3. How do I operate an Arduino I2C LCD
    By menta in forum General
    Replies: 8
    Last Post: - 13th July 2011, 02:28
  4. Still new to PicBasic - i2c questions
    By cometboy in forum mel PIC BASIC
    Replies: 4
    Last Post: - 13th November 2006, 18:27
  5. A little help with I2C and PICBASIC Pro
    By Qacer in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th January 2006, 16:13

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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