LCDInfo.com

http://www.lcdinfo.com
It is currently Fri Nov 22, 2024 10:45

All times are UTC + 2 hours




Post new topic Reply to topic  [ 46 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: Tue Dec 31, 2002 17:54 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
I can't tell you if it works... but it works in the way that both codes never end in an endless loop.

I did some tests with different images (geometric forms) and it seems that the pixels are not set on the correct position.

The reason could be in the SetLCDPixel function. I didn't know what font_width was, so I thought it is the width of each character. This would be 6 pixels with my display (because of the 6x8 font set).
Was this right?

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 31, 2002 18:05 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
If it hangs it is a sign that the code isn't right. You could try adding some delay in place of the statuscheck before I figure out how the status check works.

This is from Yarvieh (the maker of LCDStudio) and it can be used to create small delays. I'm not sure how easy it is to convert to visual basic but I'm sure it has some way to create delays.

Code:
void MicroDelay(long microseconds)
{
  LARGE_INTEGER liFreq;
  LARGE_INTEGER liCnt;
  LARGE_INTEGER liStart;
  LONGLONG ticksPerMilliSec = 0;

  if ( QueryPerformanceFrequency(&liFreq) )
  {
    ticksPerMilliSec = (liFreq.QuadPart)/1000000;
  }
  else
  {
  // MessageBox(NULL,"Error obtaining frequency\n",0,NULL);
  }

  if ( QueryPerformanceCounter(&liStart) )
  {
    do
    {
      QueryPerformanceCounter(&liCnt);
    }while ((liStart.QuadPart + (__int64)(ticksPerMilliSec * microseconds)) > liCnt.QuadPart);
  }
}


The font_widht is what you thought. It should be 6 if used with 6x8 font.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 31, 2002 19:25 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
It does not hang, it seems to work correct.
When I display text, it is displayed perfectly without any characters or pixels left out.

Here are pictures of my geometric test:

Image

Image

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 01, 2003 14:03 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
floppes wrote:
It does not hang, it seems to work correct.
When I display text, it is displayed perfectly without any characters or pixels left out.

Hmm, so you can use the WaitDisplayReady() function without problems ? Because if it can't read the status flag it should go to infinite loop and hang the program.

Have you tried with some pause instead of WaitDisplayReady() ?

You could also post your code here or send it to me to check if I could notice anything strange in it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 01, 2003 15:46 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
I have written this to wait for the display:

Code:
Public Sub WaitDisplayReady()
Dim lngTmp As Long
Dim lngDiff As Long

lngTmp = GetTickCount()
Do Until lngDiff > 2
    lngDiff = GetTickCount() - lngTmp
    DoEvents
Loop

End Sub


It waits 2 ms to do the next pixel. So it takes about 5 minutes to draw the whole display. This is quite interesting to see in which order it draws the pixels. I will try to describe it (pixel 0 starts in the upper left corner):

It starts at (0|0) and ends at (127|127). It goes like this: (0|0), (0|1), (0|2)... until (0|127) and then starts at (1|0) and goes till (1|127) and so on. But it jumps in the columns. After the first three lines, it jumps to line 5 or 6 and draws there 3 lines, then jumps back to fill the gap with the content that should have been elsewhere. This is why the picture I posted above looks that strange.

It could be caused by the modulo calculation. Here is my code that draws a pixel:

Code:
Public Sub SetPixel(intX As Integer, intY As Integer)
Dim intAddr As Integer

intAddr = intGBase + (intY * intBytesPerRow) + (intX / 6)  'calculate place in memory
Call WriteData(intAddr And 255) 'write calculated address

Call WriteData(RShiftLong(intAddr, 8)) 'write calculated address
Call WriteCommand(36) 'set cursor

Call WriteCommand(248 Or (6 - 1 - (intX) Mod 6))
End Sub

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 01, 2003 16:18 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
I have analyzed the way the lines are drawn. This is a list in which order the lines are drawn. On the left is line 1 which starts at (0|0) and goes to (0|127):

Code:
01 02 03 04 -- -- 07 08 09 -- 05 06 13 14 15 10 11 12 19 20 21 -- 17 18 25 26 27 22 23 24 31 32 33 -- 29 30 37 38 39 34 35 36 43 44 45 -- 41 42 49 50 51 46 47 48 55 56 57 ...

it should have been:

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57


Those are always blocks of 11 lines, seperated by a blank line (--). Only the beginning is different.

I will try to find out the scheme that lies behind this line shifting.

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 01, 2003 19:27 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
I did not come any further, but made a small graphic to analyze the shifting:

Image

The light red squares are lines that are drawn over the yellow lines.

I think the problem lies in the SetPixel function. Something with the calculation must be wrong. I have experimented with it a little, but always got strange results...

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 01, 2003 23:59 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
More code for you:

It draws a bitmap to the screen using the block write mode of t6963c.

Code:
void cT6963C::DrawAnimFrame(Graphics::TBitmap *frameBitmap, int x, int y)
{

  int addr;

  for(int i=0;i<frameBitmap->Height;i++)
  {
    // set address pointer to beginning of row
    addr = G_BASE + ((y+i)*BYTES_PER_ROW) + (x/font_width);
    T6963C.WriteData(addr & 0xFF);
    T6963C.WriteData(addr >> 8);
    T6963C.WriteCtrl(0x24);

    T6963C.WriteCtrl(0xB0); // auto write mode on

    for(int j=0;j<frameBitmap->Width;j++)
    {
      BYTE lcdValue = 0;

      // build the byte to send to display
      for(int k=0;k<font_width-1;k++) // add all bits except last one
      {
        lcdValue |= (frameBitmap->Canvas->Pixels[font_width*j+k][i]!=0 ? (byte)0 : (byte)1);
        lcdValue <<= 1;
      }
      lcdValue |= (frameBitmap->Canvas->Pixels[font_width*j+5][i]!=0 ? (byte)0 : (byte)1); // add
last bit to byte
     
      T6963C.WriteData(lcdValue);
    }

    T6963C.WriteCtrl(0xB2); // auto write mode off
  }

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 0:12 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
Thanks!

It looks like BorlandC++.
But I don't understand those lines:

Code:
lcdValue |= (frameBitmap->Canvas->Pixels[font_width*j+k][i]!=0 ? (byte)0 : (byte)1);
lcdValue <<= 1;


What do "|=", "?" and "(byte)0 : (byte)1" do?

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 0:38 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
I just made my first ever visual basic program to calculate these:

VB: (248 Or (6 - 1 - (intX) Mod 6))

C: (0xf8 | (6-1-(x % 6)))

I tried them with different values but couldn't notice any difference.


Quote:
What do "|=", "?" and "(byte)0 : (byte)1" do?


The following is from C++ Builders help:
In the expression E1 ? E2 : E3, E1 evaluates first. If its value is true, then E2 evaluates and E3 is ignored. If E1 evaluates to false, then E3 evaluates and E2 is ignored.

Example:
lcdValue = bitmap[x][y]!=0 ? 0 : 1;
If bitmap[x][y] is 0 then store 1 to lcdValue if bitmap[x][y] is something else store 0.
EDIT: I ignored the ! sign in the above explanation but I changed it now.



Then
lcdValue |= bitmap;
is same as
lcdValue = lcdValue | bitmap;

But then what this means ?
lcdValue |= bitmap[x][y]!=0 ? 0 : 1;
lcdValue <<= 1;

Below is lcdValue in different stages:
00000000 <- lcdValue in the beginning
00000001 <- 0 found from bitmap[x][y] -> inverted to 1-> ORred to lcdValue
00000010 <- left shift lcdValue with 1
00000011 <- 0 found from bitmap[x][y] -> inverted to 1-> ORred to lcdValue
00000110 <- left shift lcdValue with 1
00000110 <- 1 found from bitmap[x][y] -> inverted to 0-> ORred to lcdValue
00001100 <- left shift lcdValue with 1

Hope this makes some sense, teaching these to others just isn't my thing :wink:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 2:03 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
Quote:
But then what this means ?
lcdValue |= bitmap[x][y]!=0 ? 0 : 1;
lcdValue <<= 1;


I didn't know what <<= does, but now I know that it is left shifting :)

I ported your code to VB and it works! :D
This is the code:

Code:
Public Sub DrawBMP(picPicBox As PictureBox, intX As Integer, intY As Integer)
Dim intAddr As Integer
Dim intI As Integer
Dim intJ As Integer
Dim intK As Integer
Dim lngLCDValue As Integer
Dim intTmp As Integer

For intI = 0 To 127
    'set address pointer to beginning of row
    intAddr = intGBase + ((intY + intI) * intBytesPerRow) + (intX / 6)
    Call WriteData(intAddr And 255)
    Call WriteData(RShiftLong(intAddr, 8))
    Call WriteCommand(36)

    Call WriteCommand(176) 'auto write mode on

    For intJ = 0 To 127
        lngLCDValue = 0

        'build the byte to send to display
        For intK = 0 To 4 'add all bits except last one
            If picPicBox.Point(6 * intJ + intK, intI) <> 0 Then
                intTmp = 0
            Else
                intTmp = 1
            End If
           
            lngLCDValue = lngLCDValue Or intTmp
            lngLCDValue = LShiftLong(lngLCDValue, 1)
        Next intK

        If picPicBox.Point(6 * intJ + 5, intI) <> 0 Then
            intTmp = 0
        Else
            inttmo = 1
        End If

        lngLCDValue = lngLCDValue Or intTmp 'addlast bit to byte
     
        Call WriteData(lngLCDValue)

    Next intJ
    Call WriteCommand(178) 'auto write mode off
Next intI

End Sub


But there are irregular graphic errors, but I think they don't have to do with the code but with the display itself. Even when I use LCDInfo to display some bitmaps I get those graphic errors. Each time I display the same bitmap the errors are different. Mostly they are shifted lines. Here is a picture as an example:

Image

The text is always correct.

Are there any registers in the RAM or ROM of the display that are saved even when the computer is switched off? Maybe they are set wrong in this is the cause for the errors. And do I need to perform any commands to prepare the display to be shut off? Something like I the initialization.

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 2:24 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
floppes wrote:
But there are irregular graphic errors, but I think they don't have to do with the code but with the display itself. Even when I use LCDInfo to display some bitmaps I get those graphic errors. Each time I display the same bitmap the errors are different. Mostly they are shifted lines.

That may be because of writing too fast to the lcd. Adding busy flag checking just before writing the data byte might fix it. Unfortunately auto mode has it's own busy flag checking and I haven't got the code for that working. But you could try adding a slight delay before the Call WriteData(lngLCDValue) line. This would confirm if that's the problem.

Also LCDInfo doesn't yet have busy flag checking implemented for your wiring. I'm hoping to have user definable wiring in the next LCDInfo version so after that there shouldn't be worries of different wirings anymore.

Quote:
Are there any registers in the RAM or ROM of the display that are saved even when the computer is switched off? Maybe they are set wrong in this is the cause for the errors. And do I need to perform any commands to prepare the display to be shut off? Something like I the initialization.

I don't know of any registers that would retain their values after power off. Also I'm not aware of any shutdown routines needed.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 2:39 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
I also noticed that you have hardcoded the picture size to 128x128 in your code. In this case it isn't necessary to set the memory pointer to the beginning of a next row in the outer loop. You can just set the memory pointer to G_BASE before the loops. This way you get rid of some unnecessary work and your program should work faster.

The code I posted works for smaller bitmaps too.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 13:49 
Offline

Joined: Mon Dec 30, 2002 18:10
Posts: 27
Location: Darmstadt, Germany
Quote:
That may be because of writing too fast to the lcd.

This is strange, because in the first days when I had the LCD everything worked fine with LCDInfo.

I added a delay before writing and it fixes most of the shifted lines. But there are still a few graphic errors, which are visible only at the second sight. I made a test graphic where every second line (horizontal and vertical) is black, the next white. When using your algorithm, every 6th line horizontal is left out. The vertikal lines are ok. Then I changed something in the code:

Code:
For intK = 0 To 4
to
For intK = 1 To 5

and

If picPicBox.Point(6 * intJ + 5, intI) <> 0 Then
to
If picPicBox.Point(6 * intJ + 6, intI) <> 0 Then


With this change the lines are no longer left out.
But there are still small errors in the drawn picture, everytime at the same position.

I will try to find out how to read the busy flag for my wiring.
And I am looking forward for the next version of LCDInfo :) If I can help you with testing, just let me know!

_________________
The answer to all questions is 42


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 02, 2003 14:13 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
floppes wrote:
This is strange, because in the first days when I had the LCD everything worked fine with LCDInfo.

Hmm, when was that and what LCDInfo version were you using ?

Quote:
When using your algorithm, every 6th line horizontal is left out. The vertikal lines are ok. Then I changed something in the code:

...

With this change the lines are no longer left out.

Maybe you found a bug in my code or some thing that works differently in VB.

Quote:
I will try to find out how to read the busy flag for my wiring.

Some new code including busy flag reading for all wirings is coming soon...

Quote:
And I am looking forward for the next version of LCDInfo :) If I can help you with testing, just let me know!

Ok, you could email me and I will send you a test version. There should be something to test pretty soon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 46 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC + 2 hours


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group