标题:
0.96寸OLED驱动程序 驱动IC为SH1106G
[打印本页]
作者:
hslgyh
时间:
2019-4-9 08:16
标题:
0.96寸OLED驱动程序 驱动IC为SH1106G
进来项目需要进行了0.96寸OLED的驱动调试,驱动IC为SH1106G
该OLED接线方式为:8080接口/SPI接口/IIC接口
建议初学者采用SPI比较容易上手,谢谢!现将
资料上传,希望对你们有帮助!谢谢了!
0.png
(207.35 KB, 下载次数: 63)
下载附件
2019-4-9 15:36 上传
0.png
(422.5 KB, 下载次数: 52)
下载附件
2019-4-9 15:37 上传
单片机源程序如下:
/**
---------------------------------------------------------------------
**
** This device driver was created by
** 8-Bit Single-Chip Microcontrollers
**
** Copyright(C) visionox display Corporation 2002 - 2009
** All rights reserved by Kunshan visionox display Corporation.
**
** This program should be used on your own responsibility.
**
** Filename : SSD1305_Init.c
** Abstract : This file implements device driver for Initial SSD1306 IC function.
**
** Device : STC89LE516RD
**
** Compiler : KEIL uVision2
**
** Module
**
** Dot Matrix: 128*64
**
** Display Color:
**
** Driver IC:
**
** Edit :
**
** Creation date:
---------------------------------------------------------------------
**/
//
//
/****************************包含头文件***************************/
#include "reg52.h"
#include "intrins.h"
#include "IC.h"
#include "Delay.h"
#define Slave_Address 0x78 //0X3C 部分IIC主控会自动左移一位地址
#define OP_Data 0x40
#define OP_Command 0x00
//
//
#define Interface_IIC //定义通信方式接口8080、IIC、SPI
//
//
void Clear_Screen();
#ifdef Interface_8080
/**********************************************
//
//写命令函数
**********************************************/
//
//
void Write_Command(uchar command)
{
CS=low;
DC=low;
WR=low;
_nop_();_nop_();
P0=command;
WR=high;
_nop_();_nop_();
CS=high;
}
//
//
//
/**********************************************
//
//写数据函数
//
**********************************************/
//
//
void Write_Data(uchar date)
{
CS=low;
DC=high;
WR=low;
_nop_();_nop_();
P0=date;
WR=high;
_nop_();_nop_();
CS=high;
}
#endif
#ifdef Interface_IIC
/**********************************************
//
//IIC通信开始函数
//
**********************************************/
void IC_IIC_Start()
{
SDA = high;
SCL = high;
_nop_();
SDA = low;
_nop_();_nop_();
SCL = low;
}
/**********************************************
//
//IIC通信停止函数
//
**********************************************/
void IC_IIC_Stop()
{
SDA = low;
_nop_();
SCL = high;
_nop_();_nop_();
SDA = high;
}
/**********************************************
//
//向IIC写数据函数
//返回值为acknowledgement位信号
//
**********************************************/
bit Write_IIC_Data(uchar Data)
{
unsigned char i;
bit Ack_Bit; //应答信号
for(i = 0; i < 8; i++)
{
SDA = (bit)(Data & 0x80);
_nop_();
SCL = high;
_nop_();_nop_();
SCL = low;
Data = _crol_(Data,1);
}
SDA = high; //释放IIC SDA总线为主器件接收从器件产生应答信号
_nop_();_nop_();
SCL = high; //第9个时钟周期
_nop_();_nop_();
Ack_Bit = SDA; //读取应答信号
SCL = low;
return Ack_Bit;
}
/**********************************************
//
//写命令函数
**********************************************/
//
//
void Write_Command(uchar command)
{
IC_IIC_Start();
Write_IIC_Data(Slave_Address); //Salve Adress
Write_IIC_Data(OP_Command); //写命令
Write_IIC_Data(command);
IC_IIC_Stop();
}
/**********************************************
//
//写数据函数
//
**********************************************/
//
//
void Write_Data(uchar date)
{
IC_IIC_Start();
Write_IIC_Data(Slave_Address); //Salve Adress
Write_IIC_Data(OP_Data); //写数据
Write_IIC_Data(date);
IC_IIC_Stop();
}
#endif
#ifdef Interface_SPI
/**********************************************
//
//写命令函数
**********************************************/
//
//
void Write_Command(uchar command)
{
uchar i,value;
value = command;
CS = low;
DC = low;
for(i=0;i<8;i++)
{
SCL = low;
_nop_(); _nop_();
if(value & 0x80) SI = high;
else SI = low;
SCL = high;
_nop_(); _nop_();
value = _crol_(value, 1);
}
CS = high;
}
//
//
/**********************************************
//
//写命令函数
**********************************************/
//
//
void Write_Data(uchar date)
{
uchar i,value;
value = date;
CS = low;
DC = high;
for(i=0;i<8;i++)
{
SCL = low;
_nop_(); _nop_();
if(value & 0x80) SI = high;
else SI = low;
SCL = high;
_nop_(); _nop_();
value = _crol_(value, 1);
}
CS = high;
}
#endif
/******************************************************
//
//复位IC函数
//
******************************************************/
//
//
void Reset_IC()
{
Delay_Ms(10);
RES = low;
Delay_Ms(50);
RES = high;
Delay_Ms(100);
}
/******************************************************
//
//初始化IC函数
//
******************************************************/
void init_ic()
{
Write_Command(0xAE); //Set Display Off
Write_Command(0xD5); //Display divide ratio/osc. freq. mode
Write_Command(0x80); //
Write_Command(0xA8); //Multiplex ration mode:63
Write_Command(0x3F);
Write_Command(0xD3); //Set Display Offset
Write_Command(0x00);
Write_Command(0x40); //Set Display Start Line
Write_Command(0xAD); //DC-DC Control Mode Set
Write_Command(0x8B); //8A:External 8b:Built-in DC-DC is used
Write_Command(0x32); //Set Pump voltage value
Write_Command(0xA1); //Segment Remap
Write_Command(0xC8); //Set COM Output Scan Direction
Write_Command(0xDA); //Common pads hardware: alternative
Write_Command(0x12);
Write_Command(0x81); //Contrast control
Write_Command(0x40);
Write_Command(0xD9); //Set pre-charge period
Write_Command(0x1F);
Write_Command(0xDB); //VCOM deselect level mode
Write_Command(0x40);
Write_Command(0xA4); //Set Entire Display On/Off
Write_Command(0xA6); //Set Normal Display
Clear_Screen();
Write_Command(0xAF); //Set Display On
}
}
}
}
void Clear_Screen()
{
uchar page_number,column_number;
for(page_number=0;page_number<8;page_number++)
{
Write_Command(0xb0+page_number);
Write_Command(0x10);
Write_Command(0x02);
for(column_number=0;column_number<128;column_number++)
{
Write_Data(0x00);
}
}
}
void All_Screen()
{
uchar page_number,column_number;
for(page_number=0;page_number<8;page_number++)
{
Write_Command(0xb0+page_number);
Write_Command(0x10);
Write_Command(0x02);
for(column_number=0;column_number<128;column_number++)
{
Write_Data(0xFF);
}
}
}
void main()
{
Reset_IC();
init_ic();
All_Screen();
}
复制代码
作者:
paladina
时间:
2021-3-23 10:36
好东西,找了半天SH1106的驱动总算找到了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1