IIC协议——OLED(128*64)外设

IIC协议(Inter-Integrated Circuit Protocol),也被称为I2C(Inter-Integrated Circuit),是一种串行通信协议,通常用于连接集成电路(IC)和外部设备,例如传感器、存储器、显示屏等。该协议由飞利浦(现在的恩智浦半导体)于上世纪80年代开发,旨在实现在狭小空间内进行低速、短距离的数据传输。

IIC协议采用主从架构。主设备控制通信总线,并负责启动和停止数据传输。从设备被动地响应主设备的指令,并提供所需的数据或执行相应的操作。

IIC协议的特点包括:

  1. 双线制:IIC总线由两根线构成,即串行数据线(SDA)和串行时钟线(SCL)。SDA负责数据传输,而SCL则负责同步时钟信号。

  2. 多主机支持:多个主设备可以在同一个IIC总线上共存,通过地址冲突解决算法实现对总线的控制。

  3. 支持多种速率:IIC协议支持不同的时钟频率,可以根据应用的需求选择适当的通信速率。

  4. 简单且成本低廉:由于只需要两根线路,因此成本低廉且易于实现。

IIC协议被广泛应用于各种嵌入式系统、传感器网络、物联网设备等领域,因其简单、可靠且成本低廉而备受青睐。

数据传输的完整流程如下:

  1. 起始信号(Start Signal):主设备发送起始信号,标志着数据传输的开始。它是在时钟信号(SCL)保持高电平时,数据线(SDA)由高电平转变为低电平。

  2. 地址+读/写位(Address + Read/Write Bit):主设备发送要通信的从设备地址,以及读/写位。地址的最高位指示了读取还是写入操作。

  3. 应答信号(Acknowledge Signal):接收设备(从设备)在成功接收到地址+读/写位后,发送应答信号作为确认。

  4. 数据传输(Data Transmission):主设备开始发送或接收数据,通过在每个时钟周期内在数据线(SDA)上改变电平来传输数据位。时钟信号(SCL)控制数据传输的时机和持续时间。

  5. 应答信号(Acknowledge Signal):每个数据字节的传输结束后,接收设备发送应答信号作为确认。

  6. 停止信号(Stop Signal):主设备发送停止信号,标志着数据传输的结束。它是在时钟信号(SCL)保持高电平时,数据线(SDA)由低电平转变为高电平。

这样的流程形成了完整的数据传输周期。起始信号和停止信号的发送以及应答信号的接收是确保数据传输顺利进行的重要步骤,而时钟信号和数据信号则负责实际的数据传输。

#include "reg52.h"
#include "intrins.h"

sbit SCL = P1^0;
sbit SDA = P1^1;

//起始信号
void IIC_Start()
{
	SCL = 0;
	SDA = 1;
	SCL = 1;
	_nop_();
	SDA = 0;
	_nop_();
}

//停止信号
void IIC_Stop()
{
	SCL = 0;
	SDA = 0;
	SCL = 1;
	_nop_();
	SDA = 1;
	_nop_();
}

//应答信号
char IIC_ACK()
{
	char flag;
	SDA = 1;
	_nop_();
	SCL = 1;
	_nop_();
	flag = SDA;
	_nop_();
	SCL = 0;
	_nop_();
	return flag;
}

//数据发送
void IIC_SendByte(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_SendByte(0x78);
	IIC_ACK();
	IIC_SendByte(0x00);
	IIC_ACK();
	IIC_SendByte(dataCmd);
	IIC_ACK();
	IIC_Stop();
}

//写数据
void Oled_Write_Data(char dataData)
{
	IIC_Start();
	IIC_SendByte(0x78);
	IIC_ACK();
	IIC_SendByte(0x40);
	IIC_ACK();
	IIC_SendByte(dataData);
	IIC_ACK();
	IIC_Stop();
}

//OLED初始化
void Oled_Init(void){
	Oled_Write_Cmd(0xAE);//--display off
	Oled_Write_Cmd(0x00);//---set low column address
	Oled_Write_Cmd(0x10);//---set high column address
	Oled_Write_Cmd(0x40);//--set start line address
	Oled_Write_Cmd(0xB0);//--set page address
	Oled_Write_Cmd(0x81); // contract control
	Oled_Write_Cmd(0xFF);//--128
	Oled_Write_Cmd(0xA1);//set segment remap
	Oled_Write_Cmd(0xA6);//--normal / reverse
	Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
	Oled_Write_Cmd(0x3F);//--1/32 duty
	Oled_Write_Cmd(0xC8);//Com scan direction
	Oled_Write_Cmd(0xD3);//-set display offset
	Oled_Write_Cmd(0x00);//
	Oled_Write_Cmd(0xD5);//set osc division
	Oled_Write_Cmd(0x80);//
	Oled_Write_Cmd(0xD8);//set area color mode off
	Oled_Write_Cmd(0x05);//
	Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
	Oled_Write_Cmd(0xF1);//
	Oled_Write_Cmd(0xDA);//set com pin configuartion
	Oled_Write_Cmd(0x12);//
	Oled_Write_Cmd(0xDB);//set Vcomh
	Oled_Write_Cmd(0x30);//
	Oled_Write_Cmd(0x8D);//set charge pump enable
	Oled_Write_Cmd(0x14);//
	Oled_Write_Cmd(0xAF);//--turn on oled panel
}

//清屏函数
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);
		}
	}
}

/*--  调入了一幅图像:D:\桌面\无标题.bmp  --*/
/*--  宽度x高度=128x64  --*/
code unsigned char GGImage[] = {
								0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x80,0xC0,0x80,0x80,0x00,0x00,0x00,0x80,
								0x80,0x80,0xC0,0xC0,0xE0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xE0,0xE0,0xE0,0xE0,0xE0,
								0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xF8,0xF8,0xF8,
								0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF0,0xF0,0xF0,0xF0,0xF0,0xC0,0xC0,0x80,
								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,0x80,0x80,0xE0,0xF0,0xF8,0xF8,0xF0,0xF8,
								0xF0,0xF2,0xFE,0xFE,0xFC,0xFD,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x3F,0x3F,
								0x3F,0x3F,0x3F,0x3F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x3F,
								0x3F,0x3F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0xC0,0x80,0x80,0x80,
								0x00,0x40,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xC0,0xE0,0xF0,
								0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x21,0x20,0x20,0x10,0x10,
								0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x20,0x20,0x20,0x20,0x40,0x40,0x80,0x80,0x00,
								0x00,0x00,0x80,0xC0,0x40,0x60,0x21,0x23,0x27,0x3F,0x1F,0x3F,0x3F,0x7F,0x7F,0x7F,
								0x7F,0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFC,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x1C,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
								0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x3F,
								0x1F,0x1F,0xFF,0xCF,0x0F,0x0F,0x0F,0x0F,0x07,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1C,0x1C,0x1C,0x08,0x00,0x00,0x81,0xFF,
								0xFF,0xC3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x08,0x18,0x1C,0x18,0x08,0x00,0x00,0x81,0xFF,0x7F,0x03,0x03,0x03,0x07,0x07,
								0x0F,0x1F,0x3F,0xFF,0xFF,0x3F,0x1F,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x1F,0x1F,0x1F,0x3F,0x3F,
								0x3F,0x3F,0x7F,0x7F,0xFF,0xFF,0xFF,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
								0x8F,0xCF,0xEF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF9,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,
								0xF8,0xF0,0xF0,0xE1,0xC3,0x82,0x06,0x04,0x0C,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
								0x08,0xC8,0xE8,0x78,0xB8,0x98,0x98,0x08,0x0C,0x0C,0x0C,0x06,0x06,0x05,0x05,0x04,
								0x04,0x05,0x07,0x06,0x04,0x0C,0x0C,0x08,0x08,0x18,0x98,0xB8,0xF8,0xE8,0xC8,0x08,
								0x08,0x08,0x08,0x04,0x84,0xC6,0xE2,0xF3,0xF1,0xF0,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,
								0xF8,0xF0,0xF0,0xE3,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0xE0,0xE0,0xF0,
								0xF0,0xF8,0xF8,0xF8,0xF8,0xFC,0xFF,0xFE,0xFC,0xF0,0x60,0xC0,0xC0,0x80,0x00,0x03,
								0x0F,0x1F,0x1F,0x3F,0x3F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x3F,
								0x3F,0x3F,0x1F,0x1F,0x0F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x03,0x07,0x06,0x0C,0x0D,0x09,0x1B,0x1B,0x1B,0x13,0x12,0x12,0x12,0x16,0x16,
								0x16,0x16,0x16,0x16,0x16,0x12,0x12,0x1B,0x1B,0x1B,0x0D,0x0D,0x07,0x03,0x01,0x00,
								0x00,0x00,0x00,0x00,0x03,0x0F,0x1F,0x1F,0x1F,0x3F,0x3F,0x3F,0xBF,0x9F,0xDF,0x6F,
								0x3F,0x1F,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xFC,0xFF,0x7F,0x3F,0x9F,0x7F,0x3F,0x9F,0xBF,
								0x3F,0xBF,0xBF,0x3F,0x7F,0xFF,0xFF,0x3F,0x3F,0xBF,0x3F,0x3E,0x6F,0x7B,0x7B,0x73,
								0x36,0x1E,0x7C,0xFC,0xF8,0x38,0x38,0x98,0x38,0x38,0xB0,0x30,0x10,0x90,0x30,0x30,
								0xF0,0xF0,0xF0,0xB0,0x30,0x30,0xB0,0xF0,0x70,0xB0,0x30,0x30,0xB0,0x30,0x30,0xF0,
								0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
								0xF0,0xB0,0xB0,0xB0,0x30,0x20,0xA0,0xA0,0xA0,0xB0,0xE0,0xE0,0xE0,0xE0,0x20,0x20,
								0x30,0x70,0x50,0xF8,0x38,0x38,0xBC,0xBC,0xDE,0xFE,0xFB,0xF9,0x39,0x90,0x30,0x20,
								0xA0,0xE0,0x20,0x20,0xA0,0xA0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x3E,0x3E,0x70,0x7F,0xFB,0x78,0x75,0x77,
								0x70,0x7C,0x7C,0xF9,0xFB,0xFF,0x7F,0x53,0x1A,0x58,0xF8,0xFB,0xFF,0xFC,0xF5,0xF7,
								0xF0,0xF0,0xFF,0xFF,0xFF,0xF7,0xF0,0xF1,0xF4,0xD0,0x11,0x14,0xF3,0xF4,0xF0,0xF1,
								0xF7,0xFF,0xFF,0xF6,0xF0,0xF8,0xFA,0xFB,0xF8,0xF5,0xF0,0xF0,0xFC,0xF8,0xFB,0xFF,
								0xFF,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,0xFF,
								0xF6,0xF6,0xFA,0xF8,0xFC,0x98,0x90,0xF6,0xF6,0xF6,0xF2,0xFB,0xFF,0xFF,0xF0,0xF8,
								0xFD,0xFC,0x1C,0xD3,0xF8,0xFE,0xFE,0xF0,0xFA,0xFF,0xFF,0xFF,0xF6,0xF2,0xF8,0xF8,
								0xFA,0xDE,0x10,0x10,0x1B,0x1B,0x10,0x10,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00};

void Show_Image(char *GGImage)
{
	unsigned char i;
	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(GGImage[j]);
		}
	}
}

void main()
{
	
	//1. OLED初始化
	Oled_Init();
	//2. 选择一个位置
	//2.1 确认页寻址模式
	Oled_Write_Cmd(0x20);
	Oled_Write_Cmd(0x02);
	Oled_Clear();
	//2.2 选择PAGE0 1011 0000
	// 0xB0
	Oled_Write_Cmd(0xB0);
	//从page0的第0列开始写数据上半部分
	Oled_Write_Cmd(0x00);
	Oled_Write_Cmd(0x10);
	Show_Image(GGImage);
	while(1);
}

### 回答1: 0.96寸I2C IIC通信128*64 OLED液晶屏模块的原理图是一张用电子元器件和连接线路等表示的图表,用于显示该液晶屏模块的电路连接和工作原理。 在原理图中,可以看到模块的主要组成部分。首先是液晶屏,它是整个模块的显示部分,具有128列和64行的像素点阵,通过I2C IIC通信方式与主控芯片连接。 主控芯片位于模块的核心位置,它负责控制液晶屏的工作,并与外部设备进行通信。主控芯片通过I2C IIC通信总线与其他硬件连接,如外部存储器、传感器等。在原理图中,可以看到主控芯片周围的连接电阻、电容、晶振等元件,这些元件在整个电路中起到支持、稳定等作用。 另外,模块中还包含了电源管理部分,用于提供电压和电流给液晶屏和主控芯片。这部分包括电源开关、稳压电路、滤波电容等。 此外,原理图还显示了模块的连接方式,如I2C IIC通信接口、电源接口、外设连接接口等。这些接口可以连接到外部设备,如单片机、传感器等,实现与其他电子设备的互联。 总体来说,0.96寸I2C IIC通信128*64 OLED液晶屏模块原理图展示了该模块的电路连接和工作原理,帮助开发人员理解模块的组成和功能,为进一步的开发和应用提供参考。 ### 回答2: 0.96寸i2c iic通信128*64 OLED液晶屏模块原理图,通常包含以下主要组成部分:控制芯片、显示面板、I2C接口以及电源电路。 首先,液晶屏模块通常集成了一个控制芯片,这个芯片负责处理从主控制器接收到的显示数据,并将其转化为适合显示的信号。控制芯片通常是通过I2CIIC通信接口与主控制器进行连接。通过这个接口,主控制器可以向液晶屏发送指令和数据,控制显示内容和格式。 其次,液晶屏模块中的显示面板是显示信息的最重要组成部分。这个面板通常由128行和64列的液晶像素点阵组成,每个像素点可以显示不同的颜色和亮度。显示面板是被控制芯片驱动的,根据控制芯片的指令和数据,液晶屏会相应地点亮或熄灭每一个像素点,从而实现显示功能。 此外,I2C接口是液晶屏模块与主控制器之间的通信接口。I2C接口是一种串行通信协议,用于在不同设备之间传送数据。通过I2C接口,主控制器可以向液晶屏模块发送指令、数据和其他控制信号,从而控制液晶屏的显示内容和操作。 最后,液晶屏模块还包含一个电源电路,用于提供液晶屏驱动所需的电源。这个电路通常由电源管理芯片、电容、电阻等组成,确保液晶屏能够正常运行并保持稳定的工作电压和电流。 综上所述,0.96寸i2c iic通信128*64 OLED液晶屏模块原理图主要包含控制芯片、显示面板、I2C接口以及电源电路等组成部分,通过这些部件的协同工作,液晶屏模块能够接收主控制器发送的指令和数据,并在显示面板上显示相应的内容。 ### 回答3: 0.96寸I2C IIC通信128*64 OLED液晶屏模块的原理图是用来描述该模块内部电路连接关系和工作原理的图纸。液晶屏模块主要由屏幕控制芯片、驱动芯片和显示屏组成。 在原理图中,屏幕控制芯片是连接OLED显示屏的主要接口,通过I2CIIC通信协议与外部主控芯片进行通信。该芯片负责接收来自主控芯片的命令和数据,并将其转化为对显示屏的控制信号和图像信号。 驱动芯片是连接显示屏的关键组件,负责将屏幕控制芯片发出的信号转化为驱动显示屏所需的电流和电压信号。驱动芯片还可以控制液晶屏模块的亮度、对比度、颜色等参数,以及完成像素点的颜色变化。 显示屏是液晶屏模块的重要设备,由128行和64列的像素点构成,每个像素点可以显示不同的颜色和亮度。在原理图中,显示屏的每个像素点与驱动芯片通过细丝连接,通过控制电路可以控制每个像素点的亮灭和颜色。 除了以上核心组件,原理图中还可能包含其他辅助电路,例如电源电路、电容电路、电阻电路等。这些辅助电路可以提供所需的电压和电流,确保液晶屏模块正常工作。 总之,0.96寸I2C IIC通信128*64 OLED液晶屏模块的原理图是解释了该模块内部各个电路之间的连接关系和工作原理,为开发人员提供了设计和调试参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值