|
本帖最后由 gxliu08 于 2015-1-19 21:02 编辑
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;x
{
OLED_WrDat(bmp_dat);
}
}
}
void OLED_CLS(void)//清屏
{
OLED_Fill(0x00);
}
void OLED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PC,D,G端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //PD3,PD6推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetBits(GPIOA,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); //PD3,PD6 输出高
DelayInit();//延时初始化
DelayMs(500);
OLED_CS_Clr();
OLED_WrCmd(0xae);
OLED_WrCmd(0xae);//--turn off oled panel
OLED_WrCmd(0x00);//---set low column address
OLED_WrCmd(0x10);//---set high column address
OLED_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
OLED_WrCmd(0x81);//--set contrast control register
OLED_WrCmd(0xcf); // Set SEG Output Current Brightness
OLED_WrCmd(0xa1);//--Set SEG/Column Mapping 0xa0,0xa1
OLED_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0,0xc8
OLED_WrCmd(0xa6);//--set normal display
OLED_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
OLED_WrCmd(0x3f);//--1/64 duty
OLED_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
OLED_WrCmd(0x00);//-not offset
OLED_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
OLED_WrCmd(0xd9);//--set pre-charge period
OLED_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
OLED_WrCmd(0xda);//--set com pins hardware configuration
OLED_WrCmd(0x12);
OLED_WrCmd(0xdb);//--set vcomh
OLED_WrCmd(0x40);//Set VCOM Deselect Level
OLED_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
OLED_WrCmd(0x02);//
OLED_WrCmd(0x8d);//--set Charge Pump enable/disable
OLED_WrCmd(0x14);//--set(0x10) disable
OLED_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
OLED_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
OLED_WrCmd(0xaf);//--turn on oled panel
OLED_Fill(0x00);
OLED_SetPos(0,0);
}
void OLED_6x8Str(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>126)
{
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;
}
}
|
|