📄 graphics.c
字号:
#include "ra8815.h" // Include basic LCD driver
bit iPoint = 1; // Global variable for Turn on/off point
// Information for drawing a rectangle
struct RectInfo
{
uint8 X0,Y0,X1,Y1;
};
// Display an image at the specific position of the screen
void disp_image(uint8 code *ptrImage, uint8 X0, Y0)
{
uint8 i, k;
uint8 PageHold;
uint8 width = *ptrImage++;
uint8 height = *ptrImage++;
if (width%8 != 0)
PageHold = width/8 + 1;
else
PageHold = width/8;
for (k = Y0; k < Y0 + height; k++)
{
Gotoxy(X0, k);
for (i = 0; i < PageHold; i++)
{
WriteData(*ptrImage++);
}
}
}
// Display a picture on the upleft corner of LCD Screen
void disp_upleft(uint8 code *ptrImage)
{
disp_image(ptrImage, 0, 0);
}
// Display a picture on the center of LCD Screen
void disp_center(uint8 code *ptrImage)
{
uint8 width = *ptrImage; // Image width
uint8 height = *(ptrImage + 1); // Image height
uint8 PageHold; // pages the image holds
uint8 StartX; // Start Page
uint8 StartY; // Start Column
if (width%8 != 0)
PageHold = width/8 + 1;
else
PageHold = width/8;
if ((X_MAX/8 + PageHold)%2 != 0)
StartX = (X_MAX/8 - PageHold)/2 + 1;
else
StartX = (X_MAX/8 - PageHold)/2;
StartY = (Y_MAX - height)/2;
disp_image(ptrImage, StartX, StartY);
}
// Draw a point at specific coordinate
void Point(uint8 Xpoint, uint8 Ypoint)
{
uint8 xUnit;
uint8 OldData;
uint8 NewData;
xUnit = Xpoint/8;
OldData = ReadData(xUnit, Ypoint);
Gotoxy(xUnit, Ypoint);
if (iPoint)
{
// Turn on a point
NewData = 0x01 << (Xpoint%8);
WriteData(OldData|NewData);
}
else
{
// Turn off a point
NewData = ~(0x01 << (Xpoint%8));
WriteData(OldData & NewData);
}
}
// Draw a horizontal line
void LineH(uint8 X0, uint8 Y0, uint8 Length)
{
uint8 i;
for (i = X0; i <= X0 + Length; i++)
{
Point(i, Y0);
}
}
// Draw a Virtical line
void LineV(uint8 X0, uint8 Y0, uint8 Height)
{
uint8 i;
for (i = Y0; i <= Y0 + Height; i++)
{
Point(X0, i);
}
}
// Draw a table with specific rows and cols
void Table(uint8 Rows, Cols, uint8 width, height)
{
uint8 i;
for (i = 0; i <= Rows; i++)
{
if ((Rows*height == Y_MAX) && (i == Rows))
LineH(0, i*height - 1, Cols*width);
else
LineH(0, i*height, Cols*width);
}
for (i = 0; i <= Cols; i++)
{
if ((Cols*width == X_MAX) && (i == Cols))
LineV(i*width - 1, 0, Rows*height);
else
LineV(i*width, 0, Rows*height);
}
}
// Scan Vertical line
void ScanV(uint8 Tscan)
{
uint8 i;
for (i = 0; i < X_MAX; i += 2)
{
LineV(i, 0, Y_MAX);
DelayMs(Tscan);
}
}
// Scan each line
void ScanH(uint8 Tscan)
{
uint8 i;
for (i = 0; i < Y_MAX; i += 2)
{
LineH(0, i, X_MAX);
DelayMs(Tscan);
}
}
// Draw a Rectangle
void Rectangle(struct RectInfo Points)
{
LineH(Points.X0, Points.Y0, Points.X0 - Points.X1);
LineH(Points.X0, Points.Y1, Points.X0 - Points.X1);
LineV(Points.X0, Points.Y1, Points.Y0 - Points.Y1);
LineV(Points.X1, Points.Y1, Points.Y0 - Points.Y1);
}
// Show x frames on the screen
void frameShow(uint8 xframes)
{
struct RectInfo OriginRect;
OriginRect.X0 = X_MAX/2 - 10;
OriginRect.Y0 = Y_MAX/2 + 5;
OriginRect.X1 = X_MAX/2 + 10;
OriginRect.Y1 = Y_MAX/2 - 5;
while(xframes-- != 0)
{
Rectangle(OriginRect);
OriginRect.X0 += 4;
OriginRect.Y0 += 2;
OriginRect.X1 -= 4;
OriginRect.Y1 -= 2;
}
}
// Draw a fullscreen rectangle
void RectFullscreen(void)
{
LineH(0, 0, X_MAX);
LineH(0, Y_MAX - 1, X_MAX);
LineV(0, 0, Y_MAX);
LineV(X_MAX - 1, 0, Y_MAX);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -