Connect with us

I2C LCD help

Discussion in 'Microcontrollers, Programming and IoT' started by boots_n_braces, Mar 4, 2012.

Scroll to continue with content
  1. boots_n_braces

    boots_n_braces

    16
    0
    Feb 24, 2012
    Evening all, i wonder if anyone can help im having my first play with some I2C lcds for a new project and im struggling a bit. The I2C routines are in software (pic16f90) which ive never done before and ive not had the joy of using a serial lcd before either so im having lots of fun and games:D

    The main source of concern is the datasheet (probably cant see the wood for the trees)

    my routine goes ;

    transmit start bit
    transmit 7 bit address plus R/W bit making a full word

    then i get confused:D the next word consists of control bit, data or instruction bit and then a 6bit control byte! Im not sure were this 6 bit control byte is coming from however as every instruction etc in the data sheet is 8bits?!?!
    Can anyone clarify the transmission pattern i should be using or just lend me a shoulder to sob onto?:D:confused:
    Data sheet found here http://www.farnell.com/datasheets/1485486.pdf
    Thanks in advance

    Harry
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    10,220
    2,201
    Nov 17, 2011
    It looks like the important bit (apart from the CO bit) in the control word is the RS bit defining whether you are going to write an instruction (RS=L) or a data byte (RS=H). The other bits are described on page 22ff. of the data sheet.
    If you look closely,
    the 8 bits in the tables are actually 10 bits and include RS and R/W as described on page 14 of the data sheet.

    Harald
     
    Last edited: Mar 5, 2012
  3. boots_n_braces

    boots_n_braces

    16
    0
    Feb 24, 2012
    I found the original source of confusion after reading the data sheet for the 300th time lol! My code is below at its current state (please ignore the poor layout its been chopped and changed a lot trying to get this lcd working! Id appreciate anyone pointing out blindingly obvious errors as its my first I2c attempt im sure there will be plenty:D

    The programs run on a p16f690 using portc c pin 0 and 1 as clock and data respectivley. data to be transmitted is moved to file transmitme were subroutine transmit takes care of transmitting individual bits. As a side question is there anyway to slow down the program running in mplab so i can watch it execute step by step and see if it hangs up anywere?
    Thanks
    harry



    GENVAR UDATA
    count res 1
    transmitme res 1
    countd res 1
    count2 res 1

    reset code 0x0000
    banksel MAIN
    goto MAIN

    MAIN
    BANKSEL TRISC
    MOVLW B'00000011'
    MOVWF TRISC
    BANKSEL PORTC
    CLRF PORTC
    BANKSEL ANSEL
    movlw b'00000000'
    movwf ANSEL

    CALL delay
    CALL start ;start bit ;
    CALL adres ;address + write bit;
    CALL delay1
    MOVLW B'00000000' ;control bit, only data to follow until stop bit;
    MOVWF transmitme
    MOVLW B'00001000'
    MOVWF count
    CALL transmit

    MOVLW B'00111000' ;parameter
    MOVWF transmitme
    movlw B'00001000'
    movwf count
    CALL transmit

    movlw b'00111001' ;parameter
    movwf transmitme
    movlw b'00001000'
    movwf count
    call transmit

    movlw b'01010000' ;parameter
    movwf transmitme
    movlw b'00001000'
    movwf count
    call transmit

    movlw b'00001100' ;parameter
    movwf transmitme
    movlw b'00001000'
    movwf count
    call transmit

    movlw b'00001000' ;parameter
    movwf count
    movlw b'00010100'
    movwf transmitme
    call transmit

    movlw b'00001000' ;parameter
    movwf count
    movlw b'01111001'
    movwf transmitme
    call transmit

    movlw b'00001000' ; parameter
    movwf count
    movlw b'01101100'
    movwf transmitme
    call transmit

    movlw b'00001000' ;parameter
    movwf count
    movlw b'00000001'
    movwf transmitme
    call transmit

    call stop
    call delay1
    call start
    call adres
    movlw b'01000000'
    movwf transmitme
    movlw b'00001000'
    movwf count
    call transmit

    capp movlw b'00000101' ;transmit screen data capital P
    movwf transmitme
    movlw b'00001000'
    movwf count
    call transmitme
    call stop
    nop
    goto $-1


    transmit
    RLF transmitme
    BTFSS STATUS,0
    GOTO zero
    GOTO one
    CALL delay1
    RETURN

    zero
    CALL lowd
    CALL clkp
    DECFSZ count
    GOTO transmit
    return

    one
    CALL highd
    CALL clkp
    DECFSZ count
    GOTO transmit
    return
    clkp
    BANKSEL PORTC
    BCF PORTC,0
    BANKSEL TRISC
    BCF TRISC,1
    BANKSEL delay
    CALL delay
    BANKSEL TRISC
    BSF TRISC,0
    BANKSEL delay
    CALL delay
    RETURN



    lowd
    BANKSEL PORTC
    BCF PORTC,1
    BANKSEL TRISC
    BCF TRISC,1
    BANKSEL delay
    CALL delay
    RETURN

    highd
    BANKSEL TRISC
    BSF TRISC,1
    BANKSEL delay
    CALL delay
    RETURN

    lowc
    BANKSEL PORTC;
    BCF PORTC,0;
    BANKSEL TRISC;
    BCF TRISC,1;
    BANKSEL delay;
    CALL delay;
    RETURN;

    highc
    BANKSEL TRISC
    BSF TRISC,0
    BANKSEL delay
    CALL delay
    RETURN

    delay
    BANKSEL countd
    MOVLW B'00001100'
    MOVWF countd
    dly1 DECFSZ countd
    GOTO dly1
    RETURN

    delay1
    banksel countd
    movlw b'11111111'
    movwf countd
    banksel count2
    movlw b'11111111'
    movwf count2
    dlylo decfsz countd
    goto dlylo
    decfsz count2
    goto dlylo
    return

    adres
    CALL lowd
    CALL clkp
    CALL highd
    CALL clkp
    CALL highd
    CALL clkp
    CALL highd
    CALL clkp
    CALL highd
    CALL clkp
    CALL highd
    CALL clkp
    CALL lowd
    CALL clkp
    CALL lowd
    CALL clkp
    RETURN

    start
    CALL highd
    CALL highc
    call delay
    CALL lowd
    call delay
    call lowc
    RETURN

    stop
    call lowd
    call highc
    call delay
    call highd
    call delay
    call lowc
    RETURN
     
  4. Balrock

    Balrock

    39
    0
    Mar 1, 2012
    This is not of direct help Harry but I wondered if you had seen this. . . .

    Why pay for Serial LCDs when you can make your own?
    http://embedded-lab.com/blog/?p=30

    I just found it interesting and worth a share.

    Paul
     
  5. boots_n_braces

    boots_n_braces

    16
    0
    Feb 24, 2012
    Cheers balrock thats provoked a few ideas for some other parrallel components ive got! unfortunatley i get the lcds through work for errrm well nothing:) so i cant beat the price on them lol just wish i could get it to work haha
     
  6. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    If you liked that, you'll love this.

    It's ripe for improvement to make it more time efficient (adding diodes across the resistors) and perhaps even using an inverter to latch on a long logic high you could get all 8 bits.
     
  7. Balrock

    Balrock

    39
    0
    Mar 1, 2012
    Thanks Steve

    I remember coming across Romans Site in November. I emailed him to say thanks for sharing all the work he was doing. That seems like ages ago. I was a bit surprised that I even understand some of it this visit! Nice to know that I am heading in the right direction at least :D
     
  8. boots_n_braces

    boots_n_braces

    16
    0
    Feb 24, 2012
    quick update post c&p'd from another forum i asked on


    Hi all, thanks for the help so far always amazes me how much people will chip in to help strangers!

    After looooads of headbanging and rewriting ive cleared the original problems that were code related! the new clean code is below, it still doesnt work But it does debug properly so at least now i know the code is correct and its just the interfacing thats the problem! i think the first thing to play with is the delay lengths ive heard of people finding software I2C runs to fast for the slave to recognise it so il try slowing processor frequency and see what happens then! I suppose i should run through the lcd initialise parameters and check the cursor direction etc are correct aswell incase im erasing what im writing etc!



    list p=16f690
    include <p16f690.inc>
    GENVAR UDATA
    count res 1
    out res 1
    rcount res 1

    reset code 0x0000
    banksel MAIN
    goto MAIN
    MAIN
    BANKSEL TRISC
    MOVLW B'00000011'
    MOVWF TRISC
    BANKSEL PORTC
    CLRF PORTC
    BANKSEL ANSEL
    movlw b'00000000'
    movwf ANSEL

    CALL start
    CALL address ;address + write bit;
    MOVLW B'00000000' ;control bit, only data to follow until stop bit;
    MOVWF out
    CALL transmit

    MOVLW B'00111000' ;parameter
    MOVWF out
    CALL transmit

    movlw b'00111001' ;parameter
    movwf out
    call transmit

    movlw b'01010000' ;parameter
    movwf out
    call transmit

    movlw b'00001100' ;parameter
    movwf out
    call transmit

    movlw b'00010100'
    movwf out
    call transmit

    movlw b'01111001'
    movwf out
    call transmit

    movlw b'01101100'
    movwf out
    call transmit

    movlw b'00000001'
    movwf out
    call transmit

    call stop
    cappp call start
    call address
    movlw b'01000000'
    movwf out
    call transmit

    capp movlw b'00000101' ;transmit screen data capital P
    movwf out
    Call transmit
    movlw b'00000101'
    movwf out
    call transmit
    call stop
    goto cappp


    transmit
    movlw b'00001000'
    movwf rcount
    sendout rlf out
    btfss STATUS,0
    goto zero
    goto one
    RETURN

    one
    banksel TRISC
    bsf TRISC,1
    MOVLW B'11111111'
    MOVWF count
    DELAY3 DECFSZ count
    GOTO DELAY3
    DECFSZ rcount
    GOTO sendout
    RETURN

    zero
    banksel PORTC
    BCF PORTC,1
    BANKSEL TRISC
    BCF TRISC,1
    MOVLW B'11111111'
    MOVWF count
    DELAY4 DECFSZ count
    GOTO DELAY4
    DECFSZ rcount
    GOTO sendout
    RETURN
    address
    MOVLW B'01111100'
    MOVWF out
    CALL transmit
    RETURN
    stop
    BANKSEL PORTC
    BCF PORTC,1
    BANKSEL TRISC
    BCF TRISC,1
    BSF TRISC,0
    MOVLW B'11111111'
    MOVWF count
    delay5 decfsz count
    goto delay5
    banksel TRISC
    BSF TRISC,1
    MOVLW B'11111111'
    MOVWF count
    delay6 decfsz count
    goto delay6
    banksel PORTC
    BCF PORTC,0
    BANKSEL TRISC
    BCF TRISC,0
    RETURN

    start
    BANKSEL TRISC
    BSF TRISC,1
    BSF TRISC,0
    MOVLW B'11111111'
    MOVWF count
    delay7 decfsz count
    goto delay7
    banksel PORTC
    BCF PORTC,1
    BANKSEL TRISC
    BCF TRISC,1
    MOVLW B'11111111'
    MOVWF count
    delay8 decfsz count
    goto delay8
    banksel PORTC
    BCF PORTC,0
    BANKSEL TRISC
    BCF TRISC,0
    RETURN
     
  9. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    If things are going too fast, you might be able to put delays in your transmit routine.

    Check the specs for the appropriate timings and try to emulate them as closely as possible. At the moment it seems you're bit banging as fast as the processor can go which may well be far too fast.
     
  10. Balrock

    Balrock

    39
    0
    Mar 1, 2012
    Keep on it Harry. I'm sure you will crack it. Communicating with a new device from scratch via I2C must be on a lot of peoples wish list.

    Thanks for updating us.
     
  11. boots_n_braces

    boots_n_braces

    16
    0
    Feb 24, 2012
    just a quick final thank you and update, after lots more weird and wonderful issues and a lack of manufacturer support i purchased an i2c model from another company (although interestingly uses the same lcd drive as the original model. The code required 5 mins of tweaking and i had a display:D Just goes to show its to easy to doubt yourself and not the buffoons supplying you!

    Thanks for the help guys and giving up a bit of your time!

    Harry
     
  12. Balrock

    Balrock

    39
    0
    Mar 1, 2012
    Great news Harry. I knew you would crack it !
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-