2. 繪圖函數(shù)的擴(kuò)展 要實(shí)現(xiàn)繪圖功能,首先是添加畫(huà)點(diǎn)函數(shù),然后是添加畫(huà)線(xiàn)函數(shù)和區(qū)域填充函數(shù)。 添加的畫(huà)點(diǎn)函數(shù)為: - void LCD_dotDraw(u16 X_Location, u16 Y_Location, u16 Color)
- {
- LCD_StarterSet(X_Location, Y_Location);
- LCD_WriteRAMPrior();
- LCD_WriteRAM(Color);
- }
復(fù)制代碼
添加的畫(huà)線(xiàn)函數(shù)為:- 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;
- }
- }
- }
復(fù)制代碼
添加的區(qū)域填充函數(shù):- 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++;
- }
- }
復(fù)制代碼
有了這3個(gè)函數(shù),后面我們?cè)谶M(jìn)行A/D采集時(shí)就可以輕松地實(shí)現(xiàn)數(shù)據(jù)的波形顯示,稍后見(jiàn)!
|