Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Algorithm for drawing any line in graphical LCD Ampire 128x64 with controller KS0108

Status
Not open for further replies.

Elnegm

Member level 1
Joined
Jun 28, 2005
Messages
33
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,524
Are any one have an algorithm to draw any line in agraphical LCD Ampire 128x64 with controller KS0108?
Thanks in advance
 

lcd ks018

Try this one (extract from Jharbour's GBA programming guide).
www.jharbour.com
GBA programming chapter 5.

Of course, you need to have the DrawPixel3() function working first.

Code:
void DrawLine3(int x1, int y1, int x2, int y2, boolean color)
{
int i, deltax, deltay, numpixels;
int d, dinc1, dinc2;
int x, xinc1, xinc2;
int y, yinc1, yinc2;
//calculate deltaX and deltaY
deltax = abs(x2 - x1);
deltay = abs(y2 - y1);
//initialize
if(deltax >= deltay)
{
//If x is independent variable
numpixels = deltax + 1;
d = (2 * deltay) - deltax;
dinc1 = deltay << 1;
dinc2 = (deltay - deltax) << 1;
xinc1 = 1;
xinc2 = 1;
yinc1 = 0;
yinc2 = 1;
}
else
{
//if y is independent variable
numpixels = deltay + 1;
d = (2 * deltax) - deltay;
dinc1 = deltax << 1;
dinc2 = (deltax - deltay) << 1;
xinc1 = 0;
xinc2 = 1;
yinc1 = 1;
yinc2 = 1;
}
//move the right direction
if(x1 > x2)
{
xinc1 = -xinc1;
xinc2 = -xinc2;
}
if(y1 > y2)
{
yinc1 = -yinc1;
yinc2 = -yinc2;
}
x = x1;
y = y1;
//draw the pixels
for(i = 1; i < numpixels; i++)
{
DrawPixel3(x, y, color);
if(d < 0)
{d = d + dinc1;
x = x + xinc1;
y = y + yinc1;
}
else
{
d = d + dinc2;
x = x + xinc2;
y = y + yinc2;
}
}
}
 

bascom ks0108

Thanks TechToys
but this code has aproblem in some cases for example in case of line with large slope the code didn't work correctly
so please help
 

drawpixel3()

What about this one? Pretty the same I think.

Code:
// Purpose:       Draw a line on a graphic LCD using Bresenham's
//                line drawing algorithm
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                color - ON or OFF
// Dependencies:  glcd_pixel()
void glcd_line(int x1, int y1, int x2, int y2, int1 color)
{
   signed int  x, y, addx, addy, dx, dy;
   signed long P;
   int i;
   dx = abs((signed int)(x2 - x1));
   dy = abs((signed int)(y2 - y1));
   x = x1;
   y = y1;

   if(x1 > x2)
      addx = -1;
   else
      addx = 1;
   if(y1 > y2)
      addy = -1;
   else
      addy = 1;

   if(dx >= dy)
   {
      P = 2*dy - dx;

      for(i=0; i<=dx; ++i)
      {
         glcd_pixel(x, y, color);

         if(P < 0)
         {
            P += 2*dy;
            x += addx;
         }
         else
         {
            P += 2*dy - 2*dx;
            x += addx;
            y += addy;
         }
      }
   }
   else
   {
      P = 2*dx - dy;

      for(i=0; i<=dy; ++i)
      {
         glcd_pixel(x, y, color);

         if(P < 0)
         {
            P += 2*dx;
            y += addy;
         }
         else
         {
            P += 2*dx - 2*dy;
            x += addx;
            y += addy;
         }
      }
   }
}
 

ks018 glcd

Any url for the others like
1. Circle
2. Ellipse
3. Beizer Curve etc...
 


or byte draw pixel lcd ks0108

The first LineDraw function works. Attached find the picture.

I used this in main to draw:

DrawLine3(0, 0, 5, 64, 0);
DrawLine3(0, 0, 20, 64, 0);
DrawLine3(0, 0, 40, 64, 0);
DrawLine3(0, 0, 60, 64, 0);
DrawLine3(0, 0, 80, 64, 0);
DrawLine3(0, 0, 100, 64, 0);
DrawLine3(0, 0, 120, 64, 0);
John
www.TechToys.com.hk
 

    Elnegm

    Points: 2
    Helpful Answer Positive Rating
Re: Graphical LCD

Thanks so much TechToys i discovered that i had aproblem in function of drawpixel as in the same page when i write on a certain location on acertain pixel when i wrote in the same location in new pixel the first pixel disappeared so i will try to fix it and for the second time thanks so much
 

Re: Graphical LCD

Hi Elnegm

OK. That is what I thought for your problem at the very beginning. Interfacing with KS0107/8 LCD uses all 8-bit data in a verticle manner. Writing a value of, say, 0xFF will draw 8 pixels at a certain column at one of the 128 pixel columns of the screen.

When a single pixel is needed but not affecting the other pixel on a certain PAGE, I use the READ function to read the original verticle byte pattern of a particular PAGE first, then a bitwise OR operation is done to make sure when a single pixel is lited at a certain co-ordinate in the the verticle direction, the other pixels will not be affected.

Hopefully on tomorrow, I will finish the last chapter of my development board's manual, which is about the graphical LCD. Detailed description will be written.

Go to take a look if interested.

John
www.TechToys.com.hk
 

Re: Graphical LCD

Hi TechToys
I got your solution but the problem that the read instruction itself i have aproblem in it this is the problem i'm facing now, that the prevoius data is not correct espectially in the first time.
Abd good luck for your development board's manual [/quote]
 

Re: Graphical LCD

hi ,is there anyone can help me in my topic. i need to an algorithm using MPLAB that can draw me a line on the AMPIRE 128*64 graphical LCD using KS018 driver or even some help in the interface between the AMPIRE LCD and pic 18 .10x in advance
 

Re: Graphical LCD

Hi
The best chip for graphical lcd is T6963c of Toshiba and the best software for work with graphical lcd is bascom.
this software has very usefull built in functions for this chip...
Other chip is ks0108 ... but T6963c is very better than ks0108
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top