比完赛,整理了一下备赛期间的调试工具,个人感觉比较好用的;
-- 1、寄存器部分参考了原子和网上其他大佬的代码,稍作修改;
-- 2、可快速更改控制引脚和控制方式(spi和i2c),在.h文件中修改即可;
-- 3、对字符显示进行优化,目前可显示字符、字符串、符号十进制、可选精度小数、十六进制...
-- 4、封装了绘图函数,绘制圆、椭圆等;
-- 5、封装对屏操作函数,移屏、翻转等,可用于制作菜单;
*声明:
-- 1、借鉴了其他人的代码,这里就不一一感谢了,总之很多;
-- 2、个人添加的内容也是在网上找不见(可能只有我找不见),然后参考一些算法写的,可能写的不正确,也请各位大佬们改正,在此感谢;
-- 3、如有任何问题,欢迎一起交流学习;
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
oled.c文件加入以下代码
hzxh gb2312_hzxh[HZLEN] =
{
{"温",0},
{"湿",1},
{"度",2},
{"空",3},
{"气",4},
};
s8 findhzxh(u8* ch)
{
u8 i,j,k,l;
u8 temphz[3];
hzxh *p;
u8* e;
p = gb2312_hzxh;
//char *ch="空气";
while(*ch!=' ')
{
for(i = 0;i < 3;i++)
{
temphz = *(ch+i);
}
temphz[2] = ' ';
ch = ch +2;
l = 0;
//printf("%s ",temphz);
for(j = 0; j < 5; j++)
{
e = p->hz;
for(k = 0;k<2;k++)
{
if(temphz[k] == *(e+k))
{
l++;
}
}
if(l == 2)
{
//printf("%d ",p->num);
return p->num;
}
l = 0;
p++;
}
p = gb2312_hzxh;
}
return -1;
}
oled_coord_handle oled_displaygb2312(u8 Xcoor, u8 Ycoor, u8 *HANZI, u8 Cover)
{
u8 page=0,part=0,col=0;
u8 hz_num=0;//汉字个数
u8 hzs[HZLEN] = {0};//汉字缓存
s8 ret_hz = 0;//返回汉字索引
u8 i;
u8 temphz[3];
while(*(HANZI)!=' ')//字符" "的ascii码是0x10
{
for(i = 0;i < 3;i++)//取出一个字符用作后面的判定
{
temphz = *(HANZI+i);
}
temphz[2] = ' ';
HANZI = HANZI + 2;
if((ret_hz = findhzxh(temphz)) != -1)//如果是-1表示该汉字不存在
{
hzs[hz_num] = ret_hz;
hz_num++;
}
}
for(page=0;page<2;page++) //页显示
{
for(part=0;part<hz_num;part++) //汉字个数16*16
{
for(col=0;col<16;col++) //列显示
{
if(Cover)
{
oled_gram[col + ((Xcoor+part)<<4)][Ycoor+page] |= Hzk[*(HANZI)*2+page+hzs[part]*2][col];//part就是实际已有的汉字个数
}else{
oled_gram[col + ((Xcoor+part)<<4)][Ycoor+page] = Hzk[*(HANZI)*2+page+hzs[part]*2][col];
}
}
}
}
return oled_coordval(Xcoor<<3, Ycoor<<2, ((Xcoor+hz_num-1)<<4)+7, (Ycoor<<2)+1);
}
oledfont.h加入以下代码
char Hzk[][32]={
{0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00},/*"温",0*/
{0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00},/*"湿",1*/
{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00},
{0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},/*"度",2*/
{0x10,0x0C,0x44,0x24,0x14,0x04,0x05,0x06,0x04,0x04,0x14,0x24,0x44,0x14,0x0C,0x00},
{0x00,0x40,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,0x00},/*"空",3*/
{0x20,0x10,0x4C,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x04,0x04,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00},/*"气",4*/
};
#define HZLEN 50
typedef struct
{
u8 *hz;
u8 num;
}hzxh;
main.c中
oled_displaygb2312(0,6,"温度湿空气",1);
这样就是实现了智能化显示汉字,如果函数输入字库没有的汉字就不会显示没有的汉字,如果要显示更多的汉字就往字库文件中添加字形码以及结构体指针那边在添加汉字对应的索引即可,其他函数依照楼主的写就可以啦,哈哈忙了一下午的代码,搞了半天的指针,感谢楼主的代码。
一周热门 更多>