LCD2041 with PIC16F876A and I2C (PicBasic Pro)
LCD2041 with PIC16F876A and I2C (PicBasic Pro)
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
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
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?
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.
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
Design and Development
Matrix Orbital
This works on a 4 MHz clock-- "Jim" -- but on a 20MHz clock I get accented o's...
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.)
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
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.
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
Design and Development
Matrix Orbital