/******************************************************
STC15W408ASP10显示屏驱动板驱动测试0.96英寸OLED程序
2015 7 12 15:30 PAST czdpj@163.com L253 CODE1030
测试显示阿拉伯数字通过
******************************************************/
#include "reg52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
uint Value,A1,A2,A3;
sfr P5=0xc8;
#define high 1
#define low 0
/*************Pin Define***************/
***it SCL=P5^5;
***it SDA=P5^4;
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_0();
void Picture_1();
void Picture();
void IIC_Start();
void IIC_Stop();
void Write_IIC_Command(unsigned char IIC_Command);
void Write_IIC_Data(unsigned char IIC_Data);
bit 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
Write_IIC_Command(0xa6); //--set normal display
Write_IIC_Command(0xa8); //--set multiplex ratio(1 to 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[]=
{
0x00,0xF0,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0X00,/*0CODE*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0X00,/*1CODE*/
0x00,0x70,0x08,0x08,0x08,0x08,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*2CODE*/
0X00,0X30,0X08,0X88,0X88,0X48,0X28,0X00,0X00,0X18,0X20,0X20,0X20,0X11,0X0E,0X00,/*3CODE*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*4CODE*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x18,0x21,0x20,0x20,0x11,0x0E,0x00,/*5CODE*/
0x00,0xE0,0x10,0x88,0x88,0x08,0x10,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*6CODE*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*7CODE*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*8CODE*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x10,0x21,0x22,0x22,0x11,0x0F,0x00,/*9CODE*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x1F,0x01,0x01,0x01,0x01,0x1F,0x00,/*ACODE*/
};
/***********************Picture Code**************************/
unsigned char code show2[]=
{
0x10,0x08,0x04,0x0F,0xB4,0xA4,0xB4,0xEC,0xA4,0xAF,0xF4,0x04,0x04,0x04,0x00,0X00,/*第CODE*/
0x00,0x00,0x40,0x20,0x13,0x0A,0x06,0xFF,0x02,0x11,0x22,0x22,0x3C,0x00,0x00,0X00,/*第CODE*/
};
/*******************IIC Start******************/
void IIC_Start()
{
SCL=high;
//Delay_us(1);
SDA=high;
_nop_();
SDA=low;
_nop_();_nop_();
SCL=low;
}
/*************IIC Stop*************************/
void IIC_Stop()
{
SDA=low;
_nop_();
SCL=high;
_nop_();_nop_();
SDA=high;
}
/*****************IIC Write byte***************/
bit Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
bit Ack_Bit; //应答信号
for(i=0;i<8;i++)
{
if(IIC_Byte & 0x80) //1?0?
SDA=high;
else
SDA=low;
//Delay_us(1);
SCL=high;
_nop_();_nop_();
SCL=low;
//Delay_us(1);
IIC_Byte<<=1; //loop
}
SDA=high; //释放IIC SDA总线为主器件接收从器件产生应答信号
_nop_();_nop_();
SCL=high; //第9个时钟周期
_nop_();_nop_();
Ack_Bit=SDA; //读取应答信号
SCL=low;
return Ack_Bit;
}
/*************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 cleardisp()
{
unsigned char x,y;
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(0X00);
}
}
}
/********************picture**********************/
void picture_1()
{
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(00); //横向离左部边缘开始的距离
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(00); //横向离左部边缘开始的距离
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(00); //横向离左部边缘开始的距离
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=62450;m>0;m--);
}
/**************Delay_1ms***************************/
void Delay_1ms(unsigned int Del_1ms) //
{
unsigned char j;
while(Del_1ms--)
{
for(j=0;j<123;j++);
}
}
/*******************************Main*******************************/
void main(void) // Value,A1,A2;
{
Initial_LY096BG30(); //初始化显示屏
Delay_1ms(5);
while(1)
{
Value=0;
cleardisp();
fill_picture(0xff); //全部填充显示屏
Delay_50ms(40);
cleardisp();
fill_picture(0x02); //全部填充显示屏
Delay_50ms(40);
cleardisp();
Picture_1(); //
}
}
|