亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? lcd-color.cpp

?? LCD using AVR controller
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
{
	/* note: this could call FillRect to save some code space, but
	   this is a bit faster (less error-checking needed), and this
	   function is called a lot... */

	if (x >= dxLCDScreen || y >= dyLCDScreen)	// completely off-screen
		return;

	/* convert to LCD coordinates (so the variables really should
	   be xl/yl from here down...) */
	x += xlMin;
	y += ylMin;
	WriteCommand(lctCmd, PASET);	// Page Address Set
	WriteCommand(lctData, y);
	WriteCommand(lctData, y);
	WriteCommand(lctCmd, CASET);	// Column Address Set
	WriteCommand(lctData, x);
	WriteCommand(lctData, x);
	WriteCommand(lctCmd, RAMWR);	// Memory Write
	WriteCommand(lctData, clr);
}

/* draw a solid/filled rectangle with its upper left corner at (x, y),
   with the given width, height, and color */
void LCD::FillRect(uchar x, uchar y, uchar dx, uchar dy, uchar clr) const
{
	uint cpx;

	cpx = CpxSetAndValidateLCDRect(x, y, dx, dy);
	while (cpx-- > 0)
		WriteCommand(lctData, clr);
}

/* outline a rectangle with its upper left corner at (x, y),
   with the given width, height, and color */
void LCD::FrameRect(uchar x, uchar y, uchar dx, uchar dy, uchar clr) const
{
	FillRect(x, y, dx, 1, clr);			// top
	FillRect(x, y + dy -1, dx, 1, clr);	// bottom
	FillRect(x, y, 1, dy, clr);			// left
	FillRect(x + dx - 1, y, 1, dy, clr);// right
}

/* helper for DrawLine */
inline void Swap(uchar *px, uchar *py)
{
	uchar t;
	t = *px; *px = *py; *py = t;
}

/* draw a line from (x1, y1) to (x2, y2) */
void LCD::DrawLine(uchar x1, uchar y1, uchar x2, uchar y2, uchar clr) const
{
	uchar dx, dy;
	char dyStep;
	bool fMirror;
	int calc;

	/* handle simple horizontal / vertical lines */
	if (x1 == x2)
	{
		if (y1 > y2)	// swap values
			Swap(&y1, &y2);
		FillRect(x1, y1, 1, y2 - y1, clr);
		return;
	}
	if (y1 == y2)
	{
		if (x1 > x2)	// swap values
			Swap(&x1, &x2);
		FillRect(x1, y1, x2 - x1, 1, clr);
		return;
	}

	/* set up parameters */
	dx = Abs((int)x2 - (int)x1);
	dy = Abs((int)y2 - (int)y1);
	/* make sure we travel along longer side; if necessary,
	   we'll flip X and Y (here and below when drawing),
	   effectively mirroring along the line y=x */
	if ((fMirror = dy > dx) != fFalse)
	{
		/* swap X-Y */
		Swap(&x1, &y1);
		Swap(&x2, &y2);
		Swap(&dx, &dy);
	}
	/* start at the leftmost point */
	if (x1 > x2)
	{
		/* swap points */
		Swap(&x1, &x2);
		Swap(&y1, &y2);
	}
	/* rising or falling? */
	dyStep = y1 < y2 ? 1 : -1;

	/*
	normalized system: line at (0,0) positive slope to (r, s) [geometry coordinates]
		y = mx + b         m = s / r, b = 0     =>   ry = sx
	for each point x along line, y will stay the same as prev or change to y + 1
		ry = sx      or    r (y + 1) = sx
	choose left-side value that is closest to sx; change y if
		r (y + 1) - sx    <    sx - ry
	which simplifies to
		r - 2 (sx - ry) < 0
	the inequality will hold if we divide by two (accounting for integer math),
	so we can use:
		r/2 - sx + ry < 0
	at start, x = y = 0, left side is just r/2
	each iteration, x increases, which subtracts another s (from right side)
	when y increases, that adds another r (to right side)
	*/
	/* draw the line */
	calc = dx >> 1;
	while (x1 <= x2)
	{
		if (fMirror)
			ColorPixel(y1, x1, clr);
		else
			ColorPixel(x1, y1, clr);
		/* move to next x value */
		++x1;
		calc -= dy;
		/* see if should change y value */
		if (calc < 0)
		{
			y1 += dyStep;
			calc += dx;
		}
	}
}

/* calculates 1/8 circle and reflects/rotates to draw full circle */
void LCD::FrameCircle(uchar xCenter, uchar yCenter, uchar r, uchar clr) const
{
	uchar x, y;
	int calc;

	/* we'll draw pixels starting at (r, 0) and going counter-clockwise
	   (viewed in geometric space, not screen coordinates), rotating
	   and reflecting to fill in 8 sections at once, so we're done
	   when x == y (1/8 of circle calculated).
	   as we traverse that arc, we'll always move either up or up-left,
	   figure out which one is closer to the correct location;
	   change x if:
		  r^2 - left pixel x^2+y^2   <    right pixel x^2+y^2 - r^2
		  r^2 - ((x - 1)^2 + y^2)    <    x^2 + y^2 - r^2
		  r2 - (x2 - 2*x + 1 + y2)   <    x2 + y2 - r2
		  r2 - x2 - y2 + 2x - 1      <    x2 + y2 - r2
		  2r2 - 2x2 - 2y2 + 2x       <    1
		  r2 - x2 - y2 + x           <    1/2
		     (only int < 1/2 is 0 or negative)
		  r2 - x2 - y2 + x           <=   0
	   at beginning, x = r, y = 0, so left side is just x
	   when increment y, y^2 term increases by 2y-1 (so term decreases)
	   when decrement x, x^2 term decreases by 2x+1 (so term increases)
	   */

	x = r;
	y = 0;
	calc = x;

	while (x >= y)
	{
		/* set pixel at current locations */
		/* (negative values will become large pos numbers and get rejected) */
		ColorPixel(xCenter + x, yCenter + y, clr);
		ColorPixel(xCenter + x, yCenter - y, clr);
		ColorPixel(xCenter - x, yCenter + y, clr);
		ColorPixel(xCenter - x, yCenter - y, clr);
		ColorPixel(xCenter + y, yCenter + x, clr);
		ColorPixel(xCenter + y, yCenter - x, clr);
		ColorPixel(xCenter - y, yCenter + x, clr);
		ColorPixel(xCenter - y, yCenter - x, clr);
		/* should next pixel be up or up-left? */
		++y;			// move up
		calc -= 2 * y - 1;
		if (calc <= 0)	// move left?
		{
			--x;
			calc += 2 * x + 1;
		}
	}
}

/* calculates 1/8 circle and reflects/rotates to draw full circle;
   see FrameCircle for calc explanation */
void LCD::FillCircle(uchar xCenter, uchar yCenter, uchar r, uchar clr) const
{
	uchar x, y;
	int calc;
	uchar xT, d;

	x = r;
	y = 0;
	calc = x;

	while (x >= y)
	{
		/* if circle extends off left side, need to handle it here (no
		   negatives, so those values become large pos values and get
		   rejected by FillRect) */
		if (x <= xCenter)
		{
			xT = xCenter - x;
			d = 2 * x;
		}
		else
		{
			xT = 0;
			/* 2x - (x - xCenter) = x + xCenter */
			d = x + xCenter;
		}
		FillRect(xT, yCenter + y, d, 1, clr);
		FillRect(xT, yCenter - y, d, 1, clr);

		if (y <= xCenter)
		{
			xT = xCenter - y;
			d = 2 * y;
		}
		else
		{
			xT = 0;
			/* 2y - (y - xCenter) = y + xCenter */
			d = y + xCenter;
		}
		FillRect(xT, yCenter + x, d, 1, clr);
		FillRect(xT, yCenter - x, d, 1, clr);

		/* should next pixel be up or up-left? */
		++y;			// move up
		calc -= 2 * y - 1;
		if (calc <= 0)	// move left?
		{
			--x;
			calc += 2 * x + 1;
		}
	}
}

/* draw the specified bitmap (located in flash memory) at the given
   coordinates (upper left corner); the first two bytes of the memory
   specify the width and height, with remaining bytes as 8-bit color
   values; will not draw anything if not enough room for full image */
void LCD::ShowBitmap(const uchar *pab, uchar x, uchar y) const
{
	uchar dz[2], clr;
	uint cpx;

	memcpy_P(dz, pab, 2 * sizeof(uchar));
	pab += 2;
	cpx = CpxSetAndValidateLCDRect(x, y, dz[0], dz[1]);
	if (cpx != (uint)dz[0] * dz[1])
		return;

	while (cpx-- > 0)
	{
		memcpy_P(&clr, pab++, sizeof(uchar));
		WriteCommand(lctData, clr);
	}
}

/*
*	LCD setup
*/

/* sets "volume" for the LCD, which is essentially a brightness
   level for the LED backlight;
   ratio: 0-7, "resistance ratio of built-in voltage regulating resistor" 
      this is a coarse setting
   volume: 0-63, "electronic volume value"
      this will fine-tune the brightness
   technique -- find a ratio value that works well, then tune volume */
void LCD::SetVolume(uchar ratio, uchar volume) const
{
	WriteCommand(lctCmd, VOLCTR);	// Electronic Volume Control (LCD brightness)
	WriteCommand(lctData, volume & 0x3f);
	WriteCommand(lctData, ratio & 0x03);
}

void LCD::IncVolumn() const
{
	WriteCommand(lctCmd, VOLUP);	// Increment Electronic Control
}

void LCD::DecVolumn() const
{
	WriteCommand(lctCmd, VOLDOWN);	// Decrement Electronic Control
}

/*
*	helper functions
*/

/* send an instruction to the LCD */
void LCD::WriteCommand(uchar lct, uchar ch) const
{
	/* enable chip */
	s_poutE->SetLow();

	/* send first bit manually */
	/* set data bit for command or data */
	if (lct == lctCmd)
		s_poutMOSI->SetLow();
	else
		s_poutMOSI->SetHigh();
	/* pulse clock */
	s_poutSCK->SetHigh();
	asm("nop");		// just to be sure...
	s_poutSCK->SetLow();

	/* enable SPI for remaining 8 bits */
	SetBit(regSPCR, bitSPE);
	regSPDR = ch;
	/* wait for transmission to complete */
	while (bit_is_clear(regSPSR, bitSPIF))
		;
	ClearBit(regSPCR, bitSPE);	// disable it so we can send manually...
	
	/* signal done with this transmit */
	s_poutE->SetHigh();
}

/* ensures that rectangle is fully on screen and sets LCD for drawing there;
   returns number of pixels available to fill */
uint LCD::CpxSetAndValidateLCDRect(uchar x, uchar y, uchar dx, uchar dy) const
{
	uchar xlFirst, ylFirst, xlLast, ylLast;	// LCD coordinates

	/* check upper left corner */
	/* (x and y aren't too low since unsigned can't be < 0!) */
	if (x >= dxLCDScreen || y >= dyLCDScreen)	// completely off-screen
		return 0;

	/* check lower right corner */
	if (x + dx > dxLCDScreen)
		dx = dxLCDScreen - x;
	if (y + dy > dyLCDScreen)
		dy = dyLCDScreen - y;

	/* convert to LCD coordinates */
	xlLast = (xlFirst = xlMin + x) + dx - 1;
	ylLast = (ylFirst = ylMin + y) + dy - 1;

	/* note: for PASET/CASET, docs say that start must be < end,
	   but <= appears to be OK; end is a "last" not "lim" value */
	WriteCommand(lctCmd, PASET);	// Page Address Set
	WriteCommand(lctData, ylFirst);	// start page (line)
	WriteCommand(lctData, ylLast);	// end page
	WriteCommand(lctCmd, CASET);	// Column Address Set
	WriteCommand(lctData, xlFirst);	// start address
	WriteCommand(lctData, xlLast);	// end address
	WriteCommand(lctCmd, RAMWR);	// Memory Write

	return (uint)dx * dy;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区三区免费| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 久久久久国产精品厨房| 亚洲婷婷在线视频| 激情亚洲综合在线| 91福利精品第一导航| 国产亚洲欧美日韩日本| 夜夜嗨av一区二区三区网页| 国产suv精品一区二区883| 在线观看91精品国产麻豆| 欧美国产视频在线| 九一九一国产精品| 欧美日韩国产三级| 亚洲欧美偷拍卡通变态| 国产成人aaaa| 久久嫩草精品久久久久| 日本不卡中文字幕| 欧美男女性生活在线直播观看| 亚洲欧洲精品一区二区精品久久久| 久久精品国产在热久久| 在线91免费看| 三级在线观看一区二区| 91精品国产综合久久精品| 亚洲欧美日韩综合aⅴ视频| 国产精选一区二区三区| 欧美精品一区二区三区一线天视频| 污片在线观看一区二区| 欧美日韩二区三区| 亚洲国产成人av网| 欧美福利视频一区| 午夜久久久久久久久久一区二区| 欧美最新大片在线看| 亚洲综合小说图片| 色999日韩国产欧美一区二区| 亚洲欧洲www| 91传媒视频在线播放| 一区二区三区中文在线| 欧美在线高清视频| 午夜在线成人av| 欧美一区二区三区的| 久久成人久久鬼色| 国产蜜臀av在线一区二区三区| 国产不卡视频在线播放| 国产精品久久一级| 在线观看av不卡| 石原莉奈在线亚洲二区| 日韩欧美精品在线视频| 国产一区福利在线| 国产精品青草综合久久久久99| www.久久精品| 亚洲一区二区三区影院| 在线播放中文字幕一区| 久久国产成人午夜av影院| 久久午夜老司机| 99视频精品在线| 亚洲成人手机在线| 精品国产一区二区亚洲人成毛片| 国产成人av一区二区三区在线观看| 亚洲国产精品99久久久久久久久 | 26uuuu精品一区二区| 高清免费成人av| 亚洲免费伊人电影| 欧美一级高清片在线观看| 国产不卡视频一区二区三区| 亚洲精选在线视频| 欧美大黄免费观看| 91在线看国产| 日韩精品高清不卡| 国产欧美日韩中文久久| 91成人看片片| 国产露脸91国语对白| 男男成人高潮片免费网站| 国产三级一区二区| 欧美在线观看视频在线| 国产福利一区二区三区在线视频| 亚洲欧美视频一区| 久久久99精品免费观看不卡| 在线看一区二区| 粉嫩av一区二区三区在线播放| 亚洲一区二区三区影院| 国产欧美视频在线观看| 欧美一区二区性放荡片| 色呦呦国产精品| 国产乱码精品一区二区三区忘忧草 | 日韩欧美123| 99国产精品久久久| 国产毛片精品视频| 午夜久久久久久电影| 成人欧美一区二区三区黑人麻豆| 日韩视频不卡中文| 欧美写真视频网站| 99久久精品国产麻豆演员表| 韩国精品在线观看| 石原莉奈在线亚洲三区| 悠悠色在线精品| 最新日韩在线视频| 中文字幕av一区二区三区| 精品区一区二区| 欧美一区二区二区| 欧美天天综合网| 色嗨嗨av一区二区三区| jiyouzz国产精品久久| 国产精品一区在线观看乱码| 人人精品人人爱| 丝袜亚洲另类欧美| 五月综合激情网| 亚洲午夜一区二区三区| 伊人开心综合网| 亚洲欧美日韩在线播放| 亚洲欧洲中文日韩久久av乱码| 国产精品久久久久aaaa| 国产欧美日韩不卡免费| 久久久高清一区二区三区| 精品国产精品一区二区夜夜嗨| 91精品国产丝袜白色高跟鞋| 欧美精品xxxxbbbb| 欧美精品久久99久久在免费线 | 一区二区三区av电影 | 午夜精品视频在线观看| 亚洲一区二区三区影院| 亚洲一区二区三区四区在线免费观看 | 日本一区二区高清| 精品久久国产老人久久综合| 日韩欧美国产三级电影视频| 日韩三级.com| 精品对白一区国产伦| 久久久国产精华| 中文字幕第一区二区| 最新热久久免费视频| 亚洲国产精品久久艾草纯爱| 午夜国产精品一区| 久久99久久精品| 国产精品99久久久久久久女警| 丁香一区二区三区| 91视频免费观看| 欧美午夜一区二区三区免费大片| 在线观看91精品国产麻豆| 欧美tk—视频vk| 中文字幕二三区不卡| 亚洲一区国产视频| 美腿丝袜亚洲综合| 国产不卡高清在线观看视频| 91麻豆国产福利精品| 欧美精品三级日韩久久| 久久精品夜夜夜夜久久| 亚洲美女一区二区三区| 麻豆91在线看| 不卡影院免费观看| 8v天堂国产在线一区二区| 久久久99久久| 亚洲v中文字幕| 岛国精品在线观看| 国产性天天综合网| 国产精品进线69影院| 午夜伦欧美伦电影理论片| 国产乱码精品1区2区3区| 99re这里都是精品| 精品日韩av一区二区| 亚洲人快播电影网| 精品一区二区三区久久| 91无套直看片红桃| 久久久三级国产网站| 亚洲国产乱码最新视频| 福利电影一区二区| 欧美电影一区二区三区| 日韩美女视频一区二区| 麻豆国产欧美日韩综合精品二区| youjizz久久| 精品欧美一区二区三区精品久久| 18成人在线观看| 黄色日韩网站视频| 欧美日韩电影一区| 一色屋精品亚洲香蕉网站| 九九九精品视频| 欧美午夜电影在线播放| 国产欧美一区二区精品性| 美国毛片一区二区三区| 欧美日韩一区二区欧美激情| 欧美激情综合网| 国产一区二区三区在线观看免费| 欧美日韩二区三区| 一区二区三区四区高清精品免费观看 | 一本久久a久久精品亚洲| 2024国产精品视频| 奇米888四色在线精品| 欧美探花视频资源| 亚洲精品视频在线观看免费| www.色综合.com| 国产亚洲综合av| 国产福利一区二区三区视频在线 | 久久久国产午夜精品| 蜜桃久久av一区| 欧美一区二区美女| 日韩精品久久久久久| 91精品国产手机| 免费视频最近日韩| 日韩欧美中文字幕制服| 麻豆国产精品777777在线| 欧美一级片免费看| 日本视频一区二区三区|