有朋友看了我的贴问我,接下来分享一下。
例如我定义一个函数,可以显示带框框的数字
unsigned char code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/
{0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"1",1*/
{0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",2*/
{0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00},/*"3",3*/
{0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24},/*"4",4*/
{0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00},/*"5",5*/
{0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00},/*"6",6*/
{0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00},/*"7",7*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",8*/
{0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00},/*"9",9*/
};
void number_not(unsigned char numb,unsigned char x,unsigned char y)
{
unsigned char i;
for(i=0;i<16;i++)
{
if(i==0||i==15)
{
OLED_Set_Pos(x+i,y+0);
OLED_WR_Byte(~0xFF,OLED_DATA);
OLED_Set_Pos(x+i,y+1);
OLED_WR_Byte(~0xFF,OLED_DATA);
}
else if((i>0&&i<4)||(i>12&&i<16))
{
OLED_Set_Pos(x+i,y+0);
OLED_WR_Byte(~0x01,OLED_DATA);
OLED_Set_Pos(x+i,y+1);
OLED_WR_Byte(~0x80,OLED_DATA);
}
else
{
OLED_Set_Pos(x+i,y+0);
OLED_WR_Byte(~(0x01|num[numb][i-4]),OLED_DATA);
OLED_Set_Pos(x+i,y+1);
OLED_WR_Byte(~(0x80|num[numb][i+4]),OLED_DATA);
}
}
}
这个大家好理解吧。
如何反色显示呢?就是让最终屏幕上要显示的1变成0,让要实现的0变成1即可
如下
void number_not(unsigned char numb,unsigned char x,unsigned char y)
{
unsigned char i;
for(i=0;i<16;i++)
{
if(i==0||i==15)
{
OLED_Set_Pos(x+i,y+0);
OLED_WR_Byte(~0xFF,OLED_DATA);
OLED_Set_Pos(x+i,y+1);
OLED_WR_Byte(~0xFF,OLED_DATA);
}
else if((i>0&&i<4)||(i>12&&i<16))
{
OLED_Set_Pos(x+i,y+0);
OLED_WR_Byte(~0x01,OLED_DATA);
OLED_Set_Pos(x+i,y+1);
OLED_WR_Byte(~0x80,OLED_DATA);
}
else
{
OLED_Set_Pos(x+i,y+0);
OLED_WR_Byte(~(0x01|num[numb][i-4]),OLED_DATA);
OLED_Set_Pos(x+i,y+1);
OLED_WR_Byte(~(0x80|num[numb][i+4]),OLED_DATA);
}
}
}
另外还可以合并这两个函数为一个函数
|
共2人点赞
|
学习一下