void delay(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<500;jj++);
}
/****主函数*****/
void main(void)
{
OLED_Init();
delay(5);
while(1)
{
OLED_ShowCN(3,0,1);
OLED_ShowCN(21,0,2);
delay(500);
//delay(500);
//OLED_Fill(0xff);
//delay(1000);
}
}
/*******************************************
//OLED: x,y -- 起始点坐标(x:0~127, y:0~7); N:汉字在codetab.h中的索引 ----OK
********************************************/
void OLED_ShowCN(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++)
{
Write_IIC_Data(F16x16[adder]);
adder += 1;
}
OLED_SetPos(x,y + 1);
for(wm = 0;wm < 16;wm++)
{
Write_IIC_Data(F16x16[adder]);
adder += 1;
}
}/***************************16*16的点阵字体取模方式:共阴——列行式——逆向输出*********/
const unsigned char F16x16[] =
{
0x7F,0x8F,0xFF,0x00,0xDF,0xEF,0xF7,0xB7,0xB7,0x00,0xB7,0xB7,0xB7,0xB7,0xF7,0xFF,
0x7F,0x9F,0xE7,0xF8,0xF7,0xCF,0xFD,0xFD,0xFD,0x00,0xFD,0xFD,0xED,0xDD,0xE1,0xFF,//"炜",0
0x80,0x70,0x00,0xFF,0x20,0x10,0x08,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0x08,0x00,
0x80,0x60,0x18,0x07,0x08,0x30,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,//"炜",0
};
引脚设置没问题,程序能成功编译
按正常思路第二个炜字可以正常显示,但实际一直黑屏,以下这个显示图片的就能正常运行,那么oled屏自身应该没问题吧
#include "reg52.h"
#define high 1
#define low 0
/*************Pin Define***************/
sbit SCL=P1^2;
sbit SDA=P1^3;
#define uchar unsigned char
#define uint unsigned int
uint Value,A1,A2,A3;
sfr P5=0xc8;
/****************************************************/
void Initial_LY096BG30(); //初始化显示屏
void Delay_50ms(unsigned int Del_50ms);
void Delay_1ms(unsigned int Del_1ms);
void fill_picture(unsigned char fill_Data);//
void Picture_1();
void IIC_Start();
void IIC_Stop();
void Write_IIC_Command(unsigned char IIC_Command);//写入协议的命令
void Write_IIC_Data(unsigned char IIC_Data);
void Write_IIC_Byte(unsigned char IIC_Byte);
/***********************Initial code*********************/
void Initial_LY096BG30()
{
Write_IIC_Command(0xAE); //display off
Write_IIC_Command(0x20); //Set Memory Addressing Mode
Write_IIC_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
Write_IIC_Command(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
Write_IIC_Command(0xc8); //Set COM Output Scan Direction
Write_IIC_Command(0x00);//---set low column address 低列的起始地址
Write_IIC_Command(0x10);//---set high column address 高列的起始地址
Write_IIC_Command(0x40);//--set start line address 开始行地址
Write_IIC_Command(0x81);//--set contrast control register 对比控制寄存器
Write_IIC_Command(0x7f);
Write_IIC_Command(0xa1);//--set segment re-map 0 to 127 设置段再现0到127
Write_IIC_Command(0xa6);//--set normal display
Write_IIC_Command(0xa8);//--set multiplex ratio(1 to 64) 设置多路复用率(1到64)
Write_IIC_Command(0x3F);//
Write_IIC_Command(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content
Write_IIC_Command(0xd3);//-set display offset
Write_IIC_Command(0x00);//-not offset
Write_IIC_Command(0xd5);//--set display clock divide ratio/oscillator frequency
Write_IIC_Command(0xf0);//--set divide ratio
Write_IIC_Command(0xd9);//--set pre-charge period
Write_IIC_Command(0x22); //
Write_IIC_Command(0xda);//--set com pins hardware configuration
Write_IIC_Command(0x12);
Write_IIC_Command(0xdb);//--set vcomh
Write_IIC_Command(0x20);//0x20,0.77xVcc
Write_IIC_Command(0x8d);//--set DC-DC enable
Write_IIC_Command(0x14);//
Write_IIC_Command(0xaf);//--turn on oled panel
}
/***********************Picture Code**************************/
unsigned char code show1[]=
{
0X08,0X20,0X06,0X20,0X40,0X7E,0X31,0X80,0X00,0X02,0X00,0X7E,0X7F,0X42,0X49,0X42,
0X49,0X7E,0X49,0X42,0X49,0X7E,0X49,0X42,0X7F,0X42,0X00,0X7E,0X00,0X02,0X00,0X00,//"温",0
0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
0x0C,0xFE,0xFE,0x0C,0x08,0x20,0x60,0xFE,0xFE,0x60,0x20,0x00,0x00,0x00,0x78,0x48,
0xFE,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xFE,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xFF,0xFF,0x00,0x00,0xFE,0xFF,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xFF,0xFE,0x00,0x00,0x00,0x00,0xC0,0xC0,
0xC0,0x00,0x00,0x00,0x00,0xFE,0xFF,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0xFF,0xFE,0x00,0x00,0xFE,0xFF,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xFF,
0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x0C,
0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0xFF,0xFF,0x00,0x00,0x00,0x00,0xE1,0xE1,
0xE1,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x0F,0x00,0x00,0x0F,0x1F,0x18,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
0x1F,0x0F,0x00,0x00,0x0F,0x1F,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1F,
0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE2,0x92,0x8A,0x86,0x00,0x00,0x7C,0x82,0x82,0x82,0x7C,
0x00,0xFE,0x00,0x82,0x92,0xAA,0xC6,0x00,0x00,0xC0,0xC0,0x00,0x7C,0x82,0x82,0x82,
0x7C,0x00,0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0xC0,0xC0,0x00,0x7C,0x82,0x82,0x82,
0x7C,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x24,0xA4,0x2E,0x24,0xE4,0x24,0x2E,0xA4,0x24,0x00,0x00,0x00,0xF8,0x4A,0x4C,
0x48,0xF8,0x48,0x4C,0x4A,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0x10,
0x10,0x10,0x20,0xC0,0x00,0x00,0xC0,0x20,0x10,0x10,0x10,0x10,0x20,0xC0,0x00,0x00,
0x00,0x12,0x0A,0x07,0x02,0x7F,0x02,0x07,0x0A,0x12,0x00,0x00,0x00,0x0B,0x0A,0x0A,
0x0A,0x7F,0x0A,0x0A,0x0A,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x40,0x40,
0x40,0x50,0x20,0x5F,0x80,0x00,0x1F,0x20,0x40,0x40,0x40,0x50,0x20,0x5F,0x80,0x00,
};
/**********************************************
//IIC Start
**********************************************/
void IIC_Start()
{
SCL = high;
//Delay_us(1);
SDA = high;
//Delay_us(1);
SDA = low;
// Delay_us(1);
SCL = low;
// Delay_us(1);
}
/**********************************************
//IIC Stop
**********************************************/
void IIC_Stop()
{
SCL = low;
//Delay_us(1);
SDA = low;
//Delay_us(1);
SCL = high;
//Delay_us(1);
SDA = high;
//Delay_us(1);
}
/**********************************************
// IIC Write byte
**********************************************/
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(IIC_Byte & 0x80) //1?0?
SDA=high;
else
SDA=low;
//Delay_us(1);
SCL=high;
//Delay_us(1);
SCL=low;
//Delay_us(1);
IIC_Byte<<=1; //loop
}
SDA=1;
//Delay_us(1);
SCL=1;
//Delay_us(1);
SCL=0;
//Delay_us(1);
}
/**********************************************
// IIC Write Command
**********************************************/
void Write_IIC_Command(unsigned char IIC_Command)
{
IIC_Start();
Write_IIC_Byte(0x78); //Slave address,SA0=0
Write_IIC_Byte(0x00); //write command
Write_IIC_Byte(IIC_Command);
IIC_Stop();
}
/**********************************************
// IIC Write Data
**********************************************/
void Write_IIC_Data(unsigned char IIC_Data)
{
IIC_Start();
Write_IIC_Byte(0x78);
Write_IIC_Byte(0x40); //write data
Write_IIC_Byte(IIC_Data);
IIC_Stop();
}
/********************************************
// fill_Picture 怎样的对应关系
********************************************/
void fill_picture(unsigned char fill_Data)
{
unsigned char m,n;
for(m=0;m<8;m++)
{
Write_IIC_Command(0xb0+m); //page0-page1
Write_IIC_Command(0x00); //low column start address
Write_IIC_Command(0x10); //high column start address
for(n=0;n<128;n++)
{
Write_IIC_Data(fill_Data);
}
}
}
/******************************************
// picture
******************************************/
void picture_1()
{
unsigned char x,y;
unsigned int i=0;
for(y=0;y<8;y++)
{
Write_IIC_Command(0xb0+y);
Write_IIC_Command(0x00);
Write_IIC_Command(0x10);
for(x=0;x<128;x++)
{
Write_IIC_Data(show1[i++]);//将show[1]中显示完
}
}
}
/********************picture**********************/
void picture_2()
{
unsigned char x,y;
unsigned int i=0;
for(Value=0;Value<1000;Value++)
{
A1=Value/100;
A2=(Value-A1*100)/10;
A3=Value-A1*100-A2*10;
for(y=0;y<2;y++)
{
Write_IIC_Command(0XB0+y); //纵向页
Write_IIC_Command(0X20); //横向离左部边缘开始的距离
Write_IIC_Command(0X10); //10--17横向第0到第七个字
for(x=0;x<8;x++) //横向像素
{
Write_IIC_Data(show1[x+y*8+A1*16]);
}
}
for(y=0;y<2;y++)
{
Write_IIC_Command(0XB0+y);//纵向页
Write_IIC_Command(0X20); //横向离左部边缘开始的距离
Write_IIC_Command(0X11); //10--17横向第0到第七个字
for(x=0;x<8;x++) //横向像素
{
Write_IIC_Data(show1[x+y*8+A2*16]);
}
}
for(y=0;y<2;y++)
{
Write_IIC_Command(0XB0+y);//纵向页
Write_IIC_Command(0X20); //横向离左部边缘开始的距离
Write_IIC_Command(0X12); //10--17横向第0到第七个字
for(x=0;x<8;x++) //横向像素
{
Write_IIC_Data(show1[x+y*8+A3*16]);
}
}
Delay_50ms(3);
}
}
/***********************Delay****************************************/
void Delay_50ms(unsigned int Del_50ms) //
{
unsigned int m;
for(;Del_50ms>0;Del_50ms--)
for(m=6245;m>0;m--);
}
void Delay_1ms(unsigned int Del_1ms) //
{
unsigned char j;
while(Del_1ms--)
{
for(j=0;j<123;j++);
}
}
/*******************************Main*******************************/
void main(void)
{
//
Initial_LY096BG30();
Delay_1ms(5);
while(1)
{
fill_picture(0xff); Delay_50ms(25);//满屏点亮
fill_picture(0xf0); Delay_50ms(25);//
Picture_1(); Delay_50ms(25);
// Picture_2(); Delay_50ms(25);
}
}
一周热门 更多>