OLED 相关驱动
//¿ªÆôOLEDÏÔʾ
void OLED_Display_On(void)
{
OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDCÃüÁî
OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON
OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON
}
//¹Ø±ÕOLEDÏÔʾ
void OLED_Display_Off(void)
{
OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDCÃüÁî
OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF
}
//ÇåÆÁº¯Êý,ÇåÍêÆÁ,Õû¸öÆÁÄ»ÊǺÚÉ«µÄ!ºÍûµãÁÁÒ»Ñù!!!
void OLED_Clear(void)
{
u8 i,n;
for(i=0;i<8;i++)for(n=0;n<130;n++)OLED_GRAM[n][i]=0X00;
OLED_Refresh_Gram();//¸üÐÂÏÔʾ
}
//»µã
//x:0~127
//y:0~63
//t:1 Ìî³ä 0,Çå¿Õ
void OLED_DrawPoint(u8 x,u8 y,u8 t)
{
u8 pos,bx,temp=0;
if(x>131||y>63)return;//³¬³ö·¶Î§ÁË.
pos=7-y/8;
bx=y%8;
temp=1<<(7-bx);
if(t)OLED_GRAM[x][pos]|=temp;
else OLED_GRAM[x][pos]&=~temp;
}
//x1,y1,x2,y2 Ìî³äÇøÓòµÄ¶Ô½Ç×ø±ê
//È·±£x1<=x2;y1<=y2 0<=x1<=127 0<=y1<=63
//dot:0,Çå¿Õ;1,Ìî³ä
void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot)
{
u8 x,y;
for(x=x1;x<=x2;x++)
{
for(y=y1;y<=y2;y++)OLED_DrawPoint(x,y,dot);
}
OLED_Refresh_Gram();//¸üÐÂÏÔʾ
}
//ÔÚÖ¸¶¨Î»ÖÃÏÔʾһ¸ö×Ö·û,°üÀ¨²¿·Ö×Ö·û
//x:0~127
//y:0~63
//mode:0,·´°×ÏÔʾ;1,Õý³£ÏÔʾ
//size:Ñ¡Ôñ×ÖÌå 16/12
void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 size,u8 mode)
{
u8 temp,t,t1;
u8 y0=y;
chr=chr-' ';//µÃµ½Æ«ÒƺóµÄÖµ
for(t=0;t<size;t++)
{
if(size==12)temp=oled_asc2_1206[chr][t]; //µ÷ÓÃ1206×ÖÌå
else temp=oled_asc2_1608[chr][t]; //µ÷ÓÃ1608×ÖÌå
for(t1=0;t1<8;t1++)
{
if(temp&0x80)OLED_DrawPoint(x,y,mode);
else OLED_DrawPoint(x,y,!mode);
temp<<=1;
y++;
if((y-y0)==size)
{
y=y0;
x++;
break;
}
}
}
}
//m^nº¯Êý
u32 oled_pow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
//ÏÔʾ2¸öÊý×Ö
//x,y :Æðµã×ø±ê
//len :Êý×ÖµÄλÊý
//size:×ÖÌå´óС
//mode:ģʽ 0,Ìî³äģʽ;1,µþ¼Óģʽ
//num:ÊýÖµ(0~4294967295);
void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/oled_pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
OLED_ShowChar(x+(size/2)*t,y,' ',size,1);
continue;
}else enshow=1;
}
OLED_ShowChar(x+(size/2)*t,y,temp+'0',size,1);
}
}
//ÏÔʾ×Ö·û´®
//x,y:Æðµã×ø±ê
//*p:×Ö·û´®ÆðʼµØÖ·
//ÓÃ16×ÖÌå
void OLED_ShowString(u8 x,u8 y,const u8 *p)
{
// #define MAX_CHAR_POSX 122
#define MAX_CHAR_POSX 126
#define MAX_CHAR_POSY 58
while(*p!='\0')
{
if(x>MAX_CHAR_POSX){x=0;y+=16;}
if(y>MAX_CHAR_POSY){y=x=0;OLED_Clear();}
OLED_ShowChar(x,y,*p,16,1);
x+=8;
p++;
}
}
//ÏÔʾºº×Ó
//x,y:Æðµã×ø±ê
//pos:Êý×éλÖúº×ÓÏÔʾ
//size:×ÖÌå´óС
//mode:0,·´°×ÏÔʾ;1,Õý³£ÏÔʾ
void OLED_ShowFontHZ(u8 x,u8 y,u8 pos,u8 size,u8 mode)
{
u8 temp,t,t1;
u8 y0=y;
u8 csize=(size/8+((size%8)?1:0))*(size);//µÃµ½×ÖÌåÒ»¸ö×Ö·û¶ÔÓ¦µãÕó¼¯ËùÕ¼µÄ×Ö½ÚÊý
if(size!=12&&size!=16&&size!=24)return; //²»Ö§³ÖµÄsize
for(t=0;t<csize;t++)
{
if(size==12)temp=FontHzk[pos][t]; //µ÷ÓÃ1206×ÖÌå
else if(size==16)temp=FontHzk[pos][t]; //µ÷ÓÃ1608×ÖÌå
else if(size==24)temp=FontHzk[pos][t]; //µ÷ÓÃ2412×ÖÌå
else return; //ûÓеÄ×Ö¿â
for(t1=0;t1<8;t1++)
{
if(temp&0x80)OLED_DrawPoint(x,y,mode);
else OLED_DrawPoint(x,y,!mode);
temp<<=1;
y++;
if((y-y0)==size)
{
y=y0;
x++;
break;
}
}
}
} |