I2C LCD 16x2 Pic16f628 Code


+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2025
    Posts
    3

    Default I2C LCD 16x2 Pic16f628 Code

    I2C LCD 16x2 Pic16f628 Code

    I have I2C attached to LCD 16x2 using Pic16f628, internal OSC 4Mhz, DSA on B.1, SLC on B.2, LED on B.5 for Blink at the end, there are 4.7k pull up resistors on the expansion board. I am not getting anything readable. The hardware verified with the Arduino uno "Nice display". I am looking for some simple code that gives something readable to be able to change around to study changes.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,699


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: I2C LCD 16x2 Pic16f628 Code

    Warning I'm not a teacher

  3. #3
    Join Date
    Dec 2025
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: I2C LCD 16x2 Pic16f628 Code

    I have gone through all those posts that I thought were remotely pertinent. I have tried all the code available in those posts. I have changed every variable possible that I know to try. I don’t understand the details of insertion of the code and variables but somewhat I think the concept. Do I need to learn C first or something else to figure this out? I have not posted any of my code because it has no viability. I have spent countless hours on this. Any information would be much appreciated.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,699


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: I2C LCD 16x2 Pic16f628 Code

    There a a few variants of backpack lcd's there are pcf8574 ones and pcf8574a ones. they have different i2c address' ranges.
    there are at least two differently wired versions also.
    there are also dfrobot lcds that look similar but are completely different.

    The hardware verified with the Arduino uno "Nice display"
    so what settings from arduino were used to get that result ?


    Do I need to learn C first or something else to figure this out?
    C has nothing to do with it , first step is know what the actual hardware is and its i2c address and how its configured


    I have not posted any of my code because it has no viability.
    so nobody has any idea of what you are trying and can not possibly see where you have gone wrong
    do post your best effort
    Warning I'm not a teacher

  5. #5
    Join Date
    Dec 2025
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: I2C LCD 16x2 Pic16f628 Code

    ''This is as far as I have got. I know it is not much. I am having great dificulty in breaking down
    '' the elements of the I2CWrite. I get a lit up display and that is all. Any help would be greatly ''appreciated.

    '************************************************* **********************
    '* Pic16f628 LCD I2C 01 260110 *
    '* Display output to LCD of Something Readable *
    '* Display lights Nothing else *
    '* *
    '* Internal Oscillator *
    '* *
    '************************************************* **********************
    #CONFIG
    cfg = _FOSC_INTOSCCLK ; INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
    ; _FOSC_ERCLK _ER_OSC_CLKOUT _FOSC_ERIO
    ; _ER_OSC_NOCLKOUT _FOSC_INTOSCCLK _INTRC_OSC_CLKOUT
    ; _FOSC_INTOSCIO _INTRC_OSC_NOCLKOUT _FOSC_ECIO
    ; _EXTCLK_OSC _FOSC_HS _HS_OSC _FOSC_XT
    ; _XT_OSC _FOSC_LP _LP_OSC
    cfg&= _WDT_ON ; WDT enabled (MUST USE CAPS)
    cfg&= _WDTE_OFF ; WDT disabled
    cfg&= _PWRTE_ON ; PWRT disabled (MUST USE CAPS)
    cfg&= _MCLRE_OFF ; RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD
    cfg&= _LVP_OFF ; RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming
    cfg&= _BOREN_OFF ; BOD Reset disabled
    cfg&= _CPD_OFF ; Data memory code protection off
    cfg&= _BODEN_OFF ; BOD Reset disabled
    cfg&= _CP_OFF ; Code protection off
    __CONFIG cfg
    #ENDCONFIG
    DEFINE OSC 4
    define I2C_SLOW 1
    DEFINE I2C_INTERNAL 1
    '#define I2C_SLOW 1 ' Not sure if it gets #
    '#DEFINE I2C_INTERNAL 1 ' Not sure if it gets #

    TrisB = 0
    SDA VAR PORTB.1 'SDA Pin#7 on Pic16f628
    SCL VAR PORTB.2 'SCL Pin#8 on Pic16f628
    Five var PORTB.5 'Pin#11 LED Output to indicate program is running
    Tim var byte ' Variable for Time
    Tim =500
    Tim2 var byte ' Variable for Time
    Tim2 =40

    Control Var byte
    Control = %10100000 'Page 157 PBP Control byte would be %10100000 or $A0
    Address var byte 'LCD address:With Arduino I2C Scan Program 39 Dec or 0x27 Hex
    Address = 39 'LCD address:With Arduino I2C Scan Program 39 Dec or 0x27 Hex

    Main:

    I2CWRITE SDA,SCL,Control,[$00,$01]'clear display
    pause Tim2
    I2CWRITE SDA,SCL,Control,[$00,$0C]'display on/off
    pause Tim2
    ' Don't know where the below $FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]
    ' are from they were copied from another program.
    I2CWRITE SDA,SCL,Control,[Address,$FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]' Hello
    pause Tim2

    low Five 'This is to see that the program is running It does Blink
    pause Tim
    high Five
    pause Tim
    low Five
    Goto Main
    END

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,699


    Did you find this post helpful? Yes | No

    Default Re: I2C LCD 16x2 Pic16f628 Code

    there are a number of issues here

    Code:
    #CONFIG
    ;cfg = _FOSC_INTOSCCLK ; INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN do you really need clockout on RA6
    cfg = _INTRC_OSC_NOCLKOUT        ;INTRC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
    ; _FOSC_ERCLK _ER_OSC_CLKOUT _FOSC_ERIO
    ; _ER_OSC_NOCLKOUT _FOSC_INTOSCCLK _INTRC_OSC_CLKOUT
    ; _FOSC_INTOSCIO _INTRC_OSC_NOCLKOUT _FOSC_ECIO
    ; _EXTCLK_OSC _FOSC_HS _HS_OSC _FOSC_XT
    ; _XT_OSC _FOSC_LP _LP_OSC
    cfg&= _WDT_ON ; WDT enabled (MUST USE CAPS)
    cfg&= _WDTE_OFF ; WDT disabled
    cfg&= _PWRTE_ON ; PWRT disabled (MUST USE CAPS)
    cfg&= _MCLRE_OFF ; RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD
    cfg&= _LVP_OFF ; RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming
    cfg&= _BOREN_OFF ; BOD Reset disabled
    cfg&= _CPD_OFF ; Data memory code protection off
    cfg&= _BODEN_OFF ; BOD Reset disabled
    cfg&= _CP_OFF ; Code protection off
    ;__CONFIG cfg    ;error not correct or needed
    #ENDCONFIG

    Code:
    DEFINE OSC 4
    ;define I2C_SLOW 1     not relevant
    ;DEFINE I2C_INTERNAL 1  incorrect
    '#define I2C_SLOW 1 ' Not sure if it gets #
    '#DEFINE I2C_INTERNAL 1 ' Not sure if it gets #
    
    
    TrisB = 0 ;   i2c pins should not be set as outputs
    SDA VAR PORTB.1 'SDA Pin#7 on Pic16f628
    SCL VAR PORTB.2 'SCL Pin#8 on Pic16f628
    Five var PORTB.5 'Pin#11 LED Output to indicate program is running
    ;Tim var byte ' Variable for Time   a byte cannot hold such a large number byte range 0 to 255
    Tim var word ' Variable for Time
    Tim =500
    Tim2 var byte ' Variable for Time
    Tim2 =40
    
    ;Control Var byte ;  the example in manual is for an eeprom , there is no eeprom here
    ;Control = 100000 'Page 157 PBP Control byte would be 100000 or $A0
    
    Address var byte 'LCD address:With Arduino I2C Scan Program 39 Dec or 0x27 Hex
    Address = 39 'LCD address:With Arduino I2C Scan Program 39 Dec or 0x27 Hex
    ; arduino i2c address is a 7 bit address pbp uses an 8 bit address 
    
    
    Address = Address <<1 ; convert to 8 bit
    
    
    
    I2CWRITE SDA,SCL,Address ,[$00,$01]'clear display
    pause Tim2
    I2CWRITE SDA,SCL,Address ,[$00,$0C]'display on/off
    pause Tim2
    ' Don't know where the below $FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]
    ' are from they were copied from another program. they come from the Darrel Taylor LCD_PCF8574A.pbp i2c lcd include file and are pointless here
    I2CWRITE SDA,SCL,Address ,[$FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]' Hello
    pause Tim2
    
    low Five 'This is to see that the program is running It does Blink at twice the expected rate due to incorrect var type
    pause Tim
    high Five
    pause Tim
    low Five
    Goto Main

    the lcd has not been initialized
    nor have you sent the lcd data in a nibblised format with correct strobe pulses being generated
    its much simpler to use the Darrel Taylor LCD_PCF8574A.pbp i2c lcd include

    there are plenty of example in the links given
    Warning I'm not a teacher

Similar Threads

  1. Pic16f616 with lcd 16x2 problem
    By juanen19 in forum mel PIC BASIC
    Replies: 7
    Last Post: - 29th August 2013, 19:20
  2. Lcd 16x2 circuit and sample program...
    By larzazral in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd July 2012, 12:21
  3. Interfacing 16x2 LCD to PIC18F2520
    By spotlite in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st January 2012, 09:29
  4. Sample code for I2C text LCD needed
    By Alexey in forum Code Examples
    Replies: 4
    Last Post: - 15th September 2011, 02:29
  5. swap lcd 16x2 with 20x2
    By kzeoprf in forum General
    Replies: 4
    Last Post: - 2nd September 2011, 17:25

Members who have read this thread : 6

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