一直在拿深度使用、STM32 Nucleo加X-NUCLEO-IDB04A1板子做应用,效果不错,这两天才有空闲下来,整理材料,发点心得。
0.96寸,串口OLED屏,分辨率12864,就是好小啊,控制器SSD1306。
void OLED_WrDat(unsigned char dat)//写数据
{
unsigned char i;
OLED_DC_Set();
for(i=0;i<8;i++)
{
if((dat << i) & 0x80)
{
OLED_SDA_Set();
}
else
OLED_SDA_Clr();
OLED_SCL_Clr();
OLED_SCL_Set();
}
}
void OLED_WrCmd(unsigned char cmd)//写命令
{
unsigned char i;
OLED_DC_Clr();
for(i=0;i<8;i++) //发送一个八位数据
{
if((cmd << i) & 0x80)
{
OLED_SDA_Set();
}
else
{
OLED_SDA_Clr();
}
OLED_SCL_Clr();
OLED_SCL_Set();
}
}
void OLED_SetPos(unsigned char x, unsigned char y)//设置起始点坐标
{
OLED_WrCmd(0xb0 + y);
OLED_WrCmd(((x&0xf0)>>4)|0x10);
OLED_WrCmd((x&0x0f)|0x01);
}
void OLED_Fill(unsigned char bmp_dat)//全屏填充
{
unsigned char y,x;
for(y=0;y<8;y++)
{
OLED_WrCmd(0xb0+y);
OLED_WrCmd(0x01);
OLED_WrCmd(0x10);
for(x=0;x126)
{
x=0;y++;
}
OLED_SetPos(x,y);
for(i=0;i<6;i++)
{
OLED_WrDat(F6x8[c]);
}
x+=6;
j++;
}
}
void OLED_8x16Str(unsigned char x, unsigned char y, unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch[j]!='\0')
{
c =ch[j]-32;
if(x>120)
{
x=0;y++;
}
OLED_SetPos(x,y);
for(i=0;i<8;i++)
{
OLED_WrDat(F8X16[c*16+i]);
}
OLED_SetPos(x,y+1);
for(i=0;i<8;i++)
{
OLED_WrDat(F8X16[c*16+i+8]);
}
x+=8;
j++;
}
}
void OLED_16x16CN(unsigned char x, unsigned char y, unsigned char N)
{
unsigned char wm=0;
unsigned int adder=32*N;
OLED_SetPos(x , y);
for(wm = 0;wm < 16;wm++)
{
OLED_WrDat(F16x16[adder]);
adder += 1;
}
OLED_SetPos(x,y + 1);
for(wm = 0;wm < 16;wm++)
{
OLED_WrDat(F16x16[adder]);
adder += 1;
}
}
本帖最后由 gxliu08 于 2015-1-19 21:02 编辑