Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Oshon Software I2C LCD Coding

Status
Not open for further replies.

Dave Phillips

New Member
Hello. I am using the Oshon PIC simulator IDE and trying to write to a 1602 (16x2 line) Liquid Crystal Display. The interface is via an I2C 4-wire connection. The command that I trying to use looks like I2CWrite sda, scl, 0x4e, addr, data (where 0x4e is the I2C address). I just can't get it to work. Could anybody help me please? All I need is an an example of how to write 0 to the first character of the first row and I can take it from there. Many thanks
 
Have you the LCD datasheet or the part number???

When these companies give you an address it's a 7 bit address... So reading is 0x4e shifted left 1 plus one and writing is ox4e shifted left 1..

address = 0x9d to read
address = 0x9c to write
 
Okay... A bit of research done... The I2C chip is a PCF8574 Address is normally 0x27 so shift left 1 = 0x4E.. so you are correct.. Sorry but I need all the information...

Now... It is a serial shift register so you will need to write a few routines as it's not quite so straight forward..

Is this the circuit on the back of the LCD

upload_2018-4-7_17-30-21.png

You will need to write several times to get it initialised and a few more to write to the screen..
 
Thank you again Ian. Unfortunately the circuit is not as you have shown it. There is a lot of documentation and code for where the PIC is connected directly via the data lines to the LCD. Unfortunately, I'm trying to avoid all the wiring by using the I2C interface. This connects to the LCD panel and has a 4-wire connection to the PIC (SDA, SCL, GND and VCC). The simplicity of the wiring is negated by the complexity of the coding I suspect!
 
Here's a short program..

Outputs Hello world!! on the top line.
Code:
Define CONFIG = 0x3f71
Define CLOCK_FREQUENCY = 4
Dim addr As Word  'variable for storing EEPROM byte address
Dim data As Byte  'variable for storing EEPROM byte data
Dim bl As Byte
Symbol sda = PORTC.4  'nickname for SDA pin
Symbol scl = PORTC.3  'nickname for SCL pin
bl = 0x80
Call i2clcdbegin()
Call printstr()

End                                              
Proc printstr()
Dim x As Byte
Dim ch As Byte
 For x = 0 To 10
  ch = LookUp("Hello world!"), x
  Call datawrite(ch)
 Next x
 
End Proc                                        
Proc i2clcdbegin()
 WaitMs 15
 Call cmdwrite(0x33)
 WaitMs 5
 Call cmdwrite(0x32)
 WaitMs 5
 Call cmdwrite(0x2c)
 WaitMs 1
 Call cmdwrite(0xc)
 WaitMs 1
 Call cmdwrite(0x6)
 WaitMs 1
 Call cmdwrite(0x1)
End Proc                                        
Proc datawrite(data As Byte)
 Dim hi As Byte
 Dim lo As Byte
 hi = ShiftRight(data, 4)
 hi = hi And 0xf
 lo = data And 0xf
 data = hi + bl + 0x10
 I2CWrite sda, scl, 0x4e, data, data
 data = data + 0x40
 I2CWrite sda, scl, 0x4e, data, data
 data = data - 0x40
 I2CWrite sda, scl, 0x4e, data, data
 WaitMs 1
 data = lo + bl + 0x10
 I2CWrite sda, scl, 0x4e, data, data
 data = data + 0x40
 I2CWrite sda, scl, 0x4e, data, data
 data = data - 0x40
 I2CWrite sda, scl, 0x4e, data, data
End Proc                                        
Proc cmdwrite(cmd As Byte)
 Dim hi As Byte
 Dim lo As Byte
 hi = ShiftRight(cmd, 4)
 hi = hi And 0xf
 lo = cmd And 0xf
 cmd = hi + bl
 I2CWrite sda, scl, 0x4e, cmd, cmd
 cmd = cmd + 0x40
 I2CWrite sda, scl, 0x4e, cmd, cmd
 cmd = cmd - 0x40
 I2CWrite sda, scl, 0x4e, cmd, cmd
 WaitMs 1
 cmd = lo + bl
 I2CWrite sda, scl, 0x4e, cmd, cmd
 cmd = cmd + 0x40
 I2CWrite sda, scl, 0x4e, cmd, cmd
 cmd = cmd - 0x40
 I2CWrite sda, scl, 0x4e, cmd, cmd
End Proc

bl = back light.... data has a 0x10 added to set RS and the 0x40 is the enable on / off
 
Ian. You are a kind man - and a genious! Thank you so much for taking the time to sort my problem. I am most grateful.

David
 
Hello again Ian (I hope that you are there).

Sorry about the genious typo - it should of course had been genius!

I’ve tried the code out now and LCD flashes but no text is displayed. I suspect that it is a case of ‘so close but so far’. Do you have any other thoughts please?

Thank you

David
 
Do me a snapshot of the backpack so I can see how it's connected..

There are one or two different types.... As your I2C address was 0x4E I just assumed PCF8574... The circuit above is the normal connection!!
 
Hi Ian. In actual fact I am making use of a PIC board previously connected to a RTC so I know that the board itself works. It uses a 16F876A (old technology I know!) which has a 4MHz crystal. Although you assumed a different processor the connections are actually the same. RC4 (pin 15) connected to SDA and RC3 (pin 14) connected to SCL on the I2C interface on the Liquid Crystal Display.

David
 
Hey guys.
Dave, ignore the fact that this is on an arduino, I believe Ian wants to pin down the exact hardware you are using.
Are you using something like the LCD & backpack shown in the link below, perhaps soldered together already, or are you using something else?
**broken link removed**

Regards.

EDIT: a pic would be most useful if you can upload one.
EDIT2: If this is the backpack, there are 6 solder blobs above A0 A1 A2 beneath the blue pot - are any bridged?
 
Last edited:
Another possibility is whether a PCF8574 is used, or a PCF8574A:
PCF8574.png

PCF8574A.png
 
Hi Ian.

Thanks for the ongoing help and sorry for the confusion.

The chip on the I2C interface card is a TLPCF8574T as you thought. A photo is attached.

I have noticed that in your circuit diagram you have pull-up resistors on the SDA and SCL lines from the PIC. I don’t have them so do you think that could be the problem?

David
 

Attachments

  • image.jpg
    image.jpg
    1 MB · Views: 251
New program for new circuit
Code:
Define CONFIG = 0x3f71
Define CLOCK_FREQUENCY = 4
Dim addr As Word  'variable for storing EEPROM byte address
Dim data As Byte  'variable for storing EEPROM byte data
Dim bl As Byte
Dim rs As Byte
Symbol sda = PORTC.4  'nickname for SDA pin
Symbol scl = PORTC.3  'nickname for SCL pin
bl = 0x8
rs = 0x1
Call i2clcdbegin()
Call printstr()
Call cmdwrite(0xc0)
Call printstr2()
End                                             
Proc printstr()
Dim x As Byte
Dim ch As Byte
For x = 0 To 16
ch = LookUp(" Hello world!!  "), x
Call datawrite(ch)
Next x

End Proc                                       

Proc printstr2()
Dim x As Byte
Dim ch As Byte
For x = 0 To 16
ch = LookUp(" Dave Phillips "), x
Call datawrite(ch)
Next x

End Proc                                       
Proc i2clcdbegin()
WaitMs 15
Call cmdwrite(0x33)
WaitMs 5
Call cmdwrite(0x32)
WaitMs 5
Call cmdwrite(0x2c)
WaitMs 1
Call cmdwrite(0xc)
WaitMs 1
Call cmdwrite(0x6)
WaitMs 1
Call cmdwrite(0x1)
End Proc                                       

Proc datawrite(data As Byte)
Dim hi As Byte
Dim lo As Byte
lo = ShiftLeft(data, 4)
hi = data And 0xf0
lo = lo And 0xf0
data = hi + bl + rs
I2CWrite sda, scl, 0x4e, data, data
data = data + 0x4
I2CWrite sda, scl, 0x4e, data, data
data = data - 0x4
I2CWrite sda, scl, 0x4e, data, data
WaitMs 1
data = lo + bl + rs
I2CWrite sda, scl, 0x4e, data, data
data = data + 0x4
I2CWrite sda, scl, 0x4e, data, data
data = data - 0x4
I2CWrite sda, scl, 0x4e, data, data
End Proc                                       
Proc cmdwrite(cmd As Byte)
Dim hi As Byte
Dim lo As Byte
lo = ShiftLeft(cmd, 4)
hi = cmd And 0xf0
lo = lo And 0xf0
cmd = hi + bl
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd + 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd - 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
WaitMs 1
cmd = lo + bl
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd + 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
cmd = cmd - 0x4
I2CWrite sda, scl, 0x4e, cmd, cmd
 
Last edited:
Don't want to interfere but does not the I2CWrite command shift the 0x4E <<1 ?
No! Vladimir makes you do it manually.. I have tested my code and it works as it should.
I think Arduino platform does... I definitely know the .net framework shifts it as well..
 
Hi Ian. Alas I still can't get it to work with the new code. I've tried adding two 10K pull-up resistors and also a different LCD/I2C interface. All that happens is the display flashes for a fraction of a second and then the light goes out.

I'm taking up too much of your time now so I will not trouble you again. Thank you so much though for all your help.

Best wishes

David
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top