#include "OLED.h"
#include "codetab.h"
/*********************LCD 设置坐标************************************/
void LCD_Set_Pos(unsigned char x, unsigned char y)
{
Write_IIC_Command(0xb0+y);
Write_IIC_Command(((x&0xf0)>>4)|0x10);
Write_IIC_Command((x&0x0f)|0x01);
}
/***************功能描述:显示6*8一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void LCD_P6x8Str(unsigned char x, 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++;}
LCD_Set_Pos(x,y);
for(i=0;i<6;i++)
Write_IIC_Data(F6x8[c][i]);
x+=6;
j++;
}
}
//*******************功能描述:显示8*16一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void LCD_P8x16Str(unsigned char x, 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++;}
LCD_Set_Pos(x,y);
for(i=0;i<8;i++)
Write_IIC_Data(F8X16[c*16+i]);
LCD_Set_Pos(x,y+1);
for(i=0;i<8;i++)
Write_IIC_Data(F8X16[c*16+i+8]);
x+=8;
j++;
}
}
/*****************功能描述:显示16*16点阵 显示的坐标(x,y),y为页范围0~7****************************/
void LCD_P16x16Ch(unsigned char x, y, N)
{
unsigned char wm=0;
unsigned int adder=32*N;
LCD_Set_Pos(x , y);
for(wm = 0;wm < 16;wm++)
{
// Write_IIC_Data(F16x16[adder]);
adder += 1;
}
LCD_Set_Pos(x,y + 1);
for(wm = 0;wm < 16;wm++)
{
// Write_IIC_Data(F16x16[adder]);
adder += 1;
}
}
/*********************LCD复位************************************/
void LCD_CLS(void)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
Write_IIC_Command(0xb0+y);
Write_IIC_Command(0x01);
Write_IIC_Command(0x10);
for(x=0;x<X_WIDTH;x++)
Write_IIC_Data(0);
}
}
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
fill_picture(0x00); //初始清屏
LCD_Set_Pos(0,0);
}
/**********************************************
//IIC Start
**********************************************/
void IIC_Start()
{
SCL = high;
SDA = high;
SDA = low;
SCL = low;
}
/**********************************************
//IIC Stop
**********************************************/
void IIC_Stop()
{
SCL = low;
SDA = low;
SCL = high;
SDA = high;
}
/**********************************************
// IIC Write byte
**********************************************/
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(IIC_Byte & 0x80)
SDA=high;
else
SDA=low;
SCL=high;
SCL=low;
IIC_Byte<<=1;
}
SDA=1;
SCL=1;
SCL=0;
}
/**********************************************
// 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();
}
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_fan1(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<24;m++)
{
Write_IIC_Data(show1[i++]);
}
}
}
void Picture_fan2(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<24;m++)
{
Write_IIC_Data(show2[i++]);
}
}
}
void Picture_temp1(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<4;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<16;m++)
{
Write_IIC_Data(show3[i++]);
}
}
}
void Picture_temp2(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<2;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<16;m++)
{
Write_IIC_Data(show4[i++]);
}
}
}
void Picture_rh(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<4;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<32;m++)
{
Write_IIC_Data(show5[i++]);
}
}
}
void Picture_bai(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<2;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<16;m++)
{
Write_IIC_Data(show6[i++]);
}
}
}
void Picture_shan(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<24;m++)
{
Write_IIC_Data(show7[i++]);
}
}
}
void Picture_logo(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<1;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<24;m++)
{
Write_IIC_Data(show8[i++]);
}
}
}
void Picture_feng1(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<16;m++)
{
Write_IIC_Data(show9[i++]);
}
}
}
void Picture_feng2(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<16;m++)
{
Write_IIC_Data(show10[i++]);
}
}
}
void Picture_feng3(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m=0;m<16;m++)
{
Write_IIC_Data(show11[i++]);
}
}
}
void Picture_feng4(uchar x,uchar y)
{
unsigned char m,n;
unsigned int i=0;
for(n=0;n<3;n++)
{
LCD_Set_Pos(x,y++);
for(m