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.
    your assistance is great.
    Ambrogio

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

    This is the code to initialise the LCD and send Test. It does not use the LCD_Buff features. Obviously you need to check the OSC and DEFINEs as usual. I do expect this not to work first time!

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

  3. #3
    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,
    Thanks a lot for the intersest.
    It does not work. I added the bck_lt flashing in the main loop just to see if the communication is good > the bck_lt comes ond goes correctly.
    I am attaching the whole program
    Ambrogio
    '************************************************* ***************
    '* Name : RKPK40 board pic18F452 40 MHz *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 23/06/2014 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    ';Program Configuration Register 1H
    @ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H

    ';Program Configuration Register 2L
    @ __CONFIG _CONFIG2L, _BOR_OFF_2L & _BORV_20_2L & _PWRT_ON_2L

    ';Program Configuration Register 2H
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H

    ';Program Configuration Register 3H
    @ __CONFIG _CONFIG3H, _CCP2MX_OFF_3H

    ';Program Configuration Register 4L
    @ __CONFIG _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L

    ';Program Configuration Register 5L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L

    ';Program Configuration Register 5H
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H

    ';Program Configuration Register 6L
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L

    ';Program Configuration Register 6H
    @ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H

    ';Program Configuration Register 7L
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L

    ';Program Configuration Register 7H
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H


    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
    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_
    pause 5000
    i2cwrite sda, scl, LCD_addr, [0] ' back_lt blinking
    pause 1000
    i2cwrite sda, scl, LCD_Addr,[%00010000]
    pause 1000
    goto main

  4. #4
    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,
    Thanks a lot for the intersest.
    It does not work. I added the bck_lt flashing in the main loop just to see if the communication is good > the bck_lt comes ond goes correctly.
    I am attaching the whole program
    Ambrogio
    Code:
    '****************************************************************
    '*  Name    : RKPK40 board pic18F452  40 MHz                    *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 23/06/2014                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    ';Program Configuration Register 1H
    @		__CONFIG    _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H      
    
    ';Program Configuration Register 2L
    @		__CONFIG    _CONFIG2L, _BOR_OFF_2L & _BORV_20_2L & _PWRT_ON_2L
    
    ';Program Configuration Register 2H
    @		__CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
    
    ';Program Configuration Register 3H
    @		__CONFIG    _CONFIG3H, _CCP2MX_OFF_3H
    
    ';Program Configuration Register 4L
    @		__CONFIG    _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
    
    ';Program Configuration Register 5L
    @		__CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L 
    
    ';Program Configuration Register 5H
    @		__CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    
    ';Program Configuration Register 6L
    @		__CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L 
    
    ';Program Configuration Register 6H
    @		__CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    
    ';Program Configuration Register 7L
    @		__CONFIG    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
    
    ';Program Configuration Register 7H
    @		__CONFIG    _CONFIG7H, _EBTRB_OFF_7H
    
    
    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
    I over simplified the program!
    need to add this line

    LCD_RS = 1 ' this is data highlighted in red above. This switches from command mode to data. It was in command mode that is why your back_lt instructions worked. An excellent clue for me.

    I am not sure about these lines

    LCD_Data = $28
    gosub LCD_Write_ ; Function Set, 4-bit, 2-line, 5x7


    and what the location addresses are to position the cursor at the beginning of each line.

    Have you a datasheet for this LCD?

    When this simple example is working we can add Command/Data switching which we will obviously need to have. I will follow Darrel's method as close as possible, he uses $FE to indicate the next byte is a command and switches to command mode for one byte then back to data.

    Plenty for me to think about.

  5. #5
    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 have checked the PCF to LCD connection :

    bit0 = RS
    bit1 =RW
    bit2 =EN
    bit3 =bck_lt
    bit4 =D4
    bit5 =D5
    bit6 =D6
    bit7 =D7

    D0 to D3 of the LCD : there is no connection at all.

    Regards,
    Ambrogio

  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,
    the display has 20 chrs X 4 lines.
    Thanks,
    Ambrogio

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    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

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

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

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

    without arraywrite that's a lot of code

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

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

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

    does 2.5 have the dig command

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

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

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