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.
I now understand that this is for backlighting etc ..
This is a Midas display. Hereby the link to the datasheet.
MC41605B6W-SPTLY-V2
Just for clarity this is what I see on the screen.
With the previously sent code.

IMG_20191027_155558.jpg
 
You missed the pin definitions at the beginning.. Also the 16 x 4 has slightly different addresses..

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
main:  'endless loop
Call i2clcdbegin()
Call cmdwrite(0x80)
Call printstr1()
Call cmdwrite(0xc0)
Call printstr2()
Call cmdwrite(0x90)
Call printstr3()
Call cmdwrite(0xd0)
Call printstr4()
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
 
There is no difference with these change in addresses. See the photo.
The SDA and SCL were a bit higher in my program, I had not copied this piece of the code. (Sorry)
But how do you determine this hex code anyway, I don't see it in the data sheet?
I am very curious how do you determine this, where do you get that information?

Does the problem anything to do with the I2C clock speed?
And should the SDA and SCL be used as an output or as an input? It is said in the datasheet that it does not matter.
But is that true? What is your experience? Now they are set as input.

IMG_20191027_162138.jpg
 
I did not expect that you specifically wanted to see this PCB.
Because I actually assumed that these problems are caused by the LCD.
I misunderstood you.
Below the total picture!
It is hard to read but it is the PCF8574T and below that is written ABX919

IMG_20191029_172229.jpg
 
There is the problem... My code is written for the PCF8574.. the address used was 0x4E... All A(X) pins tied high (A0,A1,A2)

I believe some of the PCF8574T models use 0x38.. Look at the three resistor positions... These may upset the address.

Two options... 0x3E or 0x38 one is all high and the other all low...
 
They are all three high in any case. That's how they are set now.
I'm going to try this tomorrow.
You will hear from me. ;-)
Thanks anyway.
 
I have the same daughter board on a 4x20 display and just checked the project where I used it. It uses address 0x3f which must be shifted left to give 0x7e.

Mike.
 
Dear Ian and Pommie,

When I connect a two line display to the code below, I have this as a result.
As you can see a nice result.
IMG_20191030_115435.jpg

Then you can conclude that it is not the PCF8574T. (At least that's how I see it)
I tried these other addresses this morning, but no result with a four line display.
What is the difference between this two line display and a four line display?
I don't understand this.

Code:
'
DEVICE PIC16F887

Define CONFIG1 = 0x23e2  '23e2
Define CONFIG2 = 0x3eff
Define CLOCK_FREQUENCY = 16

AllDigital  'alle ports digital

Symbol LedBlue = PORTD.3

'Dim addr As Word  'variable for storing EEPROM byte address
Dim data As Byte  'variable for storing EEPROM byte data

Dim bl As Byte  'backlighting
Dim rs As Byte

'I2C Bus
Symbol sda = PORTC.4
Symbol scl = PORTC.3

Low LedBlue

bl = 0x8
rs = 0x1

main:  'endless loop

Call i2clcdbegin()
Call cmdwrite(0x80)  '0x80 = 1e line
Call printstr1()
Call cmdwrite(0xc0)  '0xc0 = 2e line
Call printstr2()
Call cmdwrite(0x94)  '0x94 = 3e line
Call printstr3()
Call cmdwrite(0xd4)  '0xd4 = 4e line
Call printstr4()

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
        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
 
Check you soldering on the big LCD as one of the data pins isn't connected right.. The chip insde the LCD has the exact same command set.

Other than that, you have a bad 4 x 16 screen..

Just check your single inline socket on the 4x16.. I once had one that was broken inside, no electrical thu put!
 
Last edited:
What is the difference between this two line display and a four line display?
You can think of a four line display as a 2x32 char display that has been split vertically and the right hand side placed below the left hand side. If you write to the top line eventually (when it's full) the next characters will appear on line 3 - not line 2 as you would imagine. So the address of each line is 0x00,0x40,0x10,0x50. These numbers need the top bit added before being sent as a command. So, if it works with a 2x16 display then it should work with a 4x32 display. The fact it doesn't points to a mechanical problem as pointed out by Ian.

Mike.
 
No I don't believe it's a hardware issue.
Below a totally different and new display with the same problems.
IMG_20191030_124539.jpg

So the address of each line is 0x00,0x40,0x10,0x50. These numbers need the top bit added before being sent as a command.
But what do you mean by this rule?
Keep looking for the solution, but I don't quite understand what to do with this.
Can you explain it more clearly?
I am not very experienced with I2C. :-(
Try to learn from this.
 
The I2C is only acting as a serial to parallel convertor.. The software shifts all the relevant bits into place then clocks it in.
Code:
  data = hi + bl + rs      ////// data is the high nibble + backlight + register selected ie.. command or data
  I2CWrite sda, scl, 0x4e, data, data     //////  write it to the shift register
  data = data + 0x4         ////  Enable bit 4 ( EN signal )
  I2CWrite sda, scl, 0x4e, data, data //// Clock that in
  data = data - 0x4       //// Disable bit 4
  I2CWrite sda, scl, 0x4e, data, data       ////// clock that in
The I2C control is superfluous here... Whats not happening is the BIG display isn't receiving the signals correctly... Maybe the datapins on that display are in the wrong positions...
 
But how do you determine this hex code anyway, I don't see it in the data sheet?
I am very curious how do you determine this, where do you get that information?
What do you mean by "hex code" What do you need to know..
 
The I2C is only acting as a serial to parallel convertor.. The software shifts all the relevant bits into place then clocks it in.
Code:
  data = hi + bl + rs      ////// data is the high nibble + backlight + register selected ie.. command or data
  I2CWrite sda, scl, 0x4e, data, data     //////  write it to the shift register
  data = data + 0x4         ////  Enable bit 4 ( EN signal )
  I2CWrite sda, scl, 0x4e, data, data //// Clock that in
  data = data - 0x4       //// Disable bit 4
  I2CWrite sda, scl, 0x4e, data, data       ////// clock that in
The I2C control is superfluous here... Whats not happening is the BIG display isn't receiving the signals correctly... Maybe the datapins on that display are in the wrong positions...
I now understand that piece well. Thanks for that anyway.
This has given me more insight into what actually happens.

No, I've already checked that before!
Is exactly the same as the two line display. The same pining no difference.
 
What do you mean by "hex code" What do you need to know..

Where the information is taken from the "i2clcdbegin" code.
I have now understood that these are the addresses of the PCF8574T.
So that the data is sent to the correct port of this IC.
That right or not?
 
Status
Not open for further replies.

Latest threads

Back
Top