Menu

Help with I2C LCD Display

Help
Fman
2014-09-30
2014-10-09
  • Fman

    Fman - 2014-09-30

    Hi all. I'm using a 16F74 at 2mhz with a rc oscillator. The plan is to connect and display using an I2C LED display. The 16F74 has the data pin at 23 (portc.4) , and the clock pin at 18 (portc.3).

    This is a close cousin of the display I got:

    http://www.ebay.ca/itm/Arduino-IIC-I2C-TWI-162-1602-16X2-Serial-Blue-LCD-Module-Display-Screen-/190573003243

    All info points to it being a HD44780 based device. The I2c interface connected to it has the following numbers: T313S06, and LCD1602 IIC V1

    Anyway, the unit powers up, I can adjust contrast and the backlit led on/off.

    I tried to send it data via the onboard SSP port. Every indication is that the diaplay is address 0x27. When that didn't work I tried to write code which would identify the address without much luck. The code is below.

    When I 'scoped the pins 18, 23, the clock pin is a solid high, and the data pin gives me two high to low transitions, then solid high again each time the subroutine is called.

    I have a set of 8 leds connected to portd and portb. PortD pins are used to display values, portb pins are used as check leds for debugging.

    The leds on portd count like they should, but the HI2CAckPollState test is never true or false, because the patterns I have selected never show up on portd.

    Any help is appreciated.

    chip 16f74, 2; chip is obvious, 2 is 2mhz internal rc oscillator, use c=100pf, r=10k pot. Adjust until rpm is correct

    config osc = rc_osc ;configure for external rc in this program

    ;pin in/outs

    Dir portc.4 in
    Dir portc.3 in ;pins must be defined as inputs to get the i2c pins working

    ;Define I2C Settings, note: the order of the instructions is extremely importanat!!!

    define HI2C_Mode Master ;we are going to output data to the display

    ;define data and clock pins

    define I2C_DATA portc.4

    define I2C_CLOCK portc.3

    define I2C_BIT_DELAY 20 us ;Unknown setting from help file

    define I2C_CLOCK_DELAY 30 us ;Unknown setting from help file

    define I2C_disable_interrupts on ;dont use interrupts I guess

    define LCD_IO 0 ;lcd setting for i2c

    define LCD_NO_RW ;lcd is not capable of reads

    ;------------------

    include <lowlevel\\hwspi.h>

    include <lowlevel\\hwi2c.h>

    include <lowlevel\\lcd.h>

    ;Varible definitions

    byte count ;couter for display change

    byte count1

    byte controlbyte

    ;______

    portb = 0xff ;turn on all leds on port b for a check
    portd = 0xff ;turn on all leds on port d for a check
    wait 5 s
    portb = 0x00
    portd = 0x00

    startmain:

                                                    ;adresses 0-7 and 120 to 127 are reserved
    

    count = 8
    count1 = count ;synchronize count1 and count

    for count = 8 to 119 ; do for all possible adresses

    portb.1 = on ;check led on

    gosub prn

    portb.1=off ;check led on when process complete

    count1 = count1+1 ;increment count1

    next

    wait 2 s

    goto startmain ;loop back to addres 8 when done

    end

    sub prn

    portb.2 = on ;check led on

    ControlByte = 0
    If LCD_RS = on Then Controlbyte.4 = on ;as per help file

    portd = count1 ;turn leds on to address we are testing
    wait 1 s ;

    HI2CStart ;Turn port on

    HI2CSend count1 ;Send address
    I2CSend Controlbyte ;set the mode of communications as per help file

    if HI2CAckPollState = true then
    portd = 0xaa ;turn on pattern 10101010
    end if

    if HI2CAckPollState = false then
    portd= 0xff ;turn on pattern 11111111
    end if

    HI2CStop ;
    portb.2 = off

    wait 2 s ;

    end sub

     
  • Fman

    Fman - 2014-09-30

    whoa, sorry about the crazy fonts, no idea how that happened.

    Chay

     
  • kent_twt4

    kent_twt4 - 2014-10-01

    SSP module is hardware Slave I2C mode only. You need to try with software I2C with this device. MSSP is the master/slave I2C module, like in the 16f877a device.

     
  • Fman

    Fman - 2014-10-01

    Thanks for the heads up. I'll try it in software mode and see what happens.

    Chay

     
  • David Stephenson

    I found communicating via I2C to an LCD difficult to set up basically because it is difficult to find (understandable) example code (preferable in Basic).
    Below is what I got to work on a Midas MCCOG21605 LCD display.

    ~~~~~~~

    chip 16F688,1

    config OSC=INTRC_OSC_NOCLKOUT, MCLRE=Off, WDT=on, boren=off

    'I2C settings

    define I2C_MODE Master

    define I2C_DATA PORTC.0

    define I2C_CLOCK PORTC.1

    SL=0x7C 'DISPLAY ID
    COMSEND=0x00 'display COMMAND send
    DS=0X40 'display DATA send

    'INITIALIZATION of the display (Midas MCCOG21605 LCD)
    'this is all in the datasheet

    WAIT 20 MS
    I2CStart
    I2CSEND(Sl)
    I2CSEND(Comsend)
    I2CSEND(0x34) 'initialize 16x2
    'i2csend(0x38) '16x1
    WAIT 30 US
    I2CSEND(COMSEND)
    I2CSEND(0x35)
    'i2csend(0x39)
    WAIT 30 US
    I2CSEND(0x14) 'osc
    WAIT 30 US
    I2CSEND(0x74) 'contrast
    WAIT 30 US
    I2CSEND(0x54) 'pwr
    WAIT 30 US
    I2CSEND(0x6F) 'follower
    WAIT 30 US
    I2CSEND(0x0C) 'on/off
    WAIT 30 US
    I2CSEND(0x01) 'clear
    WAIT 30 US
    I2Cstop
    'end of initialization

    'data to screen

    a1=3:a2=5:a3=7
    I2CStart
    I2CSEND(Sl) 'device ID
    I2CSEND(Comsend) 'Command mode
    i2csend(0x01) 'clear screen
    i2cstop
    I2CStart
    I2Csend(Sl) 'device ID
    I2Csend(DS) 'data send mode
    I2CSend (A1+48) 'send number 3
    I2CSend (A2+48) '5
    I2CSend (A3+48) '7
    I2CStop
    ~~~~

    I hope it is of help to somebody.

     
  • kent_twt4

    kent_twt4 - 2014-10-09

    Thanks for posting your code. I've always wanted to try an I2C lcd.

     
  • Fman

    Fman - 2014-10-09

    Yes thank you. I'll try it when I get the 8 pin code sorted for my application.

    Chay

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.