andy40185
Member level 5
Hi all,
I am designing a picture to display on lcd. Have any software can support this and convert to a bitmap?
Also, I have a function to draw a circle on lcd but it does not work and something are missing, can anyone help me to modify it?
I am designing a picture to display on lcd. Have any software can support this and convert to a bitmap?
Also, I have a function to draw a circle on lcd but it does not work and something are missing, can anyone help me to modify it?
Code:
// Purpose: Draw a circle on a graphic LCD
// Inputs: (x,y) - the center of the circle
// radius - the radius of the circle
// fill - YES or NO
// color - ON or OFF
void glcd_circle(int x, int y, int radius, int1 fill, int1 color)
{
signed int a, b, P;
a = 0;
b = radius;
P = 1 - radius;
do
{
if(fill)
{
glcd_line(x-a, y+b, x+a, y+b, color);
glcd_line(x-a, y-b, x+a, y-b, color);
glcd_line(x-b, y+a, x+b, y+a, color);
glcd_line(x-b, y-a, x+b, y-a, color);
}
else
{
glcd_pixel(a+x, b+y, color);
glcd_pixel(b+x, a+y, color);
glcd_pixel(x-a, b+y, color);
glcd_pixel(x-b, a+y, color);
glcd_pixel(b+x, y-a, color);
glcd_pixel(a+x, y-b, color);
glcd_pixel(x-a, y-b, color);
glcd_pixel(x-b, y-a, color);
}
if(P 0)
P+= 3 + 2*a++;
else
P+= 5 + 2*(a++ - b--);
} while(a = b);
}
Code:
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;
do
{
glcd_pixel(x, y, color);
if(P<0)
{
P += 2*dy;
x += addx;
}
else
{
P += 2*dy - 2*dx;
x += addx;
y += addy;
}
} while(x!=x2);
}
else
{
P = 2*dx - dy;
do
{
glcd_pixel(x, y, color);
if(P>0)
{
P += 2*dx;
y += addy;
}
else
{
P += 2*dx - 2*dy;
x += addx;
y += addy;
}
} while(y!=y2);
}
}
Code:
// Purpose: Turn a pixel on a graphic LCD on or off
// Inputs: x - the x coordinate of the pixel
// y - the y coordinate of the pixel
// color - ON or OFF
// Output: 1 if coordinate out of range, 0 if in range
void glcd_pixel(int x, int y, int1 color)
{
BYTE data;
BYTE chip = GLCD_CS1; // Stores which chip to use on the LCD
if(x > 63) // Check for first or second display area
{
x -= 64;
chip = GLCD_CS2;
}
output_low(GLCD_DI); // Set for instruction
bit_clear(x,7); // Clear the MSB. Part of an instruction code
bit_set(x,6); // Set bit 6. Also part of an instruction code
glcd_writeByte(chip, x); // Set the horizontal address
glcd_writeByte(chip, (y/8 & 0b10111111) | 0b10111000); // Set the vertical page address
output_high(GLCD_DI); // Set for data
data = glcd_readByte(chip);
if(color == ON)
bit_set(data, y%8); // Turn the pixel on
else // or
bit_clear(data, y%8); // turn the pixel off
output_low(GLCD_DI); // Set for instruction
glcd_writeByte(chip, x); // Set the horizontal address
output_high(GLCD_DI); // Set for data
glcd_writeByte(chip, data); // Write the pixel data
}
Last edited: