Replace the PRINT command to use I2C backpack on 1602 LCD


+ Reply to Thread
Page 1 of 18 12311 ... LastLast
Results 1 to 15 of 264
  1. #1
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    1 Not allowed!

    Default Replace the PRINT command to use I2C backpack on 1602 LCD

    You can buy the backpack http://www.ebay.co.uk/itm/TWI-SPI-II...item2a2ff9ffbb on Ebay for silly money, £1.50

    At the outset I assumed that the major problems would be the replacement of the Print command or the synthesis of the HD44780 protocol over I2C. Given that how old and widely used the HD44780 is, I assumed that its initialization and everything about this device would be well documented. Of the sources I found few mentioned the 3/4 nibbles that are required to start the process, and of those that did few seemed to agree on value or quantity. I eventually used the I2C monitor in Proteus to copy the values that Proton uses. The other problem I had is that oddly

    Code:
     HBusOut Address, [ByteA | ByteB]
    doesn't OR the bytes together and send the result, it sends both bytes.

    The replacement of the print command is a straight rip of a similar exercise that Barak posted for a graphic LCD using SPI.

    I use breadboard a lot and this arrangement works really well particularly on devices like 18F4550 where Gnd, Vcc, SCL and SDA are on adjacent pins. I use a 4 pin header and ribbon cable to the Backpack/1602, so no breadboard territory is used by the LCD.

    Here is a version for 4550 using the MSSP ie I2C is generated by hardware on the PIC
    Code:
    '*****************************************************************************************************************
    '*  Name    : I2CPrintCommand.bas                                                                                *
    '*  Purpose : allow Proton Print commands to access the standard 1602 LCD via I2C serial board                   * 
    '*  Author  : George Towler                                                                                      *
    '*  Notice  : I claim no copyright but maybe Barak does                                                          *
    '*  Date    : 16/08/2013                                                                                         *
    '*  Version : 0.1                                                                                                *
    '*  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  *                                          *                                                                                     *
    '*****************************************************************************************************************
        Device = 18F4550
    
        Config_Start
          PLLDIV = 5    ;Divide by 5 (20 MHz oscillator input)
          CPUDIV = OSC1_PLL2    ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
          USBDIV = 2    ;USB clock source comes from the 96 MHz PLL divided by 2
          FOSC = HSPLL_HS    ;HS oscillator, PLL enabled (HSPLL)
          FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
          IESO = OFF    ;Oscillator Switchover mode disabled
          PWRT = On    ;PWRT enabled
          BOR = On    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
          BORV = 3    ;Minimum setting
          VREGEN = OFF    ;USB voltage regulator disabled
          WDT = OFF    ;WDT disabled (control is placed on the SWDTEN bit)
          WDTPS = 32768    ;1:32768
          CCP2MX = OFF    ;CCP2 input/output is multiplexed with RB3
          PBADEN = OFF    ;PORTB<4:0> pins are configured as digital I/O on Reset
          LPT1OSC = OFF    ;Timer1 configured for higher power operation
          MCLRE = On    ;MCLR pin enabled; RE3 input pin disabled
          STVREN = On    ;Stack full/underflow will cause Reset
          LVP = OFF    ;Single-Supply ICSP disabled
          ICPRT = OFF    ;ICPORT disabled
          XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
          Debug = OFF    ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
          CP0 = OFF    ;Block 0 (000800-001FFFh) is not code-protected
          CP1 = OFF    ;Block 1 (002000-003FFFh) is not code-protected
          CP2 = OFF    ;Block 2 (004000-005FFFh) is not code-protected
          CP3 = OFF    ;Block 3 (006000-007FFFh) is not code-protected
          CPB = OFF    ;Boot block (000000-0007FFh) is not code-protected
          CPD = OFF    ;Data EEPROM is not code-protected
          WRT0 = OFF    ;Block 0 (000800-001FFFh) is not write-protected
          WRT1 = OFF    ;Block 1 (002000-003FFFh) is not write-protected
          WRT2 = OFF    ;Block 2 (004000-005FFFh) is not write-protected
          WRT3 = OFF    ;Block 3 (006000-007FFFh) is not write-protected
          WRTC = OFF    ;Configuration registers (300000-3000FFh) are not write-protected
          WRTB = OFF    ;Boot block (000000-0007FFh) is not write-protected
          WRTD = OFF    ;Data EEPROM is not write-protected
          EBTR0 = OFF    ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
          EBTR1 = OFF    ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
          EBTR2 = OFF    ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
          EBTR3 = OFF    ;Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
          EBTRB = OFF    ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
        Config_End
    
      #Disable Print                               ' put the disable after config fuses
    
      Xtal = 48
      All_Digital = True
     
      Symbol Control = %01000000                   ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW  where W=0
      Symbol Address = Control + $0E
      Symbol InitForLCDLines = $28                 ' LCD has two lines
      
      ' Define I2C bus ports
      Declare SDA_Pin = PORTB.0 
      Declare SCL_Pin = PORTB.1 
      Declare Slow_Bus On
      Declare Hbus_Bitrate 100
    
      Dim PrintData As Byte
      Dim HighData As Byte
      Dim LowData As Byte
      Dim dummy As Byte
      Dim RSFlag As Byte
    
    
      GoTo Boot                                    ' jump over the Print redicet
    
      @Print                                       ' assembler Print redirect
      Wreg_Byte PrintData                          ' load LCDByte to W Register
      GoTo LCD_WriteData                           ' print command Excution
    
      '***[Start here]****************************
    Boot:
      DelayMS 500
      GoSub PrintInit
    
    ' You're Main goes here, delete the test below, don't forget to set the address and the correct InitForLCDLines
    
    
    Main:                                          ' just try to print stuff
      While 1 = 1    
        Print At 1,4,"new print"                   ' test printing at coordinates At x,y,
        DelayMS 1000
        Print 0xFE,0x01                            ' test sending a comad 0x01 is Cls
        DelayMS 1000
          Dim Flt As Float                         ' generate rubbish to test Print modifier
          Flt = 3.14519453466
        Print At 2,5, Dec4 Flt                     ' test printing a formated nomber
        DelayMS 1000
        Cursor 1,2                                 ' test moving the cursor
        Print " something"
        DelayMS 1000
        Cls                                        ' test Cls
        DelayMS 1000
      Wend
    
    ' ****************************************************************************
    ' **                             S U B R O U T I N E S                      **
    ' ****************************************************************************
    
    SendData:
      HighData = PrintData & %11110000     ; mask LSBs
      LowData = PrintData << 4             ; shift left
      dummy = %00001101 | HighData         ; data and e hi
      HBusOut Address, [dummy]              
      dummy = %00001001 | HighData         ; data and e lo
      HBusOut Address, [dummy]              
      HBusOut Address, [%00001001]         ; Delay, Backlight and RS on throughout
      dummy = %00001101 | LowData          ; data and e hi
      HBusOut Address, [dummy]              
      dummy = %00001001 | LowData          ; data and e lo
      HBusOut Address, [dummy]         
      Return
      
      
    SendControl:
      HighData = PrintData & %11110000     ; mask LSBs
      LowData = PrintData << 4             ; shift left
      dummy = %00001100 | HighData         ; data and e hi
      HBusOut Address, [dummy]              
      dummy = %00001000 | HighData         ; data and e lo
      HBusOut Address, [dummy]              
      HBusOut Address, [%00001000]         ; Delay, Backlight on throughout
      dummy = %00001100 | LowData          ; data and e hi
      HBusOut Address, [dummy]              
      dummy = %00001000 | LowData          ; data and e lo
      HBusOut Address, [dummy]         
      DelayMS 20
      Return
    
      
    PrintInit:
      HBusOut Address, [%00111100]         ; E hi and send command nibble 0011 (3)    
      HBusOut Address, [%00111000]         ; E lo     
      DelayMS 20
    
      HBusOut Address, [%00111100]         ; E hi and send command nibble 0011 (3)    
      HBusOut Address, [%00111000]         ; E lo     
      DelayMS 20
    
      HBusOut Address, [%00101100]         ; E hi and send command nibble 0010 (2)    
      HBusOut Address, [%00101000]         ; E lo     
      DelayMS 20
    
      PrintData = InitForLCDLines          ; 4 bit mode and n lines 
      GoSub SendControl
      PrintData = $0C                      ; enable display, 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
      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
    If you are using a PIC that doesn't have an MSSP or would prefer not to use the fixed pins for I2C, then specify the pins for SDA and SLC and replace the HBUSOUT commands with BUSOUT and Proton will bit bang on any pins you like.

    Obviously in real use your code will replace the nonsense main I have used to test control codes.

    George
    Last edited by towlerg; 21st August 2013 at 01:24. Reason: old and stupid

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.

  • #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,676
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Good Stuff, thanks
    Tim

  • 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
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,468
    Thumbs Up
    Received: 71
    Given: 29
    Total Downloaded
    6.17 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    George,

    Why you don't make a small article in the Wiki? Eventually it will get lost here.
    Regards

    Joseph

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

  • #4
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Sorry Joe, don't know how to. Is there a "how to make a wiki article" tutorial?

    George

  • 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
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,468
    Thumbs Up
    Received: 71
    Given: 29
    Total Downloaded
    6.17 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Quote Originally Posted by towlerg View Post
    Sorry Joe, don't know how to. Is there a "how to make a wiki article" tutorial?

    George
    Go to Wiki, on the right hand side, above `recent activity' there is `Create article', hit go and you can begin. If you need further help try here.
    Regards

    Joseph

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

  • #6
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    558
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Hi George,

    I've been playing around with your program without any real success. Now it must be said for starters that I'm trying to get it to work with a PIC16F877A and so a few mods have been made. These are.....

    Code:
     Device = 16F877A
     
      Config FOSC_HS, WDTE_OFF, PWRTE_ON, BOREN_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, CP_OFF
    
      #Disable Print                               ' put the disable after config fuses
    
      Xtal = 4
      All_Digital = True
     
      Symbol Control = 000000                   ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW  where W=0
      Symbol Address = Control + $0E
      Symbol InitForLCDLines = $28                 ' LCD has two lines
      
      ' Define I2C bus ports
      Declare SDA_Pin = PORTC.4 
      Declare SCL_Pin = PORTC.3 
      'Declare Slow_Bus On
      'Declare Hbus_Bitrate 100
    All other parts of your program remain unchanged. When I power the PIC up the LCD light illuminates suggesting I've got the address right. (changing the address results in no light). It seems that the LCDs - I've tried several types - are not initialising? All I get on the display is 16 dark blocks. Any pointers as to the problem would be greatly appreciated.


    Bob
    Last edited by Mellbreak; 23rd August 2013 at 17:31.

  • 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
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    558
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Having had a further look around my I2C board, I'm starting to wonder if the wiring on mine is the same as George's. Looking around the Internet it seems that there are several configurations available. The connections on my board are as follows....

    PCF8574 P0 ....Lcd pin 11 (D4)
    PCF8574 P1 ....Lcd pin 12 (D5)
    PCF8574 P2 ....Lcd pin 13 (D6)
    PCF8574 P3 ....Lcd pin 14 (D7)
    PCF8574 P4 ....Lcd pin 6 (E)
    PCF8574 P5 ....Lcd pin 5 (R/W)
    PCF8574 P6 ....Lcd pin 4 (RS)
    PCF8574 P7 ....Lcd Backlight control.


    Are yours the same George? If not then I suspect that's my problem.

    Kind regards,

    Bob

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

  • #8
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Hi Mellbreak,

    you're right, the pin assignment of the 8574 is different. Check that you have a 8574 not 8574A - different address range.

    Here's mine
    Click image for larger version

Name:	I2CPrint.jpg
Views:	100
Size:	19.0 KB
ID:	1897

    I've attached a zip with this picture, a Proteus model and a test program that toggles the backlight (shows you have the right address without worring about the HD44780 protocol, it writes to all possible address, so with a bit of judicious remming you can confirm the correct address - you see that in the test program I tried to use symbolic names for the bits but because of the odd way HBUSOUT works I applied KISS)

    George
    Attached Files Attached Files

  • 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
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Here's a version thats functionally the same (I hope) but which brings out the variables for LCD and I2C hardware and symbolizes the bit patterns.

    Code:
    '*****************************************************************************************************************
    '*  Name    : I2CPrintCommand.bas                                                                                *
    '*  Purpose : allow Proton Print commands to access the standard 1602 LCD via I2C serial board                   * 
    '*  Author  : George Towler                                                                                      *
    '*  Notice  : I claim no copyright but maybe Barak does                                                          *
    '*  Date    : 24/08/2013                                                                                         *
    '*  Version : 0.1.1                                                                                                *
    '*  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  *                                          *                                                                                     *
    '*****************************************************************************************************************
        Device = 18F4550
    
        Config_Start
          PLLDIV = 5    ;Divide by 5 (20 MHz oscillator input)
          CPUDIV = OSC1_PLL2    ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
          USBDIV = 2    ;USB clock source comes from the 96 MHz PLL divided by 2
          FOSC = HSPLL_HS    ;HS oscillator, PLL enabled (HSPLL)
          FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
          IESO = OFF    ;Oscillator Switchover mode disabled
          PWRT = On    ;PWRT enabled
          BOR = On    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
          BORV = 3    ;Minimum setting
          VREGEN = OFF    ;USB voltage regulator disabled
          WDT = OFF    ;WDT disabled (control is placed on the SWDTEN bit)
          WDTPS = 32768    ;1:32768
          CCP2MX = OFF    ;CCP2 input/output is multiplexed with RB3
          PBADEN = OFF    ;PORTB<4:0> pins are configured as digital I/O on Reset
          LPT1OSC = OFF    ;Timer1 configured for higher power operation
          MCLRE = On    ;MCLR pin enabled; RE3 input pin disabled
          STVREN = On    ;Stack full/underflow will cause Reset
          LVP = OFF    ;Single-Supply ICSP disabled
          ICPRT = OFF    ;ICPORT disabled
          XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
          Debug = OFF    ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
          CP0 = OFF    ;Block 0 (000800-001FFFh) is not code-protected
          CP1 = OFF    ;Block 1 (002000-003FFFh) is not code-protected
          CP2 = OFF    ;Block 2 (004000-005FFFh) is not code-protected
          CP3 = OFF    ;Block 3 (006000-007FFFh) is not code-protected
          CPB = OFF    ;Boot block (000000-0007FFh) is not code-protected
          CPD = OFF    ;Data EEPROM is not code-protected
          WRT0 = OFF    ;Block 0 (000800-001FFFh) is not write-protected
          WRT1 = OFF    ;Block 1 (002000-003FFFh) is not write-protected
          WRT2 = OFF    ;Block 2 (004000-005FFFh) is not write-protected
          WRT3 = OFF    ;Block 3 (006000-007FFFh) is not write-protected
          WRTC = OFF    ;Configuration registers (300000-3000FFh) are not write-protected
          WRTB = OFF    ;Boot block (000000-0007FFh) is not write-protected
          WRTD = OFF    ;Data EEPROM is not write-protected
          EBTR0 = OFF    ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
          EBTR1 = OFF    ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
          EBTR2 = OFF    ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
          EBTR3 = OFF    ;Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
          EBTRB = OFF    ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
        Config_End
    
      #Disable Print                               ' put the disable after config fuses
    
      Xtal = 48
      All_Digital = True
    
      ;*********************************************************************************
      ; you need to set these 6 items to suit you're LCD and I2C hardware 
      ;
      Symbol Part_address = $0E               ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW  where W=0
      Symbol InitForLCDLines = $28            ' $28 for two lines
      Symbol LCD_RS         = %00000001
      Symbol LCD_RW         = %00000010
      Symbol LCD_E          = %00000100
      Symbol BackLight      = %00001000
      ;**********************************************************************************
    
      Symbol BackLight_RS   = BackLight | LCD_RS
      Symbol BackLight_E    = BackLight | LCD_E
      Symbol BackLight_RS_E = BackLight | LCD_RS | LCD_E
      Symbol Init1          = %00110000 | BackLight 
      Symbol Init1_E        = %00110000 | BackLight | LCD_E
      Symbol Init2          = %00110000 | BackLight 
      Symbol Init2_E        = %00110000 | BackLight | LCD_E
      Symbol Init3          = %00100000 | BackLight 
      Symbol Init3_E        = %00100000 | BackLight | LCD_E
      Symbol Control = %01000000                         
      Symbol Address = Control + Part_address
        
      ' Define I2C bus ports
      Declare SDA_Pin = PORTB.0 
      Declare SCL_Pin = PORTB.1 
      Declare Slow_Bus On
      Declare Hbus_Bitrate 100
    
      Dim PrintData As Byte
      Dim HighData As Byte
      Dim LowData As Byte
      Dim dummy As Byte
      Dim RSFlag As Byte
    
    
      GoTo Boot                                    ' jump over the Print redicet
    
      @Print                                       ' assembler Print redirect
      Wreg_Byte PrintData                          ' load LCDByte to W Register
      GoTo LCD_WriteData                           ' print command Excution
    
      '***[Start here]****************************
    Boot:
      DelayMS 500
      GoSub PrintInit
    
    ' You're Main goes here, delete the test below, don't forget to set the address and the correct InitForLCDLines
    
    
    Main:                                          ' just try to print stuff
      While 1 = 1    
        Print At 1,4,"new print"                   ' test printing at coordinates At x,y,
        DelayMS 1000
        Print 0xFE,0x01                            ' test sending a comad 0x01 is Cls
        DelayMS 1000
          Dim Flt As Float                         ' generate rubbish to test Print modifier
          Flt = 3.14519453466
        Print At 2,5, Dec4 Flt                     ' test printing a formated nomber
        DelayMS 1000
        Cursor 1,2                                 ' test moving the cursor
        Print " something"
        DelayMS 1000
        Cls                                        ' test Cls
        DelayMS 1000
      Wend
    
    ' ****************************************************************************
    ' **                             S U B R O U T I N E S                      **
    ' ****************************************************************************
    
    SendData:
      HighData = PrintData & %11110000     ; 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 & %11110000     ; 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
      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
    Attached Files Attached Files
    Last edited by towlerg; 24th August 2013 at 11:32.

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

  • #10
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    I just realized, I've assumed that the data lines are on the high order bits of the 8574 (as luck would have it, not in your case Mellbreak). You just need to change the masks to %00001111 and rotate right. Someday when I'm bored I make that symbolic as well. Unless Mellbreak beats me to it. If you do that, please post.


    George

  • 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
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    558
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    George,

    Thanks for all the additional information that you've posted. It's going to be of real help. I'm away for a few days now, but will get to work on my return.

    Bob

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

  • #12
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    1 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Mellbreak,

    This should take care of pretty much any configuration of bits on the backpack. Of course I can't test with your hardware, but it works OK in simulation.
    Data is on either the top or bottom 4 bits and E, RS, RW and Backlight are any any remaining pin.

    Code:
    '*****************************************************************************************************************
    '*  Name    : I2CPrintCommand.bas                                                                                *
    '*  Purpose : allow Proton Print commands to access the standard 1602 LCD via I2C serial board                   * 
    '*  Author  : George Towler                                                                                      *
    '*  Notice  : I claim no copyright but maybe Barak does                                                          *
    '*  Date    : 26/08/2013                                                                                         *
    '*  Version : 0.1.2                                                                                                *
    '*  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.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
    
    
        Device = 18F4550
        Config_Start
          PLLDIV = 5           ;Divide by 5 (20 MHz oscillator input)
          CPUDIV = OSC1_PLL2 ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
          USBDIV = 2           ;USB clock source comes from the 96 MHz PLL divided by 2
          FOSC = HSPLL_HS       ;HS oscillator, PLL enabled (HSPLL)
          FCMEN = OFF           ;Fail-Safe Clock Monitor disabled
          IESO = OFF           ;Oscillator Switchover mode disabled
          PWRT = On             ;PWRT enabled
          BOR = On             ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
          BORV = 3             ;Minimum setting
          VREGEN = OFF         ;USB voltage regulator disabled
          WDT = OFF             ;WDT disabled (control is placed on the SWDTEN bit)
          WDTPS = 32768         ;1:32768
          CCP2MX = OFF         ;CCP2 input/output is multiplexed with RB3
          PBADEN = OFF         ;PORTB<4:0> pins are configured as digital I/O on Reset
          LPT1OSC = OFF         ;Timer1 configured for higher power operation
          MCLRE = On           ;MCLR pin enabled; RE3 input pin disabled
          STVREN = On           ;Stack full/underflow will cause Reset
          LVP = OFF             ;Single-Supply ICSP disabled
          ICPRT = OFF           ;ICPORT disabled
          XINST = OFF           ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
          Debug = OFF           ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
          CP0 = OFF             ;Block 0 (000800-001FFFh) is not code-protected
          CP1 = OFF             ;Block 1 (002000-003FFFh) is not code-protected
          CP2 = OFF             ;Block 2 (004000-005FFFh) is not code-protected
          CP3 = OFF             ;Block 3 (006000-007FFFh) is not code-protected
          CPB = OFF             ;Boot block (000000-0007FFh) is not code-protected
          CPD = OFF             ;Data EEPROM is not code-protected
          WRT0 = OFF           ;Block 0 (000800-001FFFh) is not write-protected
          WRT1 = OFF           ;Block 1 (002000-003FFFh) is not write-protected
          WRT2 = OFF           ;Block 2 (004000-005FFFh) is not write-protected
          WRT3 = OFF           ;Block 3 (006000-007FFFh) is not write-protected
          WRTC = OFF           ;Configuration registers (300000-3000FFh) are not write-protected
          WRTB = OFF           ;Boot block (000000-0007FFh) is not write-protected
          WRTD = OFF           ;Data EEPROM is not write-protected
          EBTR0 = OFF           ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
          EBTR1 = OFF           ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
          EBTR2 = OFF           ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
          EBTR3 = OFF           ;Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
          EBTRB = OFF           ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
        Config_End
    
      #Disable Print                               ' put the disable after config fuses
    
      Xtal = 48
      All_Digital = True
    
      ;****************************************************************************************************
      ; Configure items to suit your LCD and I2C hardware, DataOnHighBits remmed if data is on low bits   *
      ;                                                                                                   *
      Symbol Part_address    = $0E         ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW  where W=0         *
      Symbol InitForLCDLines = $28         ' $28 for two lines                                            *
      Symbol LCD_RS          = %00000001   '                                                              *
      Symbol LCD_RW          = %00000010   '                                                              *
      Symbol LCD_E           = %00000100   '                                                              *
      Symbol BackLight       = %00001000   '                                                              *
      $define DataOnHighBits               '                                                              *
      ;****************************************************************************************************
      ;
      ;  Example of Backpack with control bits on the low order nibble, DataOnHighBits would be remmed
      ;  Symbol LCD_RS         = %01000000
      ;  Symbol LCD_RW         = %00100000
      ;  Symbol LCD_E          = %00010000
      ;  Symbol BackLight      = %10000000
      ;  A0=D0  A1=D1  A2=D2  A3=D3  A4=E  A5=RW  A6=RS  A7=BackLight
      ;
      Symbol BackLight_RS   = BackLight | LCD_RS
      Symbol BackLight_E    = BackLight | LCD_E
      Symbol BackLight_RS_E = BackLight | LCD_RS | LCD_E
      Symbol Control = %01000000                         
      Symbol Address = Control + Part_address
    
      $ifdef DataOnHighBits
        Symbol Init1          = %00110000 | BackLight 
        Symbol Init1_E        = %00110000 | BackLight | LCD_E
        Symbol Init2          = %00110000 | BackLight 
        Symbol Init2_E        = %00110000 | BackLight | LCD_E
        Symbol Init3          = %00100000 | BackLight 
        Symbol Init3_E        = %00100000 | BackLight | LCD_E
      $else
        Symbol Init1          = %00000011 | BackLight 
        Symbol Init1_E        = %00000011 | BackLight | LCD_E
        Symbol Init2          = %00000011 | BackLight 
        Symbol Init2_E        = %00000011 | BackLight | LCD_E
        Symbol Init3          = %00000010 | BackLight 
        Symbol Init3_E        = %00000010 | BackLight | LCD_E
      $endif
        
      ' Define I2C bus ports
      Declare SDA_Pin = PORTB.0 
      Declare SCL_Pin = PORTB.1 
      Declare Slow_Bus On
      Declare Hbus_Bitrate 100
    
      Dim PrintData As Byte
      Dim HighData As Byte
      Dim LowData As Byte
      Dim dummy As Byte
      Dim RSFlag As Byte
    
    
      GoTo Boot                                    ' jump over the Print redicet
    
      @Print                                       ' assembler Print redirect
      Wreg_Byte PrintData                          ' load LCDByte to W Register
      GoTo LCD_WriteData                           ' print command Excution
    
      '***[Start here]****************************
    Boot:
      DelayMS 500
      GoSub PrintInit
    
    ' You're Main goes here, delete the test below, don't forget to set the address and the correct InitForLCDLines
    
    
    Main:                                          ' just try to print stuff
      While 1 = 1    
        Print At 1,4,"new print"                   ' test printing at coordinates At x,y,
        DelayMS 1000
        Print 0xFE,0x01                            ' test sending a comad 0x01 is Cls
        DelayMS 1000
          Dim Flt As Float                         ' generate rubbish to test Print modifier
          Flt = 3.14519453466
        Print At 2,5, Dec4 Flt                     ' test printing a formated nomber
        DelayMS 1000
        Cursor 1,2                                 ' test moving the cursor
        Print " something"
        DelayMS 1000
        Cls                                        ' test Cls
        DelayMS 1000
      Wend
    
    ' ****************************************************************************
    ' **                             S U B R O U T I N E S                      **
    ' ****************************************************************************
    
    SendData:
    
      $ifdef DataOnHighBits
        HighData = PrintData & %11110000   ; mask LSBs
        LowData = PrintData << 4           ; shift left
      $else
        LowData = PrintData & %00001111    ; mask MSBs
        HighData = PrintData >> 4          ; shift Right
      $endif
    
      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:
    
      $ifdef DataOnHighBits
        HighData = PrintData & %11110000   ; mask LSBs
        LowData = PrintData << 4           ; shift left
      $else
        LowData = PrintData & %00001111    ; mask MSBs
        HighData = PrintData >> 4          ; shift Right
      $endif
    
      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 display, 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
      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
    Last edited by towlerg; 27th August 2013 at 01:56. Reason: old and stupid

  • 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
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    558
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    George,

    I've now had the chance to test your new version of the code with my hardware. The code works well with one tiny exception. On my board bit 7 has to be 0 in order for the backlight to be turned on! Also because I'm using a 16F648 for testing I've changed the HBusOut to BusOut as suggested in a previous post.

    Thanks for putting so much effort into this George. It's saved me, and I'm sure many others, quite a bit of work.

    For reference the board I'm using is shown below



    Regards,

    Bob
    Attached Thumbnails Attached Thumbnails 12-18.jpg‎  
    Last edited by Mellbreak; 28th August 2013 at 17:54.

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

  • #14
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Hi,

    this post is just to inform that I have downloaded the code, compiled with relase 3.5.6.7. Load the FW the into the 18F4550 at 20Mhz and all is running correctly.

    Greath works.Thanks!

    This is the image of my hardware and of the i2c adapter.

    Click image for larger version

Name:	foto 1.JPG
Views:	63
Size:	39.4 KB
ID:	2189
    Click image for larger version

Name:	foto 2.JPG
Views:	47
Size:	51.1 KB
ID:	2190

    Ciao

    Leo

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

  • #15
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,240
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Replace the PRINT command to use I2C backpack on 1602 LCD

    Thanks for the kind words, coincidentally I looked at the example recently and realized that it was pretty clunky and not easy to use, so I rehashed to code, with all the I2C bits in an include (which you need to edit to suit your hardware, but of course only once).

    Anyone looking to amend/add command to basic would be advised to see my comment re. Proton_Reversed_Print.zip


    I2CPrintCommand_Demo.bas -
    Code:
    '*****************************************************************************************************************
    '*  Name    : I2CPrintCommand_Demo.bas                                                                           *
    '*  Purpose : Demonstrate the replacement Print routine For I2C backback On std alpha LCD                        * 
    '*  Author  : George Towler                                                                                      *
    '*  Notice  : I claim no copyright but maybe Barak does                                                          *
    '*  Date    : 29/06/2014                                                                                         *
    '*  Version : 0.2.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.2.0 - "working" parts of program removed to include file 
    
      Device = 18F4550
    
      Declare Create_Coff = On      ; for Proteus 8
      Xtal = 48
      All_Digital = True
    
      ' Setup the LCD. These must be included in the program
      ' Note! I2C is generated by MSSP so SDA\SCL pins are fixed for each PIC 
    
      ' Define I2C bus ports
      Declare SDA_Pin = PORTB.0 
      Declare SCL_Pin = PORTB.1 
      Declare Slow_Bus On
      Declare Hbus_Bitrate 100
    
      ' Define PRINT paramaters
      Declare LCD_Interface = 4
      Declare LCD_Lines = 2
      Declare LCD_Type = Alphanumeric
      Declare LCD_CommandUs = 2000
      Declare LCD_DataUs = 50
    
      Include "I2CPrintCommand.inc"
    
      Dim wLoop As Word = 0
    
    '------------------------------------------------------------------------------------------------
    Main:
      DelayMS 30                              ' Wait for the LCD to initialise
    
      Cls
      While
        Print At 1,1,Dec wLoop, "the quick brown"
        Inc wLoop
        DelayMS 100
      Wend
    
    
      Config_Start
        PLLDIV = 5            ;Divide by 5 (20 MHz oscillator input)
        CPUDIV = OSC1_PLL2    ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
        USBDIV = 2            ;USB clock source comes from the 96 MHz PLL divided by 2
        FOSC = HSPLL_HS       ;HS oscillator, PLL enabled (HSPLL)
        FCMEN = OFF           ;Fail-Safe Clock Monitor disabled
        IESO = OFF            ;Oscillator Switchover mode disabled
        PWRT = On             ;PWRT enabled
        BOR = On              ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
        BORV = 3              ;Minimum setting
        VREGEN = OFF          ;USB voltage regulator disabled
        WDT = OFF             ;WDT disabled (control is placed on the SWDTEN bit)
        WDTPS = 32768         ;1:32768
        CCP2MX = OFF          ;CCP2 input/output is multiplexed with RB3
        PBADEN = OFF          ;PORTB<4:0> pins are configured as digital I/O on Reset
        LPT1OSC = OFF         ;Timer1 configured for higher power operation
        MCLRE = On            ;MCLR pin enabled; RE3 input pin disabled
        STVREN = On           ;Stack full/underflow will cause Reset
        LVP = OFF             ;Single-Supply ICSP disabled
        ICPRT = OFF           ;ICPORT disabled
        XINST = OFF           ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        Debug = OFF           ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
        Cp0 = OFF             ;Block 0 (000800-001FFFh) is not code-protected
        CP1 = OFF             ;Block 1 (002000-003FFFh) is not code-protected
        CP2 = OFF             ;Block 2 (004000-005FFFh) is not code-protected
        CP3 = OFF             ;Block 3 (006000-007FFFh) is not code-protected
        CPB = OFF             ;Boot block (000000-0007FFh) is not code-protected
        CPD = OFF             ;Data EEPROM is not code-protected
        WRT0 = OFF            ;Block 0 (000800-001FFFh) is not write-protected
        WRT1 = OFF            ;Block 1 (002000-003FFFh) is not write-protected
        WRT2 = OFF            ;Block 2 (004000-005FFFh) is not write-protected
        WRT3 = OFF            ;Block 3 (006000-007FFFh) is not write-protected
        WRTC = OFF            ;Configuration registers (300000-3000FFh) are not write-protected
        WRTB = OFF            ;Boot block (000000-0007FFh) is not write-protected
        WRTD = OFF            ;Data EEPROM is not write-protected
        EBTR0 = OFF           ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
        EBTR1 = OFF           ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
        EBTR2 = OFF           ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
        EBTR3 = OFF           ;Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
        EBTRB = OFF           ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
      Config_End

    I2CPrintCommand.Inc -
    Code:
    '*****************************************************************************************************************
    '*  Name    : I2CPrintCommand.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    : 29/06/2014                                                                                         *
    '*  Version : 0.2.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.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    = $0E         ' PCF8574 Slave Address 0,1,0,0,A2,A1,A0,RW  where W=0           *
      Symbol I2CPrint_InitForLCDLines = $28         ' $28 for two lines                                              *
      Symbol I2CPrint_LCD_RS          = %00000001   '                                                                *
      Symbol I2CPrint_LCD_RW          = %00000010   '                                                                *
      Symbol I2CPrint_LCD_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_LCD_RS         = %01000000
      ;  Symbol I2CPrint_LCD_RW         = %00100000
      ;  Symbol I2CPrint_LCD_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_BackLight_RS   = I2CPrint_BackLight | I2CPrint_LCD_RS
      Symbol I2CPrint_BackLight_E    = I2CPrint_BackLight | I2CPrint_LCD_E
      Symbol I2CPrint_BackLight_RS_E = I2CPrint_BackLight | I2CPrint_LCD_RS | I2CPrint_LCD_E
      Symbol I2CPrint_Control        = %01000000                         
      Symbol I2CPrint_Address        = I2CPrint_Control + I2CPrint_Part_address
    
      $ifdef I2CPrint_DataOnHighBits
        Symbol I2CPrint_Init1          = %00110000 | I2CPrint_BackLight 
        Symbol I2CPrint_Init1_E        = %00110000 | I2CPrint_BackLight | I2CPrint_LCD_E
        Symbol I2CPrint_Init2          = %00110000 | I2CPrint_BackLight 
        Symbol I2CPrint_Init2_E        = %00110000 | I2CPrint_BackLight | I2CPrint_LCD_E
        Symbol I2CPrint_Init3          = %00100000 | I2CPrint_BackLight 
        Symbol I2CPrint_Init3_E        = %00100000 | I2CPrint_BackLight | I2CPrint_LCD_E
      $else
        Symbol I2CPrint_Init1          = %00000011 | I2CPrint_BackLight 
        Symbol I2CPrint_Init1_E        = %00000011 | I2CPrint_BackLight | I2CPrint_LCD_E
        Symbol I2CPrint_Init2          = %00000011 | I2CPrint_BackLight 
        Symbol I2CPrint_Init2_E        = %00000011 | I2CPrint_BackLight | I2CPrint_LCD_E
        Symbol I2CPrint_Init3          = %00000010 | I2CPrint_BackLight 
        Symbol I2CPrint_Init3_E        = %00000010 | I2CPrint_BackLight | I2CPrint_LCD_E
      $endif
    
      Dim BPF As Byte System
      Symbol I2CPrint_tComOrData = BPF.0
      Symbol I2CPrint_tInitialised = BPF.1  
    
      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  
    
      GoTo I2CPrintCommand_End
      @Print                                              ; assembler Print redirect
      Wreg_Byte I2CPrint_PrintData                        ; load LCDByte to W Register
    
    
      If I2CPrint_tInitialised = 0 Then                   ; Has LCD been inititalised?
        HBusOut I2CPrint_Address, [I2CPrint_Init1_E]      ; E hi and send command nibble 0011 (3)    
        HBusOut I2CPrint_Address, [I2CPrint_Init1]        ; E lo     
        DelayMS 20
        HBusOut I2CPrint_Address, [I2CPrint_Init2_E]      ; E hi and send command nibble 0011 (3)    
        HBusOut I2CPrint_Address, [I2CPrint_Init2]        ; E lo     
        DelayMS 20
        HBusOut I2CPrint_Address, [I2CPrint_Init3_E]      ; E hi and send command nibble 0010 (2)    
        HBusOut 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
    
      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
          GoSub I2CPrint_SendControl
        Else
          GoSub I2CPrint_SendData
        EndIf
        I2CPrint_RSFlag = 1                               ; set the flag so the next byte will be send as Data
      EndIf                                     
      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_BackLight_RS_E | I2CPrint_HighData    ; data and e hi
      HBusOut I2CPrint_Address, [I2CPrint_dummy]             
      I2CPrint_dummy = I2CPrint_BackLight_RS | I2CPrint_HighData      ; data and e lo
      HBusOut I2CPrint_Address, [I2CPrint_dummy]              
      HBusOut I2CPrint_Address, [I2CPrint_BackLight_RS]               ; Delay, Backlight and RS on throughout
      I2CPrint_dummy = I2CPrint_BackLight_RS_E | I2CPrint_LowData     ; data and e hi
      HBusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_BackLight_RS | I2CPrint_LowData       ; data and e lo
      HBusOut 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_BackLight_E | I2CPrint_HighData       ; data and e hi
      HBusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_BackLight | I2CPrint_HighData         ; data and e lo
      HBusOut I2CPrint_Address, [I2CPrint_dummy]              
      HBusOut I2CPrint_Address, [I2CPrint_BackLight]                  ; Delay, Backlight on throughout
      I2CPrint_dummy = I2CPrint_BackLight_E | I2CPrint_LowData        ; data and e hi
      HBusOut I2CPrint_Address, [I2CPrint_dummy]              
      I2CPrint_dummy = I2CPrint_BackLight | I2CPrint_LowData          ; data and e lo
      HBusOut I2CPrint_Address, [I2CPrint_dummy]         
      DelayMS 20
      Return
    
    I2CPrintCommand_End:
    Last edited by towlerg; 2nd July 2014 at 17:51.

  • 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. I2C Lcd Print & Owrite
      By pic-ignorant in forum The Lounge
      Replies: 1
      Last Post: 5th June 2017, 17:35
    2. Replies: 20
      Last Post: 15th August 2015, 16:13
    3. “Print” command for SPI Alfa numeric LCD?
      By barak in forum LCD module
      Replies: 16
      Last Post: 9th February 2011, 11:43
    4. Print command LCD alpha BUG
      By Flying Canuck in forum Proton Plus Compiler v3
      Replies: 26
      Last Post: 26th March 2010, 03:21
    5. [SOLVED !] LCD Print command and display justification
      By Sparky1039 in forum Proton Plus Compiler v3
      Replies: 3
      Last Post: 16th July 2007, 22:24

    Members who have read this thread : 107

    Actions :  (Set Date)

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

    Tags for this Thread

    Posting Permissions

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