⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphics.c

📁 笔段型TN LCM测试
💻 C
字号:
// --------------------- Graphic Library of LCD -------------------------------

bit iPoint = 1;		// Global variable for Turn on/off point
// Display a picture on the specific position of the Screen
void disp_image(uint8 code *ptrImage, uint8 StartP, StartC)
{
	uint8 i,k;
	uint8 width = *ptrImage++;	// Image width
	uint8 height = *ptrImage++;	// Image height
	uint8 PageHold;		// pages the image holds
	
	if (height%8 != 0)
		PageHold = height/8 + 1;
	else
		PageHold = height/8;
	
	StartP += 1;
	for (k = StartP; k > StartP - PageHold; k--)
	{
		Gotoxy(k - 1, StartC);
		for (i = 0; i < width; i++)
		{
			SendByte(iDat, *ptrImage++);
		}
	}
}

// Display a picture on the upleft corner of LCD Screen
void disp_upleft(uint8 code *ptrImage)
{
	disp_image(ptrImage, LCD_PMAX - 1, 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 StartP;		// Start Page
	uint8 StartC;		// Start Column
	
	if (height%8 != 0)
		PageHold = height/8 + 1;
	else
		PageHold = height/8;
	
	if ((LCD_PMAX + PageHold)%2 != 0)
		StartP = (LCD_PMAX + PageHold)/2 + 1;
	else
		StartP = (LCD_PMAX + PageHold)/2;
	StartC = (LCD_CMAX - width)/2;
	
	disp_image(ptrImage, StartP, StartC);
}

// Draw a rectangle using the two given points
void disp_frame(uint8 X0,Y0,X1,Y1)
{
	uint8 i, StartP, EndP;
	uint8 LstDot[2];
	StartP = Y1/8;
	EndP   = Y0/8;
	LstDot[0] = 1 << Y0%8;
	LstDot[1] = 1 << Y1%8;
	
	Gotoxy(StartP, X0);
	SendByte(iDat, 0x80|((~(2*LstDot[1] - 1))>>1));
	SetCA(X1);
	SendByte(iDat, 0x80|((~(2*LstDot[1] - 1))>>1));
	Gotoxy(EndP, X0);
	SendByte(iDat, 2*LstDot[0] - 1);
	SetCA(X1);
	SendByte(iDat, 2*LstDot[0] - 1);
	
	// Draw the vertical lines
	for (i = StartP + 1; i < EndP; i++)
	{
		Gotoxy(i, X0);
		SendByte(iDat, 0xFF);
		SetCA(X1);
		SendByte(iDat, 0xFF);
	}
	
	// Draw the horizontal lines
	for (i = X0 + 1; i < X1; i++)
	{
		Gotoxy(StartP, i);
		SendByte(iDat, LstDot[1]);
		Gotoxy(EndP, i);
		SendByte(iDat, LstDot[0]);
	}
}

#ifdef LCD_8BIT
// Draw a point at specific coordinate
void Point(uint8 Xpoint, uint8 Ypoint)
{
	uint8 Page;
	uint8 OldData;
	uint8 NewData;
	
	Page = Ypoint/8;
	OldData = ReadData(Page, Xpoint);
	
	Gotoxy(Page, Xpoint);
	if (iPoint)
	{
		// Turn on a point
		NewData = 0x01 << (Ypoint%8);
		SendByte(iDat, OldData|NewData);
	}
	else
	{
		// Turn off a point
		NewData = ~(0x01 << (Ypoint%8));
		SendByte(iDat, OldData & NewData);
	}
}

// Draw a straint line
void Line(uint8 X1, uint8 Y1, uint8 X2, uint8 Y2)
{
	// Not Completed !!!
	uint8 i, Rate;
	Rate = (Y2 - Y1)/(X2 - X1);
	
	for (i = X1; i <= X2; i++)
	{
		Point(i, Y1 + Rate*(i - X1));
	}
}

// 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 == LCD_LMAX) && (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 == LCD_CMAX) && (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 < LCD_CMAX; i += 2)
	{
		LineV(i,0, LCD_LMAX);
		DelayMs(Tscan);
	}
}

// Scan each line
void ScanH(uint8 Tscan)
{
	uint8 i;
	for (i = 0; i < LCD_LMAX; i += 2)
	{
		LineH(0,i, LCD_CMAX);
		DelayMs(Tscan);
	}
}

// Draw a Rectangle
void Rectangle(struct RectInfo Points)
{
	LineH(Points.X0, Points.Y0, Points.X1 - Points.X0);
	LineH(Points.X0, Points.Y1, Points.X1 - Points.X0);
	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 = LCD_CMAX/2 - 10;
	OriginRect.Y0 = LCD_LMAX/2 + 5;
	OriginRect.X1 = LCD_CMAX/2 + 10;
	OriginRect.Y1 = LCD_LMAX/2 - 5;
	
	while(xframes-- != 0)
	{
		Rectangle(OriginRect);
		OriginRect.X0 -= 4;
		OriginRect.Y0 += 2;
		OriginRect.X1 += 4;
		OriginRect.Y1 -= 2;
	}
}
#endif
// Draw a fullscreen rectangle
void RectFullscreen(void)
{
	#ifndef LCD_8BIT
		disp_frame(0, LCD_LMAX - 1, LCD_CMAX - 1, 0);
	#else
		LineH(0, 0, LCD_CMAX);
		LineH(0, LCD_LMAX - 1, LCD_CMAX);
		LineV(0, 0, LCD_LMAX);
		LineV(LCD_CMAX - 1, 0, LCD_LMAX);
	#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -