📄 sys_lcd.c.svn-base
字号:
****************************************************************************/
void LCD_ChangeMode(U8 mode)
{
LCDdspMode=mode;
}
/****************************************************************************
函数名称:SetPixel()
说明: 图形模式下设置某象素点的灰度级。
调用函数:无
输入参数:x 该象素横坐标
y 该象素纵坐标
color 要设置的灰度级
输出参数:无
****************************************************************************/
void SetPixel(U32 x,U32 y,U8 color)
{
U32* Pixel_Addr=pLCDBuffer16+y*40+x/8;
*(Pixel_Addr)=( *(Pixel_Addr) & ~(0xf0000000>>((x)%8)*4) )
| ( (color)<<((8-1-((x)%8))*4) );
}
/****************************************************************************
函数名称:ClearScr()
说明: 图形模式下清除屏幕。
调用函数:SetPixel()
输入参数:无
输出参数:无
****************************************************************************/
void ClearScr(void)
{
int i,j;
for(j=0;j<LCDHEIGHT;j++)
for(i=0;i<LCDWIDTH;i++)
SetPixel(i,j,0);
}
/****************************************************************************
函数名称:DrawLine()
说明: 在屏幕上画一条直线。
调用函数:SetPixel()
输入参数:x1 起点象素横坐标
y1 起点象素纵坐标
x2 终点象素横坐标
y2 终点象素纵坐标
color 要画的灰度级
输出参数:无
****************************************************************************/
void DrawLine(U32 x1,U32 y1,U32 x2,U32 y2,U8 color)
{
S32 dx,dy,e;
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
SetPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
SetPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 8/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
SetPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
SetPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
SetPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
SetPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
SetPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
SetPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
/****************************************************************************
函数名称:DrawRect()
说明: 在屏幕上画一个空心矩形。
调用函数:DrawLine()
输入参数:x1 矩形对角线起点象素横坐标
y1 矩形对角起点象素纵坐标
x2 矩形对角终点象素横坐标
y2 矩形对角终点象素纵坐标
color 要画的灰度级
输出参数:无
****************************************************************************/
void DrawRect(U32 x1,U32 y1,U32 x2,U32 y2,U8 color)
{
DrawLine(x1,y1,x2,y1,color);
DrawLine(x2,y1,x2,y2,color);
DrawLine(x1,y2,x2,y2,color);
DrawLine(x1,y1,x1,y2,color);
}
/****************************************************************************
函数名称:FillRect()
说明: 在屏幕上画一个填充矩形。
调用函数:DrawLine()
输入参数:x1 矩形对角线起点象素横坐标
y1 矩形对角起点象素纵坐标
x2 矩形对角终点象素横坐标
y2 矩形对角终点象素纵坐标
color 要画的灰度级
输出参数:无
****************************************************************************/
void FillRect(U32 x1,U32 y1,U32 x2,U32 y2,U8 color)
{
S32 i;
for(i=x1;i<=x2;i++)
DrawLine(i,y1,i,y2,color);
}
/****************************************************************************
函数名称:DrawCircle()
说明: 在屏幕上画一个空心的圆。
调用函数:SetPixel()
输入参数:x 圆心象素横坐标
y 圆心象素纵坐标
r 圆的半径
color 要画的灰度级
输出参数:无
****************************************************************************/
void DrawCircle(U32 x, U32 y, U32 r,U8 color)
{
S32 i=x,j=y+r,tempi,tempj;
S32 deltax=3,deltay=2-r-r,d=1-r;
/*以下为中点画圆法,计算一个1/8圆弧,再根据对称性画出一个圆*/
if(i>=0&&i<320&&j>=0&&j<240)
SetPixel(i,j,color);
if((int)(i-r)>=0&&(i-r)<320&&(int)(j-r)>=0&&(j-r)<240)
SetPixel(i-r,j-r,color);
if((int)(i+r)>=0&&(i+r)<320&&(int)(j-r)>=0&&(j-r)<240)
SetPixel(i+r,j-r,color);
if(i>=0&&i<320&&(int)(j-r-r)>=0&&(j-r-r)<240)
SetPixel(i,j-r-r,color);
while((i-x)<(j-y))
{
if(d<0)
{
d+=deltax;
deltax+=2;
i++;
}
else
{
d+=(deltax+deltay);
deltax+=2;deltay+=2;
i++;j--;
}
tempi=i;tempj=j; //1
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempj=y+y-j; //4
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempi=x-y+j;tempj=y-x+i; //2
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempj=y+x-i; //3
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempi=x+x-i;tempj=y+y-j; //5
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempj=j; //8
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempi=x+y-j;tempj=y+x-i; //6
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
tempj=y-x+i; //7
if(tempi>=0&&tempi<320&&tempj>=0&&tempj<240)
SetPixel(tempi,tempj,color);
}
}
/****************************************************************************
函数名称:FillCircle()
说明: 在屏幕上画一个填充的圆。
调用函数:DrawLine()
SetPixel()
输入参数:x 圆心象素横坐标
y 圆心象素纵坐标
r 圆的半径
color 要画的灰度级
输出参数:无
****************************************************************************/
void FillCircle(U32 x,U32 y,U32 r,U8 color)
{
S32 i=x,j=y+r,tempi,tempj;
S32 deltax=3,deltay=2-r-r,d=1-r,temp;
tempi=i;tempj=j;temp=y+y-tempj;
if(tempi>=0&&tempi<320){
if(tempj>=240)tempj=240;
if(temp<0)temp=0;
DrawLine(tempi,temp,tempi,tempj,color);}
if((int)(i-r)>=0&&(i-r)<320&&(int)(j-r)>=0&&(j-r)<240)
SetPixel(i-r,j-r,color);
if((int)(i+r)>=0&&(i+r)<320&&(int)(j-r)>=0&&(j-r)<240)
SetPixel(i+r,j-r,color);
while((i-x)<(j-y))
{
if(d<0)
{
d+=deltax;
deltax+=2;
i++;
}
else
{
d+=(deltax+deltay);
deltax+=2;deltay+=2;
i++;j--;
}
tempi=i;tempj=j;temp=y+y-tempj;
if(tempi>=0&&tempi<320){
if(tempj>=240)tempj=240;
if(temp<0)temp=0;
DrawLine(tempi,temp,tempi,tempj,color);}
tempi=x-y+j;tempj=y-x+i;temp=y+y-tempj;
if(tempi>=0&&tempi<320){
if(tempj>=240)tempj=240;
if(temp<0)temp=0;
DrawLine(tempi,temp,tempi,tempj,color);}
tempi=x+x-i;tempj=j;temp=y+y-tempj;
if(tempi>=0&&tempi<320){
if(tempj>=240)tempj=240;
if(temp<0)temp=0;
DrawLine(tempi,temp,tempi,tempj,color);}
tempi=x+y-j;tempj=y-x+i;temp=y+y-tempj;
if(tempi>=0&&tempi<320){
if(tempj>=240)tempj=240;
if(temp<0)temp=0;
DrawLine(tempi,temp,tempi,tempj,color);}
}
}
/****************************************************************************
函数名称:ShowBmp()
说明: 在屏幕上显示一幅图像。
调用函数:SetPixel()
输入参数:x 起点象素横坐标
y 起点象素纵坐标
bmpname[] 该图像对应的数组名
bmpxsize 该图像的宽度
bmpysize 该图像的高度
输出参数:无
****************************************************************************/
void ShowBmp(U32 x,U32 y,U8 bmpname[],U32 bmpxsize,U32 bmpysize)
{
S32 i,j,k=0,tempi,tempj,temp;
tempi=x+bmpxsize;
if(tempi>LCDWIDTH){
temp=tempi-LCDWIDTH;
tempi=LCDWIDTH;
}
tempj=y+bmpysize;
if(tempj>LCDHEIGHT){
tempj=LCDHEIGHT;
}
for(j=y ; j <tempj; j++ )
{
for(i=x; i <tempi; i+=2 )
{
k=((j-y)*bmpxsize+(i-x))/2;
SetPixel( (i+1), j, (bmpname[k]&0x0f) );
SetPixel( (i+0), j, (bmpname[k]>>4) );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -