📄 lcdbios.cpp
字号:
if(x==-1 && y!=-1)
{
x=xpos;
}
else if(x!=-1 && y==-1)
{
y=ypos;
}
else if(x==-1 && y==-1)
{
x=xpos,y=ypos;
}
xpos=x,ypos=y;
for(i=0;i<len;i++)
{
if((ustr[i]) >= 128) //最高位为1
{
if(ustr[i] >= 128) //最高位为1,是汉字
{
if(x>14) //本行写不下汉字,则自动换行
{
x=0;
y+=1;
}
p=hzk16;
p+=(94*(ustr[i]-161)+(ustr[i+1]-161))*32;//得到当前汉字在字库中的首地址
writechchr(p,x,y,reverse);
i++;
x+=2; //写入一个汉字光标右移两位(汉字)
xpos=x,ypos=y;
}
//对于ASC码超过128的字符自动舍去
}
else if(*(str+i)<32)//对于ASC码小过32的不用的字符自动舍去
{
if(*(str+i)==0x0a) //是换行
{
if(*(str+i+1)==0x0a) //填充行尾
{
while(x<16)
{
writechr(&chr[0],x,y);
x++;
}
i++;
}
x=0;
y++;
xpos=x,ypos=y;
continue;
}
if(*(str+i)==0x09)//填充行首
{
char ss=0;
while(ss<x)
{
writechr(&chr[0],ss,y);
ss++;
}
}
if(*(str+i)==0x0d) //接下来的字符居中显示
{
unsigned char k=0,t=0;
while((*(str+i+1+t)!='\0') && (*(str+i+1+t)!=0x0a) )
{
if(*(str+i+1+t)!=0x09 && *(str+i+1+t)!=0x0d)
k++;
t++;
}
if(*(str+i+1)==0x0d) //接下来的字符居右边显示
{
i++;
if(k>=(16-xpos))
{
continue;
}
else
{
x=xpos+(16-xpos-k);
for(char j=xpos;j<x;j++)
writechr(&chr[0],j,y);
xpos=x;
continue;
}
}
else //居中显示
{
if(k>16)
continue;
x=(16-k)/2;
for(char j=xpos;j<x;j++)
writechr(&chr[0],j,y);
xpos=x,ypos=y;
}
continue;
}
}
else //是英文字符
{
if(x>15) //本行写不下,则自动换行
{
x=0;
y++;
}
p = chr;
p += (*(str+i)-32)*16; //得到字符在字库中的首地址
writechr(p,x,y,reverse);
x++; //写入一个字符光标右移1位
xpos=x,ypos=y;
}
}
// return true;
}
//以英文字符的大小计算位置(一个英文字符占一个字节的宽度,16个字节的高度)
//x=0~15,y=0~3,函数并不阻止超过屏幕范围的坐标设置只是在实际输出时字符将不可见。
void CLcd::setpos(short x,short y)
{
//y *= 16;
xpos=x,ypos=y;
}
//背光控制
void CLcd::blight(bool on)
{
if(on)
{
ctl |= BL;
*PLcdCtl=ctl;
}
else
{
ctl &=~BL;
*PLcdCtl=ctl;
}
}
//int WriteItemEx(1, 0, 0x2023, BYTE* pbBuf) //0x2023 1 对比度
#define UPDOWNCTL 0x0008
#if(CURRENT_VERSION == HARD_VERSION_20)
#define INC 0x0002
#else
#define INC 0x0004
#endif
//对比度增加
void CLcd::subCtrst(void)
{
ctstenable(true);//cs low
//*pFIO_INEN&=~UPDOWNCTL;
//*pFIO_INEN&=~INC;
*pFIO_FLAG_D |=UPDOWNCTL;
*pFIO_FLAG_D |=INC;
lcddelay(1);
*pFIO_FLAG_D &=~INC;
lcddelay(1);
*pFIO_FLAG_D |= INC;
lcddelay(1);
ctstenable(false);//cs low
// ctrstNumber--;
// WriteItemEx(1, 0, 0x2023, &ctrstNumber);
}
//对比度减小
void CLcd::addCtrst(void)
{
ctstenable(true);//cs low
*pFIO_FLAG_D &= ~UPDOWNCTL;
*pFIO_FLAG_D |=INC;
lcddelay(1);
*pFIO_FLAG_D &=~INC;
lcddelay(1);
*pFIO_FLAG_D |= INC;
lcddelay(1);
ctstenable(false);//cs low
// ctrstNumber++;
// WriteItemEx(1, 0, 0x2023, &ctrstNumber);
}
//设置x位置函数
bool CLcd::setx(short x)
{
xp=x;
return true;
}
//设置y位置函数,以点为单位设置作图位置
bool CLcd::sety(short y)
{
yp=y;
return true;
}
//设置xy坐标函数,以点为单位设置作图位置
bool CLcd::setxy(short x,short y)
{
xp=x,yp=y;
return true;
}
//打点函数,颜色只能是0、1两种,大于1的数按1处理
bool CLcd::point(short x,short y,unsigned char color)
{
unsigned char i,j;
unsigned char dat;
setxy(x,y);
if(color>1)
color=1;
if(x<0 || x>127 || y<0 || y>63)
return true;
j = y%8;
i = y/8;
dat=lcdmap[x][i];
if(color==1)
{
color<<=j;
dat |= color;
}
else
{
dat &=(~(0x01<<j));
}
lcdmap[x][i]=dat;
writedat(dat,x,i);
return true;
}
bool CLcd::point(unsigned char color)
{
point(xp,yp,color);
return true;
}
//画线函数,可以画任意直线
bool CLcd::line(short x1,short y1,short x2,short y2,unsigned char color)
{
short tmp,i;
float slope,x,y;
if(x1==x2)//垂直画线
{
if(y1<=y2)
{
for(i=y1;i<=y2;i++)
point(x1,i,color);
}
else
{
for(i=y2;i<=y1;i++)
point(x1,i,color);
}
return true;
}
else if(y1==y2)//画水平线
{
if(x1<=x2)
{
for(i=x1;i<=x2;i++)
point(i,y1,color);
}
else
{
for(i=x2;i<=x1;i++)
point(i,y1,color);
}
return true;
}
else
{
slope=((float)(y2-y1))/((float)(x2-x1)); //求斜率
if((slope<=1) && (slope>=-1))
{
for(x=x1;x<=x2;x++)
{
y=x*slope;
point((short)x,(short)y,color);
}
}
else
{
slope=1/slope;
for(y=y1;y<=y2;y++)
{
x=y*slope;
point((short)x,(short)y,color);
}
}
}
return true;
}
//画矩形函数,为作图提供基础
void CLcd::rectangle(short x1,short y1,short x2,short y2,unsigned char color)
{
if(color>1)
color=1;
line(x1,y1,x1,y2,color);
line(x1,y2,x2,y2,color);
line(x2,y2,x2,y1,color);
line(x2,y1,x1,y1,color);
}
//画圆函数
void CLcd::circle(short x,short y,short r,short color)
{
float x1,y1,Pi=3.14159;
short i;
for(i=1;i<=360;)
{
x1=x+r*cos(((float)i)/360*2*Pi);
y1=y-r*sin(((float)i)/360*2*Pi);
if(i>85 && i<95)
point((short)x1,(short)y1-1,color);
else if(i>175 && i<185)
point((short)x1-1,(short)y1,color);
else if(i>265 && i<275)
point((short)x1,(short)y1+1,color);
else if(i<5 || i>355)
point((short)x1+1,(short)y1,color);
else
point((short)x1,(short)y1,color);
if(r<=5)
i+=10;
else if(r<=10)
i+=6;
else if(r<=15)
i+=4;
else if(r<=20)
i+=2;
else
i++;
}
}
void SaveToHzk(void );
void Program_One_Block (WORD *Src, WORD *Dst);
void Program_One_Sector(WORD *Src, WORD *Dst);
void Init_HZK()
{
BYTE*HZK_head=(unsigned char *)(0x201C0000);
SetFlashBankToProgram();
#ifdef NO_HZK
CopyToHzk( );
#else
if((*(HZK_head)=='H')&&(*(HZK_head+1)=='Z')&&(*(HZK_head+2)=='K'))
{
;
}
else
{
lcd.clear();
lcd.print("正在更新汉字库请稍候...",0,1);
SaveToHzk();
}
#endif
}
#define SECTOR_SIZE 2048 /* Must be 2048 words for 39VF320 */
//#define BLOCK_SIZE 32768 /* Must be 32K words for 39VF320 */
void SaveToHzk(void )
{
// #ifdef DEBUG_3
// hzk16=(unsigned char *)(0x201C0000);
// #else
int size,i,j;
unsigned char *pc1,*pc2;
pc1 = hzk_buff;
pc2=(unsigned char *)(0x201C0000);
size=sizeof(hzk_buff);
size-=(SECTOR_SIZE*2);
pc1+=(SECTOR_SIZE*2);
pc2+=(SECTOR_SIZE*2);
while(size >0)
{
size-=(SECTOR_SIZE*2);
ClearWDG();
//Program_One_Block((WORD*)pc1,(WORD*)pc2);
for (i=0;i<10;i++)
{
Erase_One_Sector((WORD *)((unsigned long)pc2 & 0xfffff000));
Program_One_Sector((WORD *)pc1,(WORD *)((unsigned long)pc2 & 0xfffff000));
j=memcmp(pc1,(char *)((unsigned long)pc2 & 0xfffff000),SECTOR_SIZE*2);
if (j==0)break;
}
if(i>=10) return ;//10次写不成功返回
pc1+=(SECTOR_SIZE*2);
pc2+=(SECTOR_SIZE*2);
}
pc1 = hzk_buff;
pc2=(unsigned char *)(0x201C0000);
for (i=0;i<10;i++)
{
Erase_One_Sector((WORD *)((unsigned long)pc2 & 0xfffff000));
Program_One_Sector((WORD *)pc1,(WORD *)((unsigned long)pc2 & 0xfffff000));
j=memcmp(pc1,(char *)((unsigned long)pc2 & 0xfffff000),SECTOR_SIZE*2);
if (j==0)break;
}
// Program_One_Block((WORD*)pc1,(WORD*)pc2);
}
void CopyToHzk(void )
{
// #ifdef DEBUG_3
// hzk16=(unsigned char *)(0x201C0000);
// #else
unsigned char *pc1,*pc2;
pc1 = hzk_buff;
pc2=(unsigned char *)(0x201C0000);
//*pc2 = 'a';
ClearWDG();
memcpy(pc1,pc2,sizeof(hzk_buff));
ClearWDG();
// #endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -