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

📄 graphics.c

📁 西红柿的驱动
💻 C
字号:
// ------------------------ Graphic Functions ----------------------------------

// Display a picture on the upleft corner of LCD Screen
void disp_upleft(uint8 code *ptrImage, uint8 width, uint8 height)
{
	// width <= LCD_CMAX, height <= LCD_PMAX
	uint8 i,k;
	uint8 PageHold;
	
	if (height%8 != 0)
		PageHold = height/8 + 1;
	else
		PageHold = height/8;

	for (k = LCD_PMAX; k > LCD_PMAX - PageHold; k--)
	{
		SetPA(k - 1);
		SetCA(0);
		for (i = 0; i < width; i++)
		{
			SendByte(iDat, *ptrImage++);
		}
	}
}

// Display a picture on the center of LCD Screen
void disp_center(uint8 code *ptrImage, uint8 width, uint8 height)
{
	// width <= LCD_CMAX, height <= LCD_PMAX
	uint8 i,k;
	uint8 PageHold;		// pages the rectangle 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;
	
	for (k = StartP; k > StartP - PageHold; k--)
	{
		SetPA(k - 1);
		SetCA(StartC);
		for (i = 0; i < width; i++)
		{
			SendByte(iDat, *ptrImage++);
		}
	}
}

// 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);
	NewData = 0x01 << (Ypoint%8);
	SetPA(Page);
	SetCA(Xpoint);
	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 + 1; 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 fullscreen rectangle
void RectFullscreen(void)
{
	LineH(0, 0, LCD_CMAX);
	LineH(0, LCD_LMAX - 1, LCD_CMAX);
	LineV(0, 0, LCD_LMAX);
	LineV(LCD_CMAX - 1, 0, LCD_LMAX);
}

// Draw a rectangle on LCD screen center
void Rect(uint8 width, uint8 height)
{
	uint8 i;
	uint8 PageHold = height/8;				// pages the rectangle holds
	uint8 LastDots = height%8;
	uint8 StartP = (LCD_PMAX + PageHold)/2; // Start Page
	uint8 StartC = (LCD_CMAX - width)/2; 	// Start Column
	
	SendByte(iCmd, LCD_OFF);
	SetPA(StartP - 1);
	SetCA(StartC);
	for (i = 0; i < width; i++)
	{
		if ((i == 0)||(i == width-1))
			SendByte(iDat, 0xFF);
		else
			SendByte(iDat, 0x80);
	}
	
	if (PageHold > 2)
	{
		for (i = StartP - 2; i > StartP - PageHold; i--)
		{
			SetPA(i);
			SetCA(StartC);
			SendByte(iDat, 0xFF);
			SetCA(StartC + width -1);
			SendByte(iDat, 0xFF);
		}
	}
	
	SetPA(StartP - PageHold);
	SetCA(StartC);
	for (i = 0; i < width; i++)
	{
		if ((i == 0)||(i == width-1))
		{
			if (LastDots != 0)
				SendByte(iDat, 0xFF << (8 - LastDots));
			else
				SendByte(iDat, 0xFF);
		}
		else
		{
			if (LastDots != 0)
				SendByte(iDat, 0x01 << (8 - LastDots));
			else
			{
				if (height == 8)
					SendByte(iDat, 0x81);
				else
					SendByte(iDat, 0x01);
			}
		}
	}
	SendByte(iCmd, LCD_ON);
}

// Draw a table with specific rows and cols
void Table(uint8 Rows, uint8 Cols)
{
	uint8 Hi, Vi, i;
	Hi = LCD_CMAX / Cols;
	Vi = LCD_LMAX / Rows;
	
	for (i = 0; i < Rows + 1; i++)
	{
		LineH(0, i*Vi, LCD_CMAX);
	}
	for (i = 0; i < Cols + 1; i++)
	{
		LineV(i*Hi, 0, LCD_LMAX);
	}
	LineV(LCD_CMAX - 1, 0, LCD_LMAX);
}

// Play a cascade animation
void Cascade(void)
{
	uint8 i,k;
	for (i = 0; i < LCD_LMAX; i++)
	{
		for (k = 0; k < LCD_CMAX; k += 2)
		{
			Point(k, i);
			Point(k, i + 64);
		}
		DelayUs(10000);
	}
}

⌨️ 快捷键说明

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