鼓捣了一晚上搞出一个基于原子哥LCD库V3.0的画坐标系图象的几个函数。
使用方法如下:
- void LCD_Plot_Init(u16 width, u16 height, u16 xUnit, u16 yUnit, u16 xOrigin, u16 yOrigin, u8 GridSwitch); //最后一个参数GridSwitch用来设置是否画栅格
- void RefreshPlot(u16 NewValue); //直接输入一个数就可以画图了
支持函数有
- typedef struct tagPlot_Init
{
u16 xOrigin;
u16 yOrigin;
u16 xUnit;
u16 yUnit;
u16 height;
u16 width;
u8 GridSwitch;
} Plot_Init;
void DrawFrame(Plot_Init PLOT_INIT); //用来绘制坐标系的外框
void DP(u16 x,u16 y,u16 color); //快速画点 其实就是给LCD_Fast_DrawPoint()套了个壳
以上部分定义在lcd.h中 在lcd.c中定义了两个全局变量,数组PLOT_NUM[]用来存放显示数据和坐标系参数结构体PLOT_INIT
具体实现代码如下
void DP(u16 x,u16 y,u16 color)
{
LCD_Fast_DrawPoint(x,y,color);
}
void LCD_Plot_Init(u16 width, u16 height, u16 xUnit, u16 yUnit, u16 xOrigin, u16 yOrigin, u8 GridSwitch){//×ø±êϵ³õʼ»¯
u16 i;
PLOT_INIT.GridSwitch=GridSwitch;
PLOT_INIT.height=height;
PLOT_INIT.width=width;
PLOT_INIT.xOrigin=xOrigin;
PLOT_INIT.yOrigin=yOrigin;
PLOT_INIT.xUnit=xUnit;
PLOT_INIT.yUnit=yUnit;
return;
}
void DrawFrame(Plot_Init PLOT_INIT){
u16 i;
//PLOT_INIT.width=width;
if(PLOT_INIT.GridSwitch){
for(i=PLOT_INIT.width/PLOT_INIT.xUnit;i>0;i--){
POINT_COLOR=LIGHTBLUE;
LCD_DrawLine(PLOT_INIT.xOrigin+i*PLOT_INIT.xUnit,PLOT_INIT.yOrigin,PLOT_INIT.xOrigin+i*PLOT_INIT.xUnit,PLOT_INIT.yOrigin-PLOT_INIT.height);
POINT_COLOR=WHITE;
LCD_Draw_Circle(PLOT_INIT.xOrigin+i*PLOT_INIT.xUnit,PLOT_INIT.yOrigin,2);
}
for(i=PLOT_INIT.height/PLOT_INIT.yUnit;i>0;i--){
POINT_COLOR=LIGHTBLUE;
LCD_DrawLine(PLOT_INIT.xOrigin,PLOT_INIT.yOrigin-i*PLOT_INIT.yUnit,PLOT_INIT.xOrigin+PLOT_INIT.width,PLOT_INIT.yOrigin-i*PLOT_INIT.yUnit);
POINT_COLOR=WHITE;
LCD_Draw_Circle(PLOT_INIT.xOrigin,PLOT_INIT.yOrigin-i*PLOT_INIT.yUnit,2);
}
}
//Draw Frame Ready
LCD_DrawLine(PLOT_INIT.xOrigin,PLOT_INIT.yOrigin,PLOT_INIT.xOrigin,PLOT_INIT.yOrigin-PLOT_INIT.height);
LCD_DrawLine(PLOT_INIT.xOrigin,PLOT_INIT.yOrigin,PLOT_INIT.xOrigin+PLOT_INIT.width,PLOT_INIT.yOrigin);
LCD_DrawLine(PLOT_INIT.xOrigin+PLOT_INIT.width,PLOT_INIT.yOrigin,PLOT_INIT.xOrigin+PLOT_INIT.width,PLOT_INIT.yOrigin-PLOT_INIT.height);
LCD_DrawLine(PLOT_INIT.xOrigin,PLOT_INIT.yOrigin-PLOT_INIT.height,PLOT_INIT.xOrigin+PLOT_INIT.width,PLOT_INIT.yOrigin-PLOT_INIT.height);
//Draw frame ready
POINT_COLOR=RED;
LCD_Draw_Circle(PLOT_INIT.xOrigin,PLOT_INIT.yOrigin,4);
POINT_COLOR=WHITE;
return;
}
void RefreshPlot(u16 NewValue){
u16 width=PLOT_INIT.width;
u16 height=PLOT_INIT.height;
u16 xOrigin=PLOT_INIT.xOrigin;
u16 yOrigin=PLOT_INIT.yOrigin;
u8 NewValueString[10];
u8 LastValueString[10];
u16 LastValue=*(PLOT_NUM+*PLOT_NUM);
u16 i;
sprintf((char*)NewValueString,"%d",NewValue);
sprintf((char*)LastValueString,"%d",*(PLOT_NUM+*PLOT_NUM));
DrawFrame(PLOT_INIT);
//ͼÏó²»ÂúÒ»ÆÁĻʱ
if(*PLOT_NUM!=width){
POINT_COLOR=BLACK;//¿ªÊ¼²Á³ý
for(i=*PLOT_NUM;i>0;i--)DP(xOrigin+i,yOrigin-*(PLOT_NUM+i),BLACK);//²Á³ýÇúÏß
LCD_ShowString(xOrigin+*PLOT_NUM+1,yOrigin-LastValue-16,120,12,12,LastValueString);//²Á³ýÊýÖµ
LCD_Draw_Circle(xOrigin+*PLOT_NUM+1,yOrigin-LastValue,1);//²Á³ý¹â±ê
LCD_Draw_Circle(xOrigin+*PLOT_NUM+1,yOrigin-LastValue,2);//²Á³ý¹â±ê
*(PLOT_NUM+*PLOT_NUM+1)=NewValue;//¸üдýÏÔʾµÄÊý¾Ý
(*PLOT_NUM)++;//¸üÐÂÊý¾ÝÊýÄ¿
POINT_COLOR=WHITE;//¿ªÊ¼»æÖÆ
for(i=*PLOT_NUM;i>0;i--){DP(xOrigin+i,yOrigin-*(PLOT_NUM+i),WHITE);}//»æÖÆÇúÏß
LCD_ShowString(xOrigin+*PLOT_NUM+1,yOrigin-NewValue-16,120,12,12,NewValueString);//»æÖÆÊýÖµ
POINT_COLOR=RED;LCD_Draw_Circle(xOrigin+*PLOT_NUM+1,yOrigin-NewValue,1);//»æÖƹâ±ê
POINT_COLOR=RED;LCD_Draw_Circle(xOrigin+*PLOT_NUM+1,yOrigin-NewValue,2);//»æÖƹâ±ê
}else{
//ͼÏóÒÑÂúÒ»ÆÁĻʱ£¬¿ªÊ¼Õû¶ÎÒƶ¯ÇúÏß
POINT_COLOR=BLACK;//¿ªÊ¼²Á³ý
for(i=width;i>0;i--)DP(xOrigin+i,yOrigin-*(PLOT_NUM+i),BLACK);//²Á³ýͼÏóµã
LCD_ShowString(xOrigin+width,yOrigin-LastValue-16,120,12,12,LastValueString);//»æÖÆÊýÖµ
LCD_Draw_Circle(xOrigin+width,yOrigin-LastValue,1);//²Á³ý¹â±ê
LCD_Draw_Circle(xOrigin+width,yOrigin-LastValue,2);//²Á³ý¹â±ê
for(i=0;i<width;i++)*(PLOT_NUM+i+1)=*(PLOT_NUM+i+2);*(PLOT_NUM+width)=NewValue; //¸üдýÏÔʾµÄÊý¾Ý
POINT_COLOR=WHITE;//¿ªÊ¼»æÖÆ
for(i=width;i>0;i--)DP(xOrigin+i,yOrigin-*(PLOT_NUM+i),WHITE);//»æÖÆͼÏóµã
LCD_ShowString(xOrigin+width,yOrigin-NewValue-16,120,12,12,NewValueString);//»æÖÆÊýÖµ
POINT_COLOR=RED;LCD_Draw_Circle(xOrigin+width,yOrigin-NewValue,1);//»æÖƹâ±ê
POINT_COLOR=RED;LCD_Draw_Circle(xOrigin+width,yOrigin-NewValue,2);//»æÖƹâ±ê
}//¸üÐÂËùÏÔʾµÄÊý¾Ý²¢»­ÐµÄÊý¾Ýµã
return;
}
哇我的缩进和注释全没了
见附件。
LCD.zip
(28.46 KB, 下载次数: 25)
2019-1-30 18:54 上传
点击文件名下载附件
一周热门 更多>