用的是7Pin的OLED,就那个宝买的那种。用的是不是中景园的程序我就不知道了。芯片应该是用SSD1306,但是用仿真里面的SSD1306总是不对。我随便试了试SSD1308到时对了!
单片机源程序如下
#include "xianshispi.h"
#include "oledfont.h"
void delay_ms(unsigned int ms)
{
unsigned int a;
while(ms)
{
a=1800;
while(a--);
ms--;
}
return;
}
void OLED_WR_Byte(unsigned char dat,unsigned char cmd) //写数据 或 指令
{ // 数据 指令
unsigned char i;
if(cmd) {OLED_DC(1);}
else {OLED_DC(0); }
OLED_CS(0);
for(i=0;i<8;i++)
{
OLED_SCL(0);
if(dat&0x80)
{
OLED_SDIN(1);
}
else
OLED_SDIN(0);
OLED_SCL(1);
dat<<=1;
}
OLED_CS(1);
OLED_DC(1);
}
void OLED_Set_Pos(unsigned char x, unsigned char y) // 定位 —(轴)
{
OLED_WR_Byte(0xb0+y,OLED_CMD);
OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
}
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
}
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) //清屏(全)
{
unsigned char i,n;
for(i=0;i<8;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD);
OLED_WR_Byte (0x02,OLED_CMD);
OLED_WR_Byte (0x10,OLED_CMD);
for(n=0;n<128;n++)OLED_WR_Byte(0x00,OLED_DATA);
}
}
void OLED_Clear2(void) //清屏(一般)
{
unsigned char i,n;
for(i=0;i<2;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD);
OLED_WR_Byte (0x02,OLED_CMD);
OLED_WR_Byte (0x10,OLED_CMD);
for(n=0;n<128;n++)OLED_WR_Byte(0xff,OLED_DATA);
}
}
void OLED_ShowChar(unsigned char x,unsigned char y,unsigned int chr) //字符取反 (背景和数据)
{
unsigned int c=0,i=0;
c=chr-' ';
if(x>Max_Column-1){x=0;y=y+2;}
if(SIZE==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
}
else
{
OLED_Set_Pos(x,y+1);
for(i=0;i<6;i++)
{
OLED_WR_Byte(F6x8[c][i],OLED_DATA);
}
}
}
void OLED_ShowChar111(unsigned char x,unsigned char y,unsigned int chr) //字符取反 (背景和数据)
{
unsigned int c=0,i=0;
c=chr-' ';
if(x>Max_Column-1){x=0;y=y+2;}
if(SIZE==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(~F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(~F8X16[c*16+i+8],OLED_DATA);
}
else
{
OLED_Set_Pos(x,y+1);
for(i=0;i<6;i++)
{
OLED_WR_Byte(~F6x8[c][i],OLED_DATA);
}
}
}
unsigned int oled_pow(unsigned char m,unsigned char n)
{
unsigned int result=1;
while(n--)result*=m;
return result;
}
void OLED_ShowNum(unsigned char x,unsigned char y,unsigned int num,unsigned char len,unsigned char size)
{
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』