OLED之显示一张图片
#include "reg52.h"
#include "intrins.h"
sbit scl = P0^1;
sbit sda = P0^3;
void IIC_Start()
{
scl = 0;
scl = 1;
sda = 1;
_nop_();
sda = 0;
_nop_();
}
void IIC_Stop()
{
scl = 0;
scl = 1;
sda = 0;
_nop_();
sda = 1;
_nop_();
sda = 0;
}
char IIC_ACK()
{
char flag;
sda = 1;
_nop_();
scl = 1;
_nop_();
flag = sda;
_nop_();
scl = 0;
_nop_();
return flag;
}
void IIC_Send_Byte(char dataSend)
{
int i;
for(i = 0; i < 8; i++){
scl = 0;
sda = dataSend & 0x80;
_nop_();
scl = 1;
_nop_();
scl = 0;
_nop_();
dataSend = dataSend << 1;
}
}
void Oled_Write_Cmd(char dataCmd)
{
IIC_Start();
IIC_Send_Byte(0x78);
IIC_ACK();
IIC_Send_Byte(0x00);
IIC_ACK();
IIC_Send_Byte(dataCmd);
IIC_ACK();
IIC_Stop();
}
void Oled_Write_Data(char dataData)
{
IIC_Start();
IIC_Send_Byte(0x78);
IIC_ACK();
IIC_Send_Byte(0x40);
IIC_ACK();
IIC_Send_Byte(dataData);
IIC_ACK();
IIC_Stop();
}
void Oled_Init()
{
Oled_Write_Cmd(0xAE);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
Oled_Write_Cmd(0x40);
Oled_Write_Cmd(0xB0);
Oled_Write_Cmd(0x81);
Oled_Write_Cmd(0xFF);
Oled_Write_Cmd(0xA1);
Oled_Write_Cmd(0xA6);
Oled_Write_Cmd(0xA8);
Oled_Write_Cmd(0x3F);
Oled_Write_Cmd(0xC8);
Oled_Write_Cmd(0xD3);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0xD5);
Oled_Write_Cmd(0x80);
Oled_Write_Cmd(0xD8);
Oled_Write_Cmd(0x05);
Oled_Write_Cmd(0xD9);
Oled_Write_Cmd(0xF1);
Oled_Write_Cmd(0xDA);
Oled_Write_Cmd(0x12);
Oled_Write_Cmd(0xDB);
Oled_Write_Cmd(0x30);
Oled_Write_Cmd(0x8D);
Oled_Write_Cmd(0x14);
Oled_Write_Cmd(0xAF);
}
void Oled_Clear()
{
unsigned char i,j;
for(i = 0; i < 8; i++){
Oled_Write_Cmd(0xB0 + i);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(j = 0; j < 128; j++){
Oled_Write_Data(0);
}
}
}
code unsigned char bmpImager[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x20,0x10,0x00,0x08,0x08,0x08,0x08,0x10,0x10,0x70,0x98,0x08,0x28,0x28,0x48,0x80,
0x10,0x60,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xF8,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xC4,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
0x03,0x04,0x00,0x08,0x09,0x09,0x09,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x20,0x22,0x22,0x22,
0x21,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x1E,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x40,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x20,
0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x40,0x40,0x40,
0x00,0x00,0xC0,0x40,0x00,0x00,0x20,0x20,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x06,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x78,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE2,0x0C,0x12,0x32,0x3B,
0x0A,0x00,0x3E,0x00,0x00,0x00,0xFE,0x38,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x40,0x3C,0x1B,0x95,0x91,0x10,0x10,0x00,0x00,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x30,0x0E,0x00,0x00,0x00,0x80,0x40,0x30,0x0C,0x03,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x00,0x01,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,
0x04,0x04,0x05,0x02,0x02,0x02,0x00,0x00,0x00,0x02,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,0x1F,0x20,0x20,0x10,0x08,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void Oled_show_Image(unsigned char *image)
{
unsigned char i;
unsigned int j;
for(i = 0; i < 8; i++){
Oled_Write_Cmd(0xB0 + i);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(j = 128 * i; j < 128 * (i + 1); j++){
Oled_Write_Data(image[j]);
}
}
}
void main()
{
Oled_Init();
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);
Oled_Clear();
Oled_show_Image(bmpImager);
while(1);
}