Drawing a line on ILI9340 display

Status
Not open for further replies.

aliyesami

Full Member level 6
Joined
Jan 7, 2010
Messages
369
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
USA
Activity points
4,190
I am struggling with programming this display in AVR , need help.
starting with just drawing a simple line , can someone look at the code and tell me what iam doing wrong ? I am using the TFT library for arduino and adapting it to AVR.

thanks

Code:
/*-----------------------------------------------------------------------------------
** TFT Display routines 
** ILI9340 controller 
-----------------------------------------------------------------------------------
*/
void setCol(int16_t StartCol,int16_t EndCol)
{
	comm_out(0x2A);
	upperNibble = StartCol >> 4;
	lowerNibble = StartCol & 0x0f;
	data_out(upperNibble);
	data_out(lowerNibble);
	upperNibble = EndCol >> 4;
	lowerNibble = EndCol & 0x0f;
	data_out(upperNibble);
	data_out(lowerNibble);
}


void setPage(int16_t StartPage,int16_t EndPage)
{
	comm_out(0x2B);
	upperNibble = StartPage >> 4;
	lowerNibble = StartPage & 0x0f;
	data_out(upperNibble);
	data_out(lowerNibble);
	upperNibble = EndPage >> 4;
	lowerNibble = EndPage & 0x0f;
	data_out(upperNibble);
	data_out(lowerNibble);
}

void setXY(int16_t poX, int16_t poY)
{
	setCol(poX, poX);
	setPage(poY, poY);
	comm_out(0x2c);
}

void setPixel(int16_t poX, int16_t poY,int16_t color)
{
	setXY(poX, poY);
	data_out(color);
}

void drawLine( int16_t x0,int16_t y0,int16_t x1, int16_t y1,int16_t color)
{

	int x = x1-x0;
	int y = y1-y0;
	int dx = abs(x), sx = x0<x1 ? 1 : -1;
	int dy = -abs(y), sy = y0<y1 ? 1 : -1;
	int err = dx+dy, e2;                                                /* error value e_xy             */
	for (;;){                                                           /* loop                         */
		setPixel(x0,y0,color);
		e2 = 2*err;
		if (e2 >= dy) {                                                 /* e_xy+e_x > 0                 */
			if (x0 == x1) break;
			err += dy; x0 += sx;
		}
		if (e2 <= dx) {                                                 /* e_xy+e_y < 0                 */
			if (y0 == y1) break;
			err += dx; y0 += sy;
		}
	}

}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…