📄 finalcd._h
字号:
{
dy=y2-y1;
while(x<=x2&&y<=y2)
{
if(y>120)
{
if((y-120)%40!=0&&x%40!=0)
point(x,y,color);
}
else
{
if((120-y)%40!=0&&x%40!=0)
point(x,y,color);
}
if(dx*(y-y1)<dy*(x-x1))//保证所画直线尽量和所求直线靠近
y++;
else x++;
}
}
else if(y1>y2)//直线于y轴夹角大于90°
{
dy=y1-y2;
while(x<=x2&&y>=y2)
{
if(y>120)
{
if((y-120)%40!=0&&x%40!=0)
point(x,y,color);
}
else
{
if((120-y)%40!=0&&x%40!=0)
point(x,y,color);
}
if(dx*(y1-y)<dy*(x-x1))//保证所画直线尽量和所求直线靠近
y--;
else x++;
}
}
}
/**********用某种颜色填充圆形区域************/
/*void cycle(char x,char y,unsigned int rad,char color)
{
unsigned int temp1,temp2;
point(x,y,color);
for(temp1=0;temp1<rad;temp1++)
{
for(temp2=0;temp1*temp1+temp2*temp2<=rad*rad;temp2++)
{
point(temp1+x,(char)temp2+y,color);//画第一象限
point(temp1+x,y-(char)temp2,color);//画第2象限
point(x-temp1,(char)temp2+y,color);//画第3象限
point(x-temp1,y-(char)temp2,color);//画第4象限
}
}
}*/
void cycle(char x,char y,unsigned int rad,char color)//在液晶上画圆,同时画维度线
{
unsigned int temp1,temp2,temp3,temp4;
char buffer1=0,buffer2=0,buffer3=0;
char i,j;
i=(char)(x/8);
buffer1 |=(color<<5);
buffer1 |=(color<<2);
buffer1 |=(color>>1);
buffer2 |=(color<<7);
buffer2 |=(color<<4);
buffer2 |=(color<<1);
buffer2 |=(color>>2);
buffer3 |=(color<<6);
buffer3 |=(color<<3);
buffer3 |= color;
write(i,y,buffer1,buffer2,buffer3);
temp3=rad*rad;//减少循环的运算
for(temp2=0;temp2<rad;temp2++)
{
//write(i,y+(char)temp2,buffer1,buffer2,buffer3);
//write(i,y-(char)temp2,buffer1,buffer2,buffer3);
temp4=temp2*temp2;//减少循环的运算
if(temp2%40!=0)
{
for(temp1=8;temp1*temp1+temp4<=temp3;temp1=temp1+8)//连续8个点都在圆内
{
j=(char)(temp1/8);
write(i+j-1,y+(char)temp2,buffer1,buffer2,buffer3);
write(i-j,y+(char)temp2,buffer1,buffer2,buffer3);
write(i+j-1,y-(char)temp2,buffer1,buffer2,buffer3);
write(i-j,y-(char)temp2,buffer1,buffer2,buffer3);
}
for(temp1=temp1-8;temp1*temp1+temp4<=temp3;temp1++)//连续8个点不都在圆内
{ point(temp1+x,(char)temp2+y,color);//画第一象限
point(temp1+x,y-(char)temp2,color);//画第2象限
point(x-temp1,(char)temp2+y,color);//画第3象限
point(x-temp1,y-(char)temp2,color);//画第4象限
}
}
else
{
for(temp1=8;temp1*temp1+temp4<=temp3;temp1=temp1+8)//连续8个点都在圆内
{
j=(char)(temp1/8);
write(i+j-1,y+(char)temp2,0xff,0xff,0xff);
write(i-j,y+(char)temp2,0xff,0xff,0xff);
write(i+j-1,y-(char)temp2,0xff,0xff,0xff);
write(i-j,y-(char)temp2,0xff,0xff,0xff);
}
for(temp1=temp1-8;temp1*temp1+temp4<=temp3;temp1++)//连续8个点不都在圆内
{ point(temp1+x,(char)temp2+y,7);//画第一象限
point(temp1+x,y-(char)temp2,7);//画第2象限
point(x-temp1,(char)temp2+y,7);//画第3象限
point(x-temp1,y-(char)temp2,7);//画第4象限
}
}
}
}
/***************汉字显示,显示整个汉字*********************/
void hanzi(char x,char y,const unsigned char *hz,char color,char bs)
{
unsigned char i,j;
for(i=0;i<bs*8;i++)//一共有bs×8行的点阵
{
for(j=0;j<bs;j++)//每行有bs个点位
{
hz_write(x,y,hz,color);//写入该点位的八个点
hz++;//hz存放黑白字模的数组
x++;
}
x-=bs;//返回字的行首
y++;//进入下一行
}
}
/***************汉字显示,显示汉字的一个字节位*********************/
void hz_write(char x,char y,const unsigned char *hz,char color)
{
char i,j,k;
char buffer1,buffer2,buffer3;
read(x,y,&buffer1,&buffer2,&buffer3);
i=*hz;
for(j=8;*hz&&j>0;j--)//判断每位的值,看其对应的点是否存在,存在则修改其颜色值。
{
i=*hz&(1<<(j-1));
if(i==0x80)//判断第一位是否存在
{
buffer1 &= 0x1f;
buffer1 |=(color<<5);
}
else if (i==0x40)//判断第二位是否存在
{
buffer1 &= 0xe3;
buffer1 |=(color<<2);
}
else if (i==0x20)//判断第三位是否存在
{
buffer1 &= 0xfc;
buffer1 |=(color>>1);
buffer2 &= 0x7f;
buffer2 |=(color<<7);
}
else if (i==0x10)//判断第四位是否存在
{
buffer2 &= 0x8f;
buffer2 |=(color<<4);
}
else if (i==0x08)//判断第五位是否存在
{
buffer2 &= 0xf1;
buffer2 |=(color<<1);
}
else if (i==0x04)//判断第六位是否存在
{
buffer2 &= 0xfe;
buffer2 |=(color>>2);
buffer3 &= 0x3f;
buffer3 |=(color<<6);
}
else if (i==0x02)//判断第七位是否存在
{
buffer3 &= 0xc7;
buffer3 |=(color<<3);
}
else if (i==0x01)//判断第八位是否存在
{
buffer3 &= 0xf8;
buffer3 |= color;
}
}//判断输入的黑白字符字模每个数字对应的写入点以及其颜色
write(x,y,buffer1,buffer2,buffer3);
}
/***************显示一个字符字符固定大小,8×16******************/
void lettershow(char x,char y,char *hz,char color)
{
unsigned char i,j;
for(i=0;i<16;i++)//一共有16行的点阵
{
hz_write(x,y,hz,color);//写入该点位的八个点
hz++;//hz存放黑白字模的数组
y++;//进入下一行
}
}
/*********计算字符a所表示的字符,调用显示字符模块来显示********/
void showchar(char x,char y,char a,char letter,char color)
{
char temp,hz[16],i;
if (letter==0)//将a转化为数字显示,可以显示0~255的数字
{
temp=a/100;
if(temp!=0)//首位不为0
{
a=a-temp*100;
for(i=0;i<16;i++)
hz[i]=suzhi[temp+4][i];
lettershow(x,y,hz,color);
x++;
temp=a/10;
a=a-temp*10;
for(i=0;i<16;i++)
hz[i]=suzhi[temp+4][i];//加4,对应二维数组数字的位置,不包含符号
lettershow(x,y,hz,color);
x++;
for(i=0;i<16;i++)
hz[i]=suzhi[a][i];
lettershow(x,y,hz,color);
}
else //首位为0
{
temp=a/10;
if(temp!=0)//第二位不为0
{
a=a-temp*10;
for(i=0;i<16;i++)
hz[i]=suzhi[temp+4][i];
lettershow(x,y,hz,color);
x++;
}
for(i=0;i<16;i++)
hz[i]=suzhi[a+4][i];
lettershow(x,y,hz,color);
}
}
else//显示一位字母或者数字或者常用标点
{
if(a>90)//显示小写字母
{
temp=a-97;
for(i=0;i<16;i++)
hz[i]=mletter[temp][i];
lettershow(x,y,hz,color);
}
else if(a<=90&&a>=65)//显示大写字母
{
temp=a-65;
for(i=0;i<16;i++)
hz[i]=bletter[temp][i];
lettershow(x,y,hz,color);
}
else//显示一位数字或者常用标点
{
temp=a-44;
for(i=0;i<16;i++)
hz[i]=suzhi[temp][i];
lettershow(x,y,hz,color);
}
}
}
/**********显示字符串a的值************/
void showchars(char x,char y,char *a,char color)
{
char i;
for(i=0;a[i]!='\0';i++)
{
if(a[i]!=' ')//将非空格显示出来,遇到空格跳到下一个显示位
showchar(x,y,a[i],1,color);//把字符串依次显示出来
x++;
}
}
void showsmallmun(char x,char y,char *a,char color)//显示4*8的数字
{
static char smun[15][8]={{0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80},//,
{0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00},//-
{0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00},//.
{0x00,0x20,0x20,0x40,0x40,0x40,0x80,0x80},///
{0x00,0x00,0x40,0xA0,0xA0,0xA0,0x40,0x00},//0
{0x00,0x00,0x20,0x60,0x20,0x20,0x70,0x00},//1
{0x00,0x00,0xE0,0xA0,0x40,0x80,0xE0,0x00},//2
{0x00,0x00,0xE0,0x40,0x20,0xA0,0xE0,0x00},//3
{0x00,0x00,0x20,0x60,0xA0,0x60,0x20,0x00},//4
{0x00,0x00,0xE0,0x80,0xE0,0x20,0xE0,0x00},//5
{0x00,0x00,0x60,0x80,0xF0,0x90,0x70,0x00},//6
{0x00,0x00,0x70,0x10,0x20,0x20,0x20,0x00},//7
{0x00,0x00,0xE0,0xA0,0x40,0xA0,0xE0,0x00},//8
{0x00,0x00,0xE0,0xA0,0xE0,0x20,0x40,0x00},//9
{0x00,0x00,0x00,0x20,0x00,0x00,0x20,0x00}};//:
char buffer1,buffer2,buffer3,j;
char i,temp1,temp2,k,temp,tk;
char b[8];
char *hz;
for(i=0;a[i]!='\0';i++)
{
if(a[i+1]!='\0')//如果显示的数字串连续,连续显示两个数字
{
temp1=a[i]-44;
temp2=a[i+1]-44;
for(k=0;k<8;k++)//计算两个数字在一个点阵中的值,将前后两个数字合并到一个点阵中
b[k]=smun[temp1][k]+(smun[temp2][k]/16);
i++;
}
else//如果显示的数字串不连续,即给数字没有下一个数就显示一个数
{
temp1=a[i]-44;
for(k=0;k<8;k++)
b[k]=smun[temp1][k];
}
hz=b;
temp=y;//获取开始的行作标
for(k=0;k<8;k++)//由于单片机堆栈的问题,在这里调用hz_write会出错,所以再写了一次
{
read(x,temp,&buffer1,&buffer2,&buffer3);
tk=*hz;
for(j=8;*hz&&j>0;j--)//判断每位的值,看其对应的点是否存在,存在则修改其颜色值。
{
tk=*hz&(1<<(j-1));
if(tk==0x80)//判断第一位是否存在
{
buffer1 &= 0x1f;
buffer1 |=(color<<5);
}
else if (tk==0x40)//判断第二位是否存在
{
buffer1 &= 0xe3;
buffer1 |=(color<<2);
}
else if (tk==0x20)//判断第三位是否存在
{
buffer1 &= 0xfc;
buffer1 |=(color>>1);
buffer2 &= 0x7f;
buffer2 |=(color<<7);
}
else if (tk==0x10)//判断第四位是否存在
{
buffer2 &= 0x8f;
buffer2 |=(color<<4);
}
else if (tk==0x08)//判断第五位是否存在
{
buffer2 &= 0xf1;
buffer2 |=(color<<1);
}
else if (tk==0x04)//判断第六位是否存在
{
buffer2 &= 0xfe;
buffer2 |=(color>>2);
buffer3 &= 0x3f;
buffer3 |=(color<<6);
}
else if (tk==0x02)//判断第七位是否存在
{
buffer3 &= 0xc7;
buffer3 |=(color<<3);
}
else if (tk==0x01)//判断第八位是否存在
{
buffer3 &= 0xf8;
buffer3 |= color;
}
}//判断输入的黑白字符字模每个数字对应的写入点以及其颜色
write(x,temp,buffer1,buffer2,buffer3);
temp++;//下一行
hz++;
}
x++;//写下两个数字
}
}
void showallhz(void)
{
hanzi(30,40,hz31,7,2);//在第一行显示汉字“船“
hanzi(32,40,hz58,7,2);//在第一行显示汉字“名“
hanzi(30,72,hz59,7,2);//在第二行显示字“MM“
hanzi(32,72,hz60,7,2);//在第二行显示字“SI“
hanzi(30,104,hz61,7,2);//在第三行显示字“呼“
hanzi(32,104,hz62,7,2);//在第三行显示字“号“
hanzi(30,136,hz31,7,2);//在第四行显示字“船“
hanzi(32,136,hz32,7,2);//在第四行显示字“舶“
hanzi(34,136,hz63,7,2);//在第四行显示字“类“
hanzi(36,136,hz64,7,2);//在第四行显示字“型“
hanzi(30,168,hz31,7,2);//在第五行显示字“船“
hanzi(32,168,hz32,7,2);//在第五行显示字“舶“
hanzi(34,168,hz65,7,2);//在第五行显示字“大“
hanzi(36,168,hz66,7,2);//在第五行显示字“小“
hanzi(30,200,hz54,7,2);//在第六行显示字“位“
hanzi(32,200,hz30,7,2);//在第六行显示字“置“
hanzi(34,200,hz39,7,2);//在第六行显示字“参“
hanzi(36,200,hz67,7,2);//在第六行显示字“照“
}
/************延时函数***************/
void delay_1ms(void)
{
unsigned int i;
for(i=1;i<10000;i++)
;
}
void delay(unsigned int n)
{
unsigned int i=0;
for(i=0;i<n;i++)
delay_1ms();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -