void LCD_DisplayChar(u8 Line, u8 Column, u8 Ascii)
{
LCD_DrawChar(Line, Column, &g_ucAscii8x16[Ascii * 16]);
}本文引用地址:http://m.butianyuan.cn/article/201611/321618.htm
void LCD_DisplayPoint(u8 u8Xpos, u8 u8Ypos, vu16 u16Color)
{
LCD_WriteReg(0x2a);//XS15-XS8
LCD_WriteDat(0);
LCD_WriteDat(u8Xpos);//XS7-XS0(X start address)
LCD_WriteDat(0);//XE15-XE8
LCD_WriteDat(u8Xpos);//XE7-XE0(X end address)
//row address set (RASET)
LCD_WriteReg(0x2b);//YS15-YS8
LCD_WriteDat(0);//YS7-YS0(Y start
LCD_WriteDat(u8Ypos);//YE15-YE8
LCD_WriteDat(0);
LCD_WriteDat(u8Ypos);//YE7-YE0(Y end address)
LCD_WriteReg(0x2c);
LCD_WriteDat(u16Color>>8);
LCD_WriteDat(u16Color&0xff);
}
void Xiexian(u8 x1,u8 y1,u8 x2,u8 y2,u16 color)
{
u16 t;
u16 xerr=0,yerr=0,delta_x,delta_y,distance;
u16 incx,incy;
u16 row,col;
delta_x = x2-x1;//計算坐標增量
delta_y = y2-y1;
col=x1;
row=y1;
if(delta_x>0) incx=1;//設(shè)置單步方向
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_DisplayPoint(col,row,color);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
col+=incx;
}
if(yerr>distance)
{
yerr-=distance;
row+=incy;
}
}
}
void LCD_SelectRegion(u8 u8XBpos, u8 u8YBpos, u8 u8XEpos, u8 u8YEpos)
{
LCD_WriteReg(0x2a);//column address set
LCD_WriteDat(0);//XS15-XS8
LCD_WriteDat(u8XBpos);//XS7-XS0 //X Start ADD
LCD_WriteDat(0);//XE15-XE8
LCD_WriteDat(u8XEpos);//XE7-XE0 //X End ADD
LCD_WriteReg(0x2b);//row address set
LCD_WriteDat(0);//YS15-YS8
LCD_WriteDat(u8YBpos);//YS7-YS0 //Y Start ADD
LCD_WriteDat(0);//YE15-YE8
LCD_WriteDat(u8YEpos);//YE7-YE0 //Y End ADD
LCD_WriteReg(0x2c);
}
void LCD_DrawCircle(u8 Xpos, u8 Ypos, u8 Radius)
//使用格式:(X坐標,y坐標,半徑)
{
s32D;
u32CurX;
u32CurY;
D = 3 - (Radius << 1);
CurX = 0;
CurY = Radius;
//LCD_Display_Color(BackColor);
while (CurX <= CurY)
{
LCD_DisplayPoint(Xpos + CurX, Ypos + CurY, TextColor);
LCD_DisplayPoint(Xpos + CurX, Ypos - CurY, TextColor);
LCD_DisplayPoint(Xpos - CurX, Ypos + CurY, TextColor);
LCD_DisplayPoint(Xpos - CurX, Ypos - CurY, TextColor);
LCD_DisplayPoint(Xpos + CurY, Ypos + CurX, TextColor);
LCD_DisplayPoint(Xpos + CurY, Ypos - CurX, TextColor);
LCD_DisplayPoint(Xpos - CurY, Ypos + CurX, TextColor);
LCD_DisplayPoint(Xpos - CurY, Ypos - CurX, TextColor);
if (D < 0)
{
D += (CurX << 2) + 6;
}
else
{
D += ((CurX - CurY) << 2) + 10;
CurY--;
}
CurX++;
}
}
void LCD_DrawLine(u8 Xpos, u16 Ypos, u16 Length, u8 Direction)
{
u32 i = 0;
//LCD_Display_Color(BackColor);
if(Direction == Horizontal)
{
for(i = 0; i < Length; i++)
{
LCD_DisplayPoint(Xpos+i, Ypos, TextColor);
}
}
else
{
for(i = 0; i < Length; i++)
{
LCD_DisplayPoint(Xpos, Ypos+i, TextColor);
}
}
}
void LCD_DrawRect(u8 Xpos, u16 Ypos, u8 Height, u16 Width)
{
LCD_DrawLine(Xpos, Ypos, Width, Horizontal);
LCD_DrawLine(Xpos , (Ypos + Height), Width, Horizontal);
LCD_DrawLine(Xpos, Ypos, Height, Vertical);
LCD_DrawLine((Xpos + Width), Ypos, Height, Vertical);
}
void LCD_DrawPict(const u8 *Pict)
{
u32 index = 0, i = 0;
const u8 *pu8Temp = Pict;
LCD_SelectRegion(0, 0, 0x7f, 0xff);
for(index = 0; index < 160; index++)
{
for(i = 0; i < 128; i++)
{
LCD_WriteDat(*(pu8Temp+1));
LCD_WriteDat(*pu8Temp);
pu8Temp += 2;
}
}
}
void LCD_DrawBarGraph(int pos_x, int pos_y, int value)
{
int i,j;
int iPosX = pos_x*XPIXES;
int iPosY = pos_y*YPIXES;
LCD_ClearLine(pos_y);
//value 0 ~ 16*8
for (i = 0; i < 26; i++)//26 * 5 ~ 128
{
if (value > 5)
{
//lcd_putchar (0x05);
LCD_SelectRegion(iPosX, iPosY, iPosX+4 ,iPosY + YPIXES-1);
for(j=0; j{
LCD_WriteDat(TextColor>>8);
LCD_WriteDat(TextColor&0xff);
}
iPosX += 8;
value -= 8;//5;
}
else
{
if(value < 0)
{
break;
}
LCD_SelectRegion(iPosX, iPosY, iPosX+value-1 ,iPosY + YPIXES);
for(j=0; j{
LCD_WriteDat(TextColor>>8);
LCD_WriteDat(TextColor&0xff);
}
break;
}
}
}
void Lcd_DspHz16(u8 Line, u8 Column, u8 *Pu8FontStr)
{
u16 i,j,k,x,y,xx,iOffStr;
u8 qm,wm,x0,y0;
u32 ulOffset;
u8 hzbuf[72],u8Mode;
x0 = Column*16;//x coordinate of start point
y0 = Line*16;//y coordinate of start point
for(iOffStr = 0; iOffStr < strlen((const char*)Pu8FontStr); )
{
x0 = iOffStr*8;
if(((u8)(*(Pu8FontStr+iOffStr))) < 161)//?? ascii coding ?
{
if ( (u8)(*(Pu8FontStr+iOffStr)) > 127 )
{
break;
}
LCD_DisplayChar(y0, x0, *(Pu8FontStr+iOffStr));
iOffStr++;//ascii only occupy one byte
}
else
{
//get the zone and the position.
qm = *(Pu8FontStr+iOffStr) - 160;//161;
wm = *(Pu8FontStr+iOffStr+1) - 160;
ulOffset = (u32)((qm-1)*94 + wm-1) * 32;
//count the offset in spi flash . then read one 32 Byte from spi flash, put info into hzbuf
SPI_FLASH_BufferRead(hzbuf, HZAdsInSpiFlash+ulOffset, HZbuffsize);
//diaplay all the info.
for(i=0; i<16; i++)
{
for(j=0; j<2; j++)
{
u8Mode = hzbuf[i*2+j];//get the font mode
for(k=0; k<8; k++)
{
if( u8Mode & (0x80>>k))
{
LCD_DisplayPoint(x0+j*8+k, y0+i, TextColor);
}
}
}
}
iOffStr += 2;
}
}
}
//顯示一個變量的值,variate的值可發(fā)生變化
void Display_variate(u8 Line, u8 Column, u16 variate)
{
int cnt,reg[4];
reg[3]=variate;
reg[2]=variate/10;
reg[1]=variate/100;
reg[0]=variate/1000;
LCD_DisplayChar(Line,Column+8*cnt,1);
for(cnt=0;cnt<=3;cnt++)
{if(cnt==1)
{
LCD_DisplayChar(Line,Column+8,.);
}
if(cnt==0)
switch(reg[cnt])
{
case 1:LCD_DisplayChar(Line,Column,1); break;
case 2:LCD_DisplayChar(Line,Column,2); break;
case 3:LCD_DisplayChar(Line,Column,3); break;
case 4:LCD_DisplayChar(Line,Column,4); break;
case 5:LCD_DisplayChar(Line,Column,5); break;
case 6:LCD_DisplayChar(Line,Column,6); break;
case 7:LCD_DisplayChar(Line,Column,7); break;
case 8:LCD_DisplayChar(Line,Column,8); break;
case 9:LCD_DisplayChar(Line,Column,9); break;
case 0:LCD_DisplayChar(Line,Column,0); break;
default: break;
}
else
switch(reg[cnt])
{
case 1:LCD_DisplayChar(Line,Column+8*(cnt+1),1); break;
case 2:LCD_DisplayChar(Line,Column+8*(cnt+1),2); break;
case 3:LCD_DisplayChar(Line,Column+8*(cnt+1),3); break;
case 4:LCD_DisplayChar(Line,Column+8*(cnt+1),4); break;
case 5:LCD_DisplayChar(Line,Column+8*(cnt+1),5); break;
case 6:LCD_DisplayChar(Line,Column+8*(cnt+1),6); break;
case 7:LCD_DisplayChar(Line,Column+8*(cnt+1),7); break;
case 8:LCD_DisplayChar(Line,Column+8*(cnt+1),8); break;
case 9:LCD_DisplayChar(Line,Column+8*(cnt+1),9); break;
case 0:LCD_DisplayChar(Line,Column+8*(cnt+1),0); break;
default: break;
}
}
}
評論