/************************************************* 函数名:LCD_DrawPoint 功能:画一个点 入口参数:无 返回值:无 *************************************************/ void Gui_DrawPoint(u16 x,u16 y,u16 Data) { Lcd_SetXY(x,y); Lcd_WriteData(Data>>8); Lcd_WriteData(Data); }
unsigned int Lcd_ReadPoint(uint16_t x, uint16_t y) { unsigned int Data; Lcd_SetXY(x, y); Lcd_ReadData(); Data=Lcd_ReadData(); //Lcd_WriteData(Data); return Data; }
/***************************************** TFT ******************************************/ unsigned int Lcd_ReadPoint(u16 x,u16 y) { unsigned int Data; Lcd_SetXY(x,y); //Lcd_ReadData();// //Data=Lcd_ReadData(); Lcd_WriteData(Data); return Data; }
void Lcd_Puts(unsigned char x,unsigned char y, unsigned char *str) //向1602写一个字符串 { unsigned char * string = str; Lcd_SetXY(x,y); while(*string) { Lcd_Write_Data(*string); string++; } }
/** * @brief Gui draw Line. * @param x0,y0,x1,y1,Color. * @retval None */ void Gui_DrawLine(uint16_t x0, uint16_t y0,uint16_t x1, uint16_t y1,uint16_t Color) { /* -difference in x's -difference in y's -dx,dy * 2 -amount in pixel space to move during drawing -amount in pixel space to move during drawing -the discriminant i.e. error i.e. decision variable -used for looping */ int dx,dy,dx2,dy2,x_inc,y_inc,error,index; LCD_CS_CLR; Lcd_SetXY(x0,y0); /* Calculate X distance */ dx = x1-x0; /* Calculate Y distance */ dy = y1-y0; if (dx>=0) { x_inc = 1; } else { x_inc = -1; dx = -dx; } if (dy>=0) { y_inc = 1; } else { y_inc = -1; dy = -dy; } dx2 = dx << 1; dy2 = dy << 1; if (dx > dy) { /* initialize error */ error = dy2 - dx; /* draw the line */ for (index=0; index <= dx; index++) { Gui_DrawPoint(x0,y0,Color); /* test if error has overflowed */ if (error >= 0) { error-=dx2; /* move to next line */ y0+=y_inc; } /* adjust the error term */ error+=dy2; /* move to the next pixel */ x0+=x_inc; } } else { /* initialize error term */ error = dx2 - dy; /* draw the linedraw the line*/ for (index=0; index <= dy; index++) { /* set the pixel */ Gui_DrawPoint(x0,y0,Color); /* test if error overflowed */ if (error >= 0) { error-=dy2; /* move to next line */ x0+=x_inc; } /* adjust the error term */ error+=dx2; /* move to the next pixel */ y0+=y_inc; } } LCD_CS_SET; }
//画线函数,使用Bresenham 画线算法 void Gui_DrawLine(u16 x0, u16 y0,u16 x1, u16 y1,u16 Color) { int dx, // difference in x's dy, // difference in y's dx2, // dx,dy * 2 dy2, x_inc, // amount in pixel space to move during drawing y_inc, // amount in pixel space to move during drawing error, // the discriminant i.e. error i.e. decision variable index; // used for looping Lcd_SetXY(x0,y0); dx = x1-x0;//计算x距离 dy = y1-y0;//计算y距离 if (dx>=0) { x_inc = 1; } else { x_inc = -1; dx = -dx; } if (dy>=0) { y_inc = 1; } else { y_inc = -1; dy = -dy; } dx2 = dx << 1; dy2 = dy << 1; if (dx > dy)//x距离大于y距离,那么每个x轴上只有一个点,每个y轴上有若干个点 {//且线的点数等于x距离,以x轴递增画点 // initialize error term error = dy2 - dx; // draw the line for (index=0; index <= dx; index++)//要画的点数不会超过x距离 { //画点 Gui_DrawPoint(x0,y0,Color); // test if error has overflowed if (error >= 0) //是否需要增加y坐标值 { error-=dx2; // move to next line y0+=y_inc;//增加y坐标值 } // end if error overflowed // adjust the error term error+=dy2; // move to the next pixel x0+=x_inc;//x坐标值每次画点后都递增1 } // end for } // end if |slope| <= 1 else//y轴大于x轴,则每个y轴上只有一个点,x轴若干个点 {//以y轴为递增画点 // initialize error term error = dx2 - dy; // draw the line for (index=0; index <= dy; index++) { // set the pixel Gui_DrawPoint(x0,y0,Color); // test if error overflowed if (error >= 0) { error-=dy2; // move to next line x0+=x_inc; } // end if error overflowed // adjust the error term error+=dx2; // move to the next pixel y0+=y_inc; } // end for } // end else |slope| > 1 }
/** * @brief Draw a point on the lcd. * @param x,y,Data * @retval None */ void Gui_DrawPoint(uint16_t x,uint16_t y,uint16_t Data) { Lcd_SetXY(x,y); Lcd_WriteData(Data>>8); Lcd_WriteData(Data); }