static uint8_t OLED_WriteData(uint8_t Data)
{
I2C_Start();
I2C_SendByte(I2C_OLED);
if(I2C_WaitAck())
return 1;
I2C_SendByte(0x40);
if(I2C_WaitAck())
return 2;
I2C_SendByte(Data);
if(I2C_WaitAck())
return 3;
I2C_Stop();
return 0;
}
static uint8_t OLED_SetXY(uint8_t x,uint8_t y)
{
OLED_WriteCmd(0xb0|y);//y
OLED_WriteCmd(((0xf0&x)>>4))|0x10);//设置x高4位
OLED_WriteCmd(((0x0f&x)>>4))|0x01);//设置x低4位
}
uint8_t OLED_Clear(void)
{
uint8_t x,y;
OLED_SetXY(0,0);
for(y=0;y<OLED_HIGH/8;y++)
{
if(OLED_SetXY(0,y))
return 1;
for(x=0;x<OLED_WIDTH;x++)
{
if(OLED_WriteData(0x00))
return 2;
}
}
return 0;
}
uint8_t OLED_Init(void)
{
// 延时一下 再初始化 OLED_Delay(100000); if(OLED_WriteCmd(0xae))
return 1;//--turn off oled panel
if(OLED_WriteCmd(0x00))
return 2;//---set low column address
if(OLED_WriteCmd(0x10))
return 3;//---set high column address
if(OLED_WriteCmd(0x40))
return 4;//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
if(OLED_WriteCmd(0x81))
return 5;//--set contrast control register
if(OLED_WriteCmd(Brightness))
return 6; // Set SEG Output Current Brightness
if(OLED_WriteCmd(0xa1))
return 7;//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
if(OLED_WriteCmd(0xc8))
return 8;//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
if(OLED_WriteCmd(0xa6))
return 9;//--set normal display
if(OLED_WriteCmd(0xa8))
return 10;//--set multiplex ratio(1 to 64)
if(OLED_WriteCmd(0x3f))
return 11;//--1/64 duty
if(OLED_WriteCmd(0xd3))
return 12;//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
if(OLED_WriteCmd(0x00))
return 13;//-not offset
if(OLED_WriteCmd(0xd5))
return 14;//--set display clock divide ratio/oscillator frequency
if(OLED_WriteCmd(0x80))
return 15;//--set divide ratio, Set Clock as 100 Frames/Sec
if(OLED_WriteCmd(0xd9))
return 16;//--set pre-charge period
if(OLED_WriteCmd(0xf1))
return 17;//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
if(OLED_WriteCmd(0xda))
return 18;//--set com pins hardware configuration
if(OLED_WriteCmd(0x12))
return 19;
if(OLED_WriteCmd(0xdb))
return 20;//--set vcomh
if(OLED_WriteCmd(0x40))
return 21;//Set VCOM Deselect Level
if(OLED_WriteCmd(0x20))
return 22;//-Set Page Addressing Mode (0x00/0x01/0x02)
if(OLED_WriteCmd(0x02))
return 23;//
if(OLED_WriteCmd(0x8d))
return 24;//--set Charge Pump enable/disable
if(OLED_WriteCmd(0x14))
return 25;//--set(0x10) disable
if(OLED_WriteCmd(0xa4))
return 26;// Disable Entire Display On (0xa4/0xa5)
if(OLED_WriteCmd(0xa6))
return 27;// Disable Inverse Display On (0xa6/a7)
if(OLED_WriteCmd(0xaf))
return 28;//--turn on oled panel
if(OLED_Clear(0x00))
return 29; //初始清屏
if(OLED_SetXY(0,0))
return 30;
return 0;
}
|