I2C lcd ( arduino ) with PICBASIC, help


Closed Thread
Results 1 to 40 of 93

Hybrid View

  1. #1
    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 Steve,
    I do appreciate your help. I will tell you as soon as I have the new dispaly in my hands.
    Ambrogio

  2. #2
    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 received the new display just now.
    It is equipped with the PCF 8574T.
    It is connected to the QC2004A display in the following way:

    pin_4 p0 > RS
    pin_5 p1 > RW
    pin_6 p2 > enable
    pin_7 p3 > Backlight
    pin_9 p4> data4
    pin_10 p5 > data5
    pin_11 p6 > data6
    pin_12 p7 > data7

    It is different wrt the one I had before: it has a different connections between the PCF and the LCD.
    I will be ready for testing tomorrow or monday: please suggest me what trials to do just to start.
    Thanks for all
    Ambrogio

  3. #3
    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

    We start with Darrel's routine for PBP3 and make changes for your LCD pin setup and PBP2.x

    http://support.melabs.com/threads/98...F8574-20x4-LCD

  4. #4
    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,
    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

  5. #5
    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,
    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
    Yes the arraywrite command has to be handled differently in pbp2.5.

    Arraywrite loads the LCD_Buff you need to replace Arraywrite with a routine that loads what you want displayed on the LCD into LCD_Buff.

    For example
    LCD_BuffLen = 4
    LCD_Buff.0 = "T"
    LCD_Buff.1 = "e"
    LCD_Buff.2 = "s"
    LCD_Buff.3 = "t"
    LCD_WriteBuff

    Just to give you an idea as I think this is how it works but obviously I have not tested it as only you have the hardware.

    Also johncouture's LCD has the same pins as your's (check it) so his modified programs are the ones you need to use.

    This is the first step more issues could be thrown up. I am expecting to enjoy the ride (voyage of discovery) and hopefully get it working.

  6. #6
    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,
    sorry for not having reply soon because of " family duty ".
    I wrote this small program and I am able to control Backlight :

    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

    The I2C address is new.
    Now, my LCD has 20 chrs X 4 lines.
    The PCF controls the LCD using the upper four bits of its output port.
    I have to initialize the LCD in four bit mode , four lines at the required PCF port pins.
    How could I do that ?
    Thanks
    Ambrogio

  7. #7
    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

    Initialise is at the end of the second code which you need to include using this code

    Code:
    INCLUDE "LCD_PCF8574A.pbp"     ; Init LCD using I2C and PCF8574
    Code:
    ; File Name   : LCD_PCF8574A.pbp
    ; Author      : Darrel Taylor
    ; Created     : Mon Feb 24 2014
    ;               Sun Mar 03 2014
    ;               Updated bit shift. Data is on Lower side, Cmd lines on Upper               
    ; Compiler    : PicBasic Pro 3.0.6.x or higher
    ; Description : Uses PCF8574 Port expander to interface with HD44780 LCD
    ;
    ;-------------------------------------------------------------------------------
    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
    
    GOTO Over_LCDPCF8574 
    
    ;----[Write 1-byte to LCD]--(Input is LCD_Data)---------------------------------
    USERCOMMAND "LCD_WRITE"
    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
    
    ASM
    LCD_WRITE?  macro
        L?CALL _LCD_WRITE_
      endm
    ENDASM
    
    ;----[Write contents of buffer to LCD]------------------------------------------
    USERCOMMAND "LCD_WRITEBUFF"
    LCD_WRITEBUFF_:
    ' The purpose of this routine is to increment through LCD_Buff and
    ' pass each character to LCD_Data so that it can be written.
    ' This will loop for LCD_BuffLen which is calculated by 
    '    subtracting the starting address of the buffer from the
    '    ending address of the buffer.
    
        LCD_BuffLen = R5 - LCD_BuffAddr -1
        LCD_WriteMode = 3          ; Both Nibbles
        LCD_CommandMode = 0
        FOR LCD_Idx = 0 TO LCD_BuffLen
            IF LCD_Buff(LCD_Idx) = $FE THEN LCD_CommandMode = 1 : GOTO LCD_ByteDone
            IF LCD_CommandMode THEN
                LCD_RS = 0   ' this is a command
                LCD_CommandMode = 0 ' false, next byte will be data
            ELSE
                LCD_RS = 1   ' this is data
            ENDIF
            LCD_Data = LCD_Buff(LCD_Idx)
            LCD_Write
            IF LCD_CommandMode THEN
                PAUSE 2
            ELSE
                PAUSEUS 50
            ENDIF
    
          LCD_ByteDone:
        NEXT LCD_Idx
    
        LCD_CommandMode = 0
    RETURN
    
    ASM
    LCD_WRITEBUFF?  macro
        L?CALL _LCD_WRITEBUFF_
      endm
    ENDASM
    
    USERCOMMAND "LED_WRITE"
    LED_Write_:    
        ; Write to the LEDs (this is a test routine)
        LCD_E = 1
        IF LCD_WriteMode.0 = 1 THEN                                  ; Write Low Nibble
           LCD_Byte = (LCD_Byte & $0F) | (LCD_Data  & $F0)
           LCD_Byte2 = LCD_Byte & $FB
           i2cwrite SDA,SCL, LCD_Addr2,[LCD_Byte]
           pause 500
           i2cwrite SDA,SCL, LCD_Addr2,[LCD_Byte2]
           pause 500
        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_Addr2,[LCD_Byte]
           pause 500
           i2cwrite SDA,SCL, LCD_Addr2,[LCD_Byte2]
           pause 500
        endif   
    RETURN
    
    ASM
    LED_WRITE?  macro
        L?CALL _LED_WRITE_
      endm
    ENDASM
    
    Over_LCDPCF8574:
    
    ;----[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
    The files you need are here
    http://support.melabs.com/threads/98...F8574-20x4-LCD

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