2. 繪圖函數的擴展 要實現繪圖功能,首先是添加畫點函數,然后是添加畫線函數和區域填充函數。 添加的畫點函數為: - void LCD_dotDraw(u16 X_Location, u16 Y_Location, u16 Color)
- {
- LCD_StarterSet(X_Location, Y_Location);
- LCD_WriteRAMPrior();
- LCD_WriteRAM(Color);
- }
復制代碼
添加的畫線函數為:- void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2, u16 Color)
- {
- u16 t;
- s16 xerr=0,yerr=0,delta_x,delta_y,distance;
- u16 incx,incy,uRow,uCol;
- delta_x=x2-x1;
- delta_y=y2-y1;
- uRow=x1;
- uCol=y1;
- if(delta_x>0)incx=1;
- else if(delta_x==0)incx=0;
- else { incx=-1; delta_x=-delta_x; }
-
- if(delta_y>0)incy=1;
- else if(delta_y==0)incy=0;
- else { incy=-1; delta_y=-delta_y; }
-
- if( delta_x>delta_y) distance=delta_x;
- else distance=delta_y;
-
- for(t=0;t<=distance+1;t++)
- {
- LCD_dotDraw(uRow,uCol,Color);
- xerr+=delta_x ;
- yerr+=delta_y ;
- if(xerr>distance)
- {
- xerr-=distance;
- uRow+=incx;
- }
- if(yerr>distance)
- {
- yerr-=distance;
- uCol+=incy;
- }
- }
- }
復制代碼
添加的區域填充函數:- void LCD_fill(u16 x,u16 y,u16 Height,u16 Width,u16 Color)
- {
- u16 i,j;
-
- for(j=0;j<Height;j++)
- {
- LCD_StarterSet(x,y);
- LCD_WriteRAMPrior();
- for (i = Width; i > 0; i--)
- {
- LCD_WriteRAM(Color);
- }
- x++;
- }
- }
復制代碼
有了這3個函數,后面我們在進行A/D采集時就可以輕松地實現數據的波形顯示,稍后見!
|