Code C graphic LCD #1

/////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_line(int16 x1, int16 y1, int16 x2, int16 y2, int1 color)
#else
void glcd_line(int8 x1, int8 y1, int8 x2, int8 y2, int1 color)
#endif
{
int16 dy, dx;
signed int8 addx=1, addy=1;
signed int16 P, diff;

#ifdef LARGE_LCD
int16 i=0;
dx = abs((signed int16)(x2 – x1));
dy = abs((signed int16)(y2 – y1));
#else
int8 i=0;
dx = abs((signed int8)(x2 – x1));
dy = abs((signed int8)(y2 – y1));
#endif

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

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

for(; i<=dx; ++i)
{
glcd_pixel(x1, y1, color);

if(P < 0)
{
P += dy;
x1 += addx;
}
else
{
P += diff;
x1 += addx;
y1 += addy;
}
}
}
else
{
dx *= 2;
P = dx – dy;
diff = P – dy;

for(; i<=dy; ++i)
{
glcd_pixel(x1, y1, color);

if(P < 0)
{
P += dx;
y1 += addy;
}
else
{
P += diff;
x1 += addx;
y1 += addy;
}
}
}
#ifdef FAST_GLCD
glcd_update();
#endif
}

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: