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.
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
No! don't give up, I'll help getting it working.... Two 10k are too large... You need 1k or 2k2.. I take it Vcc is 5v??
 
Here's the schematic I used..
Capture.png
 
Thank you so much Ian.

VCC is 5v.

I have now replaced the resistors with 1k pull-up's but no difference. With/without resistors it does look like the code is writing to the LCD. After the initial flash of the backlight it is possible to see (very dim of course) all 32 8x5 pixels on maximum contrast - but no message. In the previous version of the code (where you were only addressing one line) this was not the case.

David
 
Sounds like a jumper is missing from the backpack.. You should be able to go from extreme dim to extreme black.

I'm not sure the VCC to the back display is good... One thing I have noticed... There are no pullups on your display to A0 A1 and A2.. These should be high by default... If they are low there is a different address.. The original I2C backpack has these populated with 1k resistors.. ( Unless of course yours are pulled up internally )
 
Hello Ian (and thank you too for your suggestions granddad). Sorry for not getting back to you before but I've been trying to get to the bottom of the problem. I finally made a breakthrough yesterday (very slow learner!). There was an 'End Proc' missing from the cmdwrite procedure. Now the LCD is displaying the characters correctly. However, the backlight is still not on. I don't think that this is a jumper issue and hopefully it is only one of the setup codes.

Have a good day

David
 
There was an 'End Proc' missing from the cmdwrite procedure.
Sorry about that.... Copy and paste error!! Now I've done it all!!!

I have now adopted this display, so I have re-written in C using hardware I2C and it works extremely well..

See I even helped myself!!
 
And as a final post (just in case any Oshonsoft users ever need the solution) . . . .

The backlight works if rs = 0x9 and not 0x1

So all happy now and all thanks to Ian!
 
Hi Ian,
I read this post because I am also working on I2C. I try to read and understand this code.
What I don't fully understand is the piece you wrote in "Proc i2clcdbegin()"
Is it possible that you explain to me what you exactly are doing there?
Especially why you chose these HEX code values.
I assume this is meant for the position of the characters in the display.
I try to connect a 4 line display with this code.
 
Yes it works well with a 2x16 line display. But I try to use it with 4x16 display. And I assume that with a small change in this code it will work. But for my knowledge I try to understand the code.
 
No change to the Init() routine.... The address of each line changes. To swap to each line send the address first.

1st line = 0x80..
2nd line = 0x94..
3rd line = 0xC0..
4th line = 0xD4..

to write to the third line send;-
call cmdwrite(0xC0)

My code was extremely basic.. Here is an ( UNTESTED ) piece of code to change line..
Code:
proc LCDgoto_xy( int x, int y)
   Dim pos As Byte
   if x = 1 then pos = 0x80
   if x = 2 then pos = 0x94
   if x = 3 then pos = 0xC0
   if x = 4 then pos = 0xD4
   pos = pos + y
   call cmdwrite(pos)
end proc
 
I made the change but I don't get what I want.
I have adjusted the addresses but no correct representation. I see a lot of Chinese characters right now.
Below I just placed the code.
I try to decipher as much as possible because I want to learn from it. Some things are unclear such as
what is bl = 0x8 and rs = 0x1 meant for?

Code:
Dim data As Byte  'variable for storing EEPROM byte data
Dim bl As Byte
Dim rs As Byte

bl = 0x8
rs = 0x1

main:  'endless loop

Call i2clcdbegin()
Call printstr1()
Call cmdwrite(0x80)
Call printstr2()
Call cmdwrite(0x94)
Call printstr3()
Call cmdwrite(0xc0)
Call printstr4()
Call cmdwrite(0xd4)

End  'end program                                 

Proc printstr1()
    Dim x As Byte
    Dim ch As Byte
        For x = 0 To 16
            ch = LookUp("Line-1 Test     "), 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("Line-2 Test     "), x
            Call datawrite(ch)
        Next x
End Proc                                         

Proc printstr3()
    Dim x As Byte
    Dim ch As Byte
        For x = 0 To 16
            ch = LookUp("Line-3 Test     "), x
            Call datawrite(ch)
        Next x
End Proc                                         

Proc printstr4()
    Dim x As Byte
    Dim ch As Byte
        For x = 0 To 16
            ch = LookUp("Line-4 Test     "), 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  '0xf0 was orgineel
        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
End Proc
 
BL is the backlight and RS is register select.. This is a serial backpack so all commands are sent serially.

Also.. I never had one of these backpacks although I could simulate it...

I'll try and find this on my computer and see if you code is working.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top