LCD2041 with PIC16F876A and I2C (PicBasic Pro)

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
jheiv
LCD!
Posts: 11
Joined: Mon Jul 24, 2006 9:56 am

LCD2041 with PIC16F876A and I2C (PicBasic Pro)

Post by jheiv »

I had a LCD running on a PIC16F876A with no problem when I used a 4MHz RC oscillator-- I needed a faster and more precise clock and switched to a 20MHz clock. The LCD no longer works with the 20MHz clock. I mean, it reads characters but nothing like what I input to it-- it seems to skip three out of four characters when put in a dumb loop to just ouput commands 0 through FF. I am using PicBasicPro compilier. Thanks

Raquel
Matrix Orbital
Matrix Orbital
Posts: 805
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

hi jheiv,

Thank you for posting on the forum.

Since you have increased the speed of your host, it might be necessary to put in some delays in your existing I2C code to compensate for the faster speed.
Raquel Malinis
Design and Development
Matrix Orbital

jheiv
LCD!
Posts: 11
Joined: Mon Jul 24, 2006 9:56 am

Post by jheiv »

Code: Select all

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : J.EDWARDS                                         *
'*  Date    : 7/24/2006                                         *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************

CLEAR

@ device PIC16F876A, hs_osc, wdt_off, pwrt_off, bod_off, lvp_on, cpd_off

DEFINE  OSC             20
DEFINE  I2C_SLOW        1

TRISA   = %11111111         'Sets   Tristate Registers, Port A (Inputs)
TRISB   = %00000000         'Clears Tristate Registers, Port B (Outputs)
TRISC   = %00000000         'Clears Tristate Registers, Port C (Outputs)

SCL     VAR     PORTC.3     'Red
SDA     VAR     PORTC.4     'Brown
LED     VAR     PORTC.2     'Diagnostic LED

LCD     VAR     BYTE
CONT    VAR     BYTE

i       var     byte
j       var     byte

startup:
    pause 900
    PORTC = %00000000
main:
  'DEFINE I2C VARS
    LCD     = $50               'Default Address of LCD
    CONT    = $FE               'Control Byte
    
    for i = 0 to 255           
      i2cwrite SDA, SCL, LCD, [i]
      pause 200
      next i
    
    END    
    goto main
This doesn't work... well it works... but prints out jarbled characters...

Its supposed to run through characters 00 - FF but insteads jumps about every 4 characters... for example the 3rd line after completing starts off: "aeimquy}" followed by accented u: a' e: i' ... etc etc.

This code (if i recall, I will verify later) worked. I inserted the pause 200 and the 900 as per your request and it didn't help. Any Ideas?

Raquel
Matrix Orbital
Matrix Orbital
Posts: 805
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi,

You might want to experiment with the timing delay some more.

Also, if you can limit your loop to sending ASCII printable characters for now so that you know what to expect (maybe from '!' to 'z') .

As you mentioned, it will be good to verify that the code runs properly when you put back the 4MHz clock.
Raquel Malinis
Design and Development
Matrix Orbital

jheiv
LCD!
Posts: 11
Joined: Mon Jul 24, 2006 9:56 am

Post by jheiv »

This works on a 4 MHz clock-- "Jim" -- but on a 20MHz clock I get accented o's...

Code: Select all

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : J.EDWARDS                                         *
'*  Date    : 7/24/2006                                         *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************

CLEAR

@ device PIC16F876A, hs_osc, wdt_off, pwrt_off, bod_off, lvp_on, cpd_off

DEFINE  OSC             8
DEFINE  I2C_SLOW        1

TRISA   = %11111111         'Sets   Tristate Registers, Port A (Inputs)
TRISB   = %00000000         'Clears Tristate Registers, Port B (Outputs)
TRISC   = %00000000         'Clears Tristate Registers, Port C (Outputs)

SCL     VAR     PORTC.3     'Red
SDA     VAR     PORTC.4     'Brown
LED     VAR     PORTC.2     'Diagnostic LED

LCD     VAR     BYTE
CONT    VAR     BYTE

i       var     byte
j       var     byte

startup:
    pause 900
    PORTC = %00000000
main:
  'DEFINE I2C VARS
    LCD     = $50               'Default Address of LCD
    CONT    = $FE               'Control Byte
    
      i2cwrite SDA, SCL, LCD, ["Jim"]
    
    END    
    goto main
It looks like just a timing issue-- does it sound right that the LCD would have problems with 20MHz speeds? Also the loop in ASCII characters skipped four also... and came up with incorrect characters (on the 4MHz clock, the loop also skipped four, but displayed the correct characters.)

Raquel
Matrix Orbital
Matrix Orbital
Posts: 805
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi,

Do you have a scope you can use to probe around the I2C lines? I want to know what is the frequency of your clock (SCL).

You also might want to add in delays in between the I2C transactions, so something like the 'pause 200' you had before.
Raquel Malinis
Design and Development
Matrix Orbital

jheiv
LCD!
Posts: 11
Joined: Mon Jul 24, 2006 9:56 am

Post by jheiv »

The scope reads anywhere from ~81kHz to ~89kHz and its full 5.04V pk-pk... even pauses of 1 sec are ignored.

Raquel
Matrix Orbital
Matrix Orbital
Posts: 805
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi,

Running the I2C at 80 to 90kHz should be fine. Are you saying that even having a pause of 1 sec, you still have 4th character dropped (in both the old and the new revs)? Then this might not be a timing issue. You might want to re-visit the I2C functions and see why this is so.
If instead of "Jim" you print out "Jimmy" I wonder if it will drop the 6th character.
Raquel Malinis
Design and Development
Matrix Orbital

Post Reply