赞
踩
目录
源码仓库链接;stm32 learning code: 记录stm32学习过程,源代码 (gitee.com)
1.GPIO输入输出(IO口配置)
iic是同步、半双工,带数据应答,支持总线挂载多设备。
硬件电路
关键概念说明
由于iic中时钟线和数据线都都配置为开漏输出模式,外接上拉电阻,所以空闲时SCL和SDA都为高电平。
1.起始信号:SCL高电平期间,SDA从高电平变为低电平,只能是主机产生。
2.发送一个字节:SCL低电平期间,主机机将数据依次放到SDA线上(高位先行,与串口相反),从机将在SCL高电平期间读取数据位,所以SCL高电平期间SDA不允许有数据变化(否则就变成了启停信号),依次循环8次,即可发送一个字节。
3.接收一个字节: SCL低电平期间(设置为开漏模式时,主机SDA要置1释放数据线),从机将数据依次放到SDA线上(高位先行,与串口相反),主机将在SCL高电平期间读取数据位,所以SCL高电平期间SDA不允许有数据变化(否则就变成了启停信号),依次循环8次,即可接收一个字节(主机在接收前,需要释放SDA,输出设置为1)。主机一般上升沿读取数据,从机下降沿以后就准备下一位数据。
4.终止信号:SCL高电平期间,SDA从低电平变为高电平。SCL高电平期间,SDA从低电平变为高电平。
5.发送应答:主机在接收完成一个字节之后,在下一个时钟发送一位数据,数据0表示应答(空闲的时候为高电平,所以低电平是有反馈的结果),数据1表示非应答。
6.接收应答:主机在发送完成一个字节之后,在下一个时钟发接收一位数据,数据0表示应答,数据1表示非应答(主机在接收之前,需要释放SDA)。
通信流程
从设备有多个寄存器时,设备将多个寄存器放到一个队列中,通过一个指针指向读写寄存器位置,每次读写数据后,该指针会自动加一,所以一次读写多个数据时,会自动依次读写后续寄存器数据
1.指定地址写(指定设备,指定寄存器写入数据)
2.指定地址读(指定设备,读取指定寄存器数据):先通过写命令,指定设备目标寄存器,再通过读命令获取指定寄存器数据
第十步主机的应答信号为非应答信号(高电平1)
分辨率128*64,显示确定坐标时,原点为左上角,y轴是向下的。长(x轴)128个像素点。宽(y轴)64个像素点。 宽度方向被均分为8块,每块称为一页,一页中有128个字节,每个字节就对应宽方向的8个像素点。
关键参数说明
iic配置流程
oled配置
1.iic配置
2.配置控制寄存器0x00:按照官方配置即可
硬件连接
oled-SCL->PB8
oled-SDA->PB9
oled-3V3->3V3
oled-GND->GND
iic使用流程如上通信流程说明
oled使用流程
1.设置光标位置(向控制寄存器0x00写数据),像素点坐标系中,写数据起始位置。每一次都是显存全部数据重写,太费时间了。
光标位置设置三部分
位置说明
实际代码
2.写数据(向数据寄存器0x40写数据)
通过iic使0.96寸oled显示屏字符串
iic.c
- #include "iic.h"
- #include "delay.h"
-
- void iicInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;//1.创建gpio配置结构体
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//2.使能gpiob时钟
-
- //3.配置gpio口基本属性
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;//开漏输出
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;//GPIOB8为iic的scl
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//速度为50mhz
- GPIO_Init(GPIOB,&GPIO_InitStructure);//4.初始化
-
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//GPIOB9为iic的SDA
- GPIO_Init(GPIOB,&GPIO_InitStructure);//初始化
-
- GPIO_SetBits(GPIOB,GPIO_Pin_8|GPIO_Pin_9);//初始情况SDA/SCL为高电平
- }
-
- /*引脚配置3个函数*********************/
-
- /**
- * 函 数:写SCL高低电平
- * 参 数:要写入SCL的电平值,范围:0/1
- * 返 回 值:无
- * 说 明:当上层函数需要写SCL时,此函数会被调用
- * 用户需要根据参数传入的值,将SCL置为高电平或者低电平
- * 当参数传入0时,置SCL为低电平,当参数传入1时,置SCL为高电平
- */
- void iicSclW(u8 BitValue)
- {
- GPIO_WriteBit(GPIOB,GPIO_Pin_8,(BitAction)BitValue);//根据BitValue,设置SCL引脚的电平
- // delay_us(10);
- }
-
- /**
- * 函 数:写SDA高低电平
- * 参 数:要写入SDA的电平值,范围:0/1
- * 返 回 值:无
- * 说 明:当上层函数需要写SDA时,此函数会被调用
- * 用户需要根据参数传入的值,将SDA置为高电平或者低电平
- * 当参数传入0时,置SDA为低电平,当参数传入1时,置SDA为高电平
- */
- void iicSdaW(u8 BitValue)
- {
- GPIO_WriteBit(GPIOB,GPIO_Pin_9,(BitAction)BitValue);//根据BitValue,设置SDA引脚的电平
- // delay_us(10);
- }
-
- /**
- * 函 数:读SDA高低电平
- * 参 数:无
- * 返 回 值:读出SDA的电平值,范围:0/1
- * 说 明:当上层函数需要读SDA时,此函数会被调用
- */
- uint8_t iicSdaR(void)
- {
- uint8_t BitValue;
- BitValue=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9);//读取SDA电平
- // delay_us(10);
-
- return BitValue;
- }
-
- /*通信协议6个函数*********************/
-
- /**
- * 函 数:I2C起始
- * 参 数:无
- * 返 回 值:无
- */
- void iicStart(void)
- {
- iicSdaW(1);//释放SDA,确保SDA为高电平
- iicSclW(1);//释放SCL,确保SCL为高电平
- iicSdaW(0);//在SCL高电平期间,拉低SDA,产生起始信号
- iicSclW(0);//拉低SCL,一个时钟结束
- }
-
- /**
- * 函 数:I2C终止
- * 参 数:无
- * 返 回 值:无
- */
- void iicStop(void)
- {
- iicSdaW(0);//拉低SDA,确保SDA为低电平
- iicSclW(1);//拉高SCL一个时钟开始
- iicSdaW(1);//在SCL高电平期间,释放SDA,产生终止信号
- }
-
- /**
- * 函 数:I2C发送一个字节
- * 参 数:Byte 要发送的一个字节数据,范围:0x00~0xFF
- * 返 回 值:无
- */
- void iicSendByte(u8 Byte)
- {
- u8 i;
- for(i=0;i<8;i++)//循环8次,主机依次发送数据(一个字节8位)的每一位
- {
- iicSdaW((Byte&(0x80>>i)));//写取指定位值
- iicSclW(1);//释放SCL,一个时钟开始,从机在SCL高电平期间读取SDA
- iicSclW(0);//拉低SCL,一个时钟结束,主机开始发送下一位数据
- }
- }
-
- /**
- * 函 数:I2C接收一个字节
- * 参 数:无
- * 返 回 值:Byte 接收的一个字节数据,范围:0x00~0xFF
- */
- u8 iicReciveByte(void)
- {
- u8 i,Byte=0x00;//定义接收的数据,并赋初值0x00,此处必须赋初值0x00,后面会用到
- iicSdaW(1);//接收前,主机先确保释放SDA,避免干扰从机的数据发送
- for(i=0;i<8;i++)//循环8次,主机依次接收数据的每一位
- {
- iicSclW(1);//释放SCL,一个时钟开始,主机机在SCL高电平期间读取SDA
- if(iicSdaR()==1) Byte|=(0x80>>i);//读取SDA数据,并存储到Byte变量
- //当SDA为1时,置变量指定位为1,当SDA为0时,不做处理,指定位为默认的初值0
- iicSclW(0);//拉低SCL,一个时钟结束,主机开始发送下一位数据
- }
-
- return Byte;//返回接收到的一个字节数据
- }
-
- /**
- * 函 数:I2C发送应答位
- * 参 数:Byte 要发送的应答位,范围:0~1,0表示应答,1表示非应答
- * 返 回 值:无
- */
- void iicSendAck(u8 AckBit)
- {
- iicSdaW(AckBit);//主机把应答位数据放到SDA线
- iicSclW(1);//释放SCL,一个时钟开始,主机机在SCL高电平期间读取SDA
- iicSclW(0);//拉低SCL,一个时钟结束,主机开始发送下一位数据
- }
-
- /**
- * 函 数:I2C接收应答位
- * 参 数:无
- * 返 回 值:接收到的应答位,范围:0~1,0表示应答,1表示非应答
- */
- u8 iicReciveAck(void)
- {
- u8 AskBit;//定义应答位变量
- iicSdaW(1);//接收前,主机先确保释放SDA,避免干扰从机的数据发送
- iicSclW(1);//释放SCL,一个时钟开始,主机机在SCL高电平期间读取SDA
- AskBit=iicSdaR();//将应答位存储到变量里
- iicSclW(0);//拉低SCL,一个时钟结束,主机开始发送下一位数据
-
- return AskBit;//返回定义应答位变量
- }
iic.h
- #ifndef __IIC_H
- #define __IIC_H
- #include "sys.h"
-
- void iicInit(void);
- void iicStart(void);
- void iicStop(void);
- void iicSendByte(u8 Byte);
- u8 iicReciveByte(void);
- void iicSendAck(u8 AckBit);
- u8 iicReciveAck(void);
-
- #endif
oled.c
- #include "iic.h"
- #include "delay.h"
- #include "oled.h"
- #include "font.h"
-
- /**
- * OLED显存数组
- * 所有的显示函数,都只是对此显存数组进行读写
- * 随后调用OLED_Update函数或OLED_UpdateArea函数
- * 才会将显存数组的数据发送到OLED硬件,进行显示
- */
- uint8_t OLED_DisplayBuf[8][128];
-
- /**
- * 函 数:OLED写命令
- * 参 数:Command 要写入的命令值,范围:0x00~0xFF
- * 返 回 值:无
- */
- void oledWriteCommand(u8 Command)
- {
- iicStart();//1.起始信号
- iicSendByte(0x78);//2.oled设备地址0x78
- iicReciveAck();//3.应答信号
- iicSendByte(0x00);//4.写oled寄存器地址
- iicReciveAck();//5.应答信号
- iicSendByte(Command);//6.发送数据
- iicReciveAck();//7.应答信号
- iicStop();//8.停止信号
- }
-
- /**
- * 函 数:OLED写数据
- * 参 数:Data 要写入数据的起始地址
- * 参 数:Count 要写入数据的数量
- * 返 回 值:无
- */
- void oledWriteData(u8 *Data,u8 Count)
- {
- u8 i;
-
- iicStart();//1.起始信号
- iicSendByte(0x78);//2.oled设备地址0x78
- iicReciveAck();//3.接收应答信号
- iicSendByte(0x40);//4.目标oled设置寄存器地址0x40
- iicReciveAck();//5.接收应答
-
- for(i=0;i<Count;i++)//依次发送多位数据
- {
- iicSendByte(Data[i]);//6.发送数据
- iicReciveAck();//7.接收应答
- }
-
- iicStop();//8.停止信号
- }
-
- void oledInit()
- {
- iicInit(); //先调用底层的端口初始化iic
-
- /*写入一系列的命令,对OLED进行初始化配置*/
- oledWriteCommand(0xAE); //设置显示开启/关闭,0xAE关闭,0xAF开启
-
- oledWriteCommand(0xD5); //设置显示时钟分频比/振荡器频率
- oledWriteCommand(0x80); //0x00~0xFF
-
- oledWriteCommand(0xA8); //设置多路复用率
- oledWriteCommand(0x3F); //0x0E~0x3F
-
- oledWriteCommand(0xD3); //设置显示偏移
- oledWriteCommand(0x00); //0x00~0x7F
-
- oledWriteCommand(0x40); //设置显示开始行,0x40~0x7F
-
- oledWriteCommand(0xA1); //设置左右方向,0xA1正常,0xA0左右反置
-
- oledWriteCommand(0xC8); //设置上下方向,0xC8正常,0xC0上下反置
-
- oledWriteCommand(0xDA); //设置COM引脚硬件配置
- oledWriteCommand(0x12);
-
- oledWriteCommand(0x81); //设置对比度
- oledWriteCommand(0xCF); //0x00~0xFF
-
- oledWriteCommand(0xD9); //设置预充电周期
- oledWriteCommand(0xF1);
-
- oledWriteCommand(0xDB); //设置VCOMH取消选择级别
- oledWriteCommand(0x30);
-
- oledWriteCommand(0xA4); //设置整个显示打开/关闭
-
- oledWriteCommand(0xA6); //设置正常/反色显示,0xA6正常,0xA7反色
-
- oledWriteCommand(0x8D); //设置充电泵
- oledWriteCommand(0x14);
-
- oledWriteCommand(0xAF); //开启显示
-
- oledClear();//OLED清屏
- oledUpdate();//更新显示,清屏,防止初始化后未显示内容时花屏
- }
-
- /**
- * 函 数:将OLED显存数组全部清零
- * 参 数:无
- * 返 回 值:无
- * 说 明:调用此函数后,要想真正地呈现在屏幕上,还需调用更新函数
- */
- void oledClear(void)
- {
- u8 i,j;
-
- for(i=0;i<8;i++)//遍历8页
- {
- for(j=0;j<128;j++)//遍历128列
- {
- OLED_DisplayBuf[i][j]=0x00;//将显存数组数据全部清零
- }
- }
- }
-
- /**
- * 函 数:将OLED显存数组更新到OLED屏幕
- * 参 数:无
- * 返 回 值:无
- * 说 明:所有的显示函数,都只是对OLED显存数组进行读写
- * 随后调用OLED_Update函数或OLED_UpdateArea函数
- * 才会将显存数组的数据发送到OLED硬件,进行显示
- * 故调用显示函数后,要想真正地呈现在屏幕上,还需调用更新函数
- */
- void oledUpdate(void)
- {
- u8 j;
-
- for(j=0;j<8;j++)/*遍历每一页*/
- {
- oledSetCursor(j,0);/*设置光标位置为每一页的第一列*/
- oledWriteData(OLED_DisplayBuf[j],128);/*连续写入128个数据,将显存数组的数据写入到OLED硬件*/
- }
- }
-
- /**
- * 函 数:OLED设置显示光标位置
- * 参 数:Page 指定光标所在的页,范围:0~7
- * 参 数:X 指定光标所在的X轴坐标,范围:0~127
- * 返 回 值:无
- * 说 明:OLED默认的Y轴,只能8个Bit为一组写入,即1页等于8个Y轴坐标
- */
- void oledSetCursor(u8 Page,u8 X)
- {
- oledWriteCommand(0xB0|Page);//设置页位置
- oledWriteCommand(0x0f&X);//设置X位置低4位
- oledWriteCommand(0x10|(X>>4));//设置X位置高4位
- }
-
- /**
- * 函 数:OLED显示一个字符
- * 参 数:X 指定字符左上角的横坐标,范围:0~127
- * 参 数:Y 指定字符左上角的纵坐标,范围:0~63
- * 参 数:Char 指定要显示的字符,范围:ASCII码可见字符
- * 参 数:FontSize 指定字体大小
- * 范围:OLED_8X16 宽8像素,高16像素
- * OLED_6X8 宽6像素,高8像素
- * 返 回 值:无
- * 说 明:调用此函数后,要想真正地呈现在屏幕上,还需调用更新函数
- */
- void oledShowChar(u8 X,u8 Y,char Char, u8 FontSize)
- {
- if (FontSize == OLED_8X16) //字体为宽8像素,高16像素
- {
- /*将ASCII字模库OLED_F8x16的指定数据以8*16的图像格式显示,通过与字库中空字符作差确定目标字符对应点阵位置*/
- oledShowImage(X, Y, 8, 16, OLED_F8x16[Char - ' ']);
- }
- else if(FontSize == OLED_6X8) //字体为宽6像素,高8像素
- {
- /*将ASCII字模库OLED_F6x8的指定数据以6*8的图像格式显示*/
- oledShowImage(X, Y, 6, 8, OLED_F6x8[Char - ' ']);
- }
- }
-
- /**
- * 函 数:OLED显示图像
- * 参 数:X 指定图像左上角的横坐标,范围:0~127
- * 参 数:Y 指定图像左上角的纵坐标,范围:0~63
- * 参 数:Width 指定图像的宽度,范围:0~128
- * 参 数:Height 指定图像的高度,范围:0~64
- * 参 数:Image 指定要显示的图像
- * 返 回 值:无
- * 说 明:调用此函数后,要想真正地呈现在屏幕上,还需调用更新函数
- */
- void oledShowImage(uint8_t X, uint8_t Y, uint8_t Width, uint8_t Height, const uint8_t *Image)
- {
- uint8_t i, j;
-
- /*参数检查,保证指定图像不会超出屏幕范围*/
- if (X > 127) {return;}
- if (Y > 63) {return;}
-
- /*将图像所在区域清空*/
- oledClearArea(X, Y, Width, Height);
-
- /*遍历指定图像涉及的相关页*/
- /*(Height - 1) / 8 + 1的目的是Height / 8并向上取整*/
- for (j = 0; j < (Height - 1) / 8 + 1; j ++)
- {
- /*遍历指定图像涉及的相关列*/
- for (i = 0; i < Width; i ++)
- {
- /*超出边界,则跳过显示*/
- if (X + i > 127) {break;}
- if (Y / 8 + j > 7) {return;}
-
- /*显示图像在当前页的内容*/
- OLED_DisplayBuf[Y / 8 + j][X + i] |= Image[j * Width + i] << (Y % 8);
-
- /*超出边界,则跳过显示*/
- /*使用continue的目的是,下一页超出边界时,上一页的后续内容还需要继续显示*/
- if (Y / 8 + j + 1 > 7) {continue;}
-
- /*显示图像在下一页的内容*/
- OLED_DisplayBuf[Y / 8 + j + 1][X + i] |= Image[j * Width + i] >> (8 - Y % 8);
- }
- }
- }
-
- /**
- * 函 数:将OLED显存数组部分清零
- * 参 数:X 指定区域左上角的横坐标,范围:0~127
- * 参 数:Y 指定区域左上角的纵坐标,范围:0~63
- * 参 数:Width 指定区域的宽度,范围:0~128
- * 参 数:Height 指定区域的高度,范围:0~64
- * 返 回 值:无
- * 说 明:调用此函数后,要想真正地呈现在屏幕上,还需调用更新函数
- */
- void oledClearArea(uint8_t X, uint8_t Y, uint8_t Width, uint8_t Height)
- {
- uint8_t i, j;
-
- /*参数检查,保证指定区域不会超出屏幕范围*/
- if (X > 127) {return;}
- if (Y > 63) {return;}
- if (X + Width > 128) {Width = 128 - X;}
- if (Y + Height > 64) {Height = 64 - Y;}
-
- for (j = Y; j < Y + Height; j ++) //遍历指定页
- {
- for (i = X; i < X + Width; i ++) //遍历指定列
- {
- OLED_DisplayBuf[j / 8][i] &= ~(0x01 << (j % 8)); //将显存数组指定数据清零
- }
- }
- }
-
- /**
- * 函 数:OLED显示字符串
- * 参 数:X 指定字符串左上角的横坐标,范围:0~127
- * 参 数:Y 指定字符串左上角的纵坐标,范围:0~63
- * 参 数:String 指定要显示的字符串,范围:ASCII码可见字符组成的字符串
- * 参 数:FontSize 指定字体大小
- * 范围:OLED_8X16 宽8像素,高16像素
- * OLED_6X8 宽6像素,高8像素
- * 返 回 值:无
- * 说 明:调用此函数后,要想真正地呈现在屏幕上,还需调用更新函数
- */
- void oledShowString(uint8_t X, uint8_t Y, char *String, uint8_t FontSize)
- {
- uint8_t i;
- for (i = 0; String[i] != '\0'; i++) //遍历字符串的每个字符
- {
- /*调用OLED_ShowChar函数,依次显示每个字符*/
- oledShowChar(X + i * FontSize, Y, String[i], FontSize);
- }
- }
oled.h
- #ifndef __OLED_H
- #define __OLED_H
- #include "sys.h"
-
- /*FontSize参数取值*/
- /*此参数值不仅用于判断,而且用于计算横向字符偏移,默认值为字体像素宽度*/
- #define OLED_8X16 8
- #define OLED_6X8 6
-
- void oledInit();
- void oledClear(void);
- void oledUpdate(void);
- void oledSetCursor(u8 Page,u8 X);
- void oledClearArea(uint8_t X, uint8_t Y, uint8_t Width, uint8_t Height);
- void oledShowChar(u8 X,u8 Y,char Char, u8 FontSize);
- void oledShowImage(uint8_t X, uint8_t Y, uint8_t Width, uint8_t Height, const uint8_t *Image);
- void oledShowString(uint8_t X, uint8_t Y, char *String, uint8_t FontSize);
-
-
- #endif
字库文件
font.c
- #include "font.h"
-
-
-
- /*ASCII字模数据*********************/
-
- /*宽8像素,高16像素*/
- const uint8_t OLED_F8x16[][16] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
- 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,// ! 1
- 0x00,0x16,0x0E,0x00,0x16,0x0E,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// " 2
- 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,
- 0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,// # 3
- 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,
- 0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,// $ 4
- 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,
- 0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,// % 5
- 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,
- 0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,// & 6
- 0x00,0x00,0x00,0x16,0x0E,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ' 7
- 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,
- 0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,// ( 8
- 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,
- 0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,// ) 9
- 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,
- 0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,// * 10
- 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
- 0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,// + 11
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,// , 12
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,// - 13
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,// . 14
- 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,
- 0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,// / 15
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
- 0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,// 0 16
- 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
- 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// 1 17
- 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
- 0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,// 2 18
- 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
- 0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,// 3 19
- 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
- 0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,// 4 20
- 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
- 0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,// 5 21
- 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
- 0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,// 6 22
- 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
- 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,// 7 23
- 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
- 0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,// 8 24
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
- 0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,// 9 25
- 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,// : 26
- 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
- 0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,// ; 27
- 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,
- 0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,// < 28
- 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
- 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,// = 29
- 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
- 0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,// > 30
- 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,
- 0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,// ? 31
- 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,
- 0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,// @ 32
- 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,
- 0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,// A 33
- 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,
- 0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,// B 34
- 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,
- 0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,// C 35
- 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,
- 0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,// D 36
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
- 0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,// E 37
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
- 0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,// F 38
- 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,
- 0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,// G 39
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
- 0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,// H 40
- 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,
- 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// I 41
- 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,
- 0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,// J 42
- 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,
- 0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,// K 43
- 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,
- 0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,// L 44
- 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,
- 0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,// M 45
- 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,
- 0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,// N 46
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
- 0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,// O 47
- 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,
- 0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,// P 48
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
- 0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,// Q 49
- 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,
- 0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,// R 50
- 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,
- 0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,// S 51
- 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,
- 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// T 52
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
- 0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// U 53
- 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
- 0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,// V 54
- 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,
- 0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,// W 55
- 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,
- 0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,// X 56
- 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,
- 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// Y 57
- 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,
- 0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,// Z 58
- 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,
- 0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,// [ 59
- 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,// \ 60
- 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,
- 0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,// ] 61
- 0x00,0x20,0x10,0x08,0x04,0x08,0x10,0x20,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ^ 62
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,// _ 63
- 0x00,0x02,0x04,0x08,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ` 64
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,// a 65
- 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,
- 0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,// b 66
- 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,// c 67
- 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,
- 0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,// d 68
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,// e 69
- 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,
- 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// f 70
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
- 0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,// g 71
- 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,
- 0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,// h 72
- 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,
- 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// i 73
- 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,
- 0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,// j 74
- 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,
- 0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,// k 75
- 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,
- 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// l 76
- 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
- 0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,// m 77
- 0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,
- 0x00,0x20,0x3F,0x21,0x00,0x20,0x3F,0x20,// n 78
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// o 79
- 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,
- 0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,// p 80
- 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,
- 0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,// q 81
- 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
- 0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,// r 82
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
- 0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,// s 83
- 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,// t 84
- 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,
- 0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,// u 85
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
- 0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,// v 86
- 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,
- 0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,// w 87
- 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
- 0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,// x 88
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
- 0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,// y 89
- 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
- 0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,// z 90
- 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,
- 0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,// { 91
- 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,// | 92
- 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,
- 0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,// } 93
- 0x00,0x80,0x40,0x40,0x80,0x00,0x00,0x80,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,// ~ 94
- };
-
- /*宽6像素,高8像素*/
- const uint8_t OLED_F6x8[][6] =
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,// 0
- 0x00,0x00,0x00,0x2F,0x00,0x00,// ! 1
- 0x00,0x00,0x07,0x00,0x07,0x00,// " 2
- 0x00,0x14,0x7F,0x14,0x7F,0x14,// # 3
- 0x00,0x24,0x2A,0x7F,0x2A,0x12,// $ 4
- 0x00,0x23,0x13,0x08,0x64,0x62,// % 5
- 0x00,0x36,0x49,0x55,0x22,0x50,// & 6
- 0x00,0x00,0x00,0x07,0x00,0x00,// ' 7
- 0x00,0x00,0x1C,0x22,0x41,0x00,// ( 8
- 0x00,0x00,0x41,0x22,0x1C,0x00,// ) 9
- 0x00,0x14,0x08,0x3E,0x08,0x14,// * 10
- 0x00,0x08,0x08,0x3E,0x08,0x08,// + 11
- 0x00,0x00,0x00,0xA0,0x60,0x00,// , 12
- 0x00,0x08,0x08,0x08,0x08,0x08,// - 13
- 0x00,0x00,0x60,0x60,0x00,0x00,// . 14
- 0x00,0x20,0x10,0x08,0x04,0x02,// / 15
- 0x00,0x3E,0x51,0x49,0x45,0x3E,// 0 16
- 0x00,0x00,0x42,0x7F,0x40,0x00,// 1 17
- 0x00,0x42,0x61,0x51,0x49,0x46,// 2 18
- 0x00,0x21,0x41,0x45,0x4B,0x31,// 3 19
- 0x00,0x18,0x14,0x12,0x7F,0x10,// 4 20
- 0x00,0x27,0x45,0x45,0x45,0x39,// 5 21
- 0x00,0x3C,0x4A,0x49,0x49,0x30,// 6 22
- 0x00,0x01,0x71,0x09,0x05,0x03,// 7 23
- 0x00,0x36,0x49,0x49,0x49,0x36,// 8 24
- 0x00,0x06,0x49,0x49,0x29,0x1E,// 9 25
- 0x00,0x00,0x36,0x36,0x00,0x00,// : 26
- 0x00,0x00,0x56,0x36,0x00,0x00,// ; 27
- 0x00,0x08,0x14,0x22,0x41,0x00,// < 28
- 0x00,0x14,0x14,0x14,0x14,0x14,// = 29
- 0x00,0x00,0x41,0x22,0x14,0x08,// > 30
- 0x00,0x02,0x01,0x51,0x09,0x06,// ? 31
- 0x00,0x3E,0x49,0x55,0x59,0x2E,// @ 32
- 0x00,0x7C,0x12,0x11,0x12,0x7C,// A 33
- 0x00,0x7F,0x49,0x49,0x49,0x36,// B 34
- 0x00,0x3E,0x41,0x41,0x41,0x22,// C 35
- 0x00,0x7F,0x41,0x41,0x22,0x1C,// D 36
- 0x00,0x7F,0x49,0x49,0x49,0x41,// E 37
- 0x00,0x7F,0x09,0x09,0x09,0x01,// F 38
- 0x00,0x3E,0x41,0x49,0x49,0x7A,// G 39
- 0x00,0x7F,0x08,0x08,0x08,0x7F,// H 40
- 0x00,0x00,0x41,0x7F,0x41,0x00,// I 41
- 0x00,0x20,0x40,0x41,0x3F,0x01,// J 42
- 0x00,0x7F,0x08,0x14,0x22,0x41,// K 43
- 0x00,0x7F,0x40,0x40,0x40,0x40,// L 44
- 0x00,0x7F,0x02,0x0C,0x02,0x7F,// M 45
- 0x00,0x7F,0x04,0x08,0x10,0x7F,// N 46
- 0x00,0x3E,0x41,0x41,0x41,0x3E,// O 47
- 0x00,0x7F,0x09,0x09,0x09,0x06,// P 48
- 0x00,0x3E,0x41,0x51,0x21,0x5E,// Q 49
- 0x00,0x7F,0x09,0x19,0x29,0x46,// R 50
- 0x00,0x46,0x49,0x49,0x49,0x31,// S 51
- 0x00,0x01,0x01,0x7F,0x01,0x01,// T 52
- 0x00,0x3F,0x40,0x40,0x40,0x3F,// U 53
- 0x00,0x1F,0x20,0x40,0x20,0x1F,// V 54
- 0x00,0x3F,0x40,0x38,0x40,0x3F,// W 55
- 0x00,0x63,0x14,0x08,0x14,0x63,// X 56
- 0x00,0x07,0x08,0x70,0x08,0x07,// Y 57
- 0x00,0x61,0x51,0x49,0x45,0x43,// Z 58
- 0x00,0x00,0x7F,0x41,0x41,0x00,// [ 59
- 0x00,0x02,0x04,0x08,0x10,0x20,// \ 60
- 0x00,0x00,0x41,0x41,0x7F,0x00,// ] 61
- 0x00,0x04,0x02,0x01,0x02,0x04,// ^ 62
- 0x00,0x40,0x40,0x40,0x40,0x40,// _ 63
- 0x00,0x00,0x01,0x02,0x04,0x00,// ` 64
- 0x00,0x20,0x54,0x54,0x54,0x78,// a 65
- 0x00,0x7F,0x48,0x44,0x44,0x38,// b 66
- 0x00,0x38,0x44,0x44,0x44,0x20,// c 67
- 0x00,0x38,0x44,0x44,0x48,0x7F,// d 68
- 0x00,0x38,0x54,0x54,0x54,0x18,// e 69
- 0x00,0x08,0x7E,0x09,0x01,0x02,// f 70
- 0x00,0x18,0xA4,0xA4,0xA4,0x7C,// g 71
- 0x00,0x7F,0x08,0x04,0x04,0x78,// h 72
- 0x00,0x00,0x44,0x7D,0x40,0x00,// i 73
- 0x00,0x40,0x80,0x84,0x7D,0x00,// j 74
- 0x00,0x7F,0x10,0x28,0x44,0x00,// k 75
- 0x00,0x00,0x41,0x7F,0x40,0x00,// l 76
- 0x00,0x7C,0x04,0x18,0x04,0x78,// m 77
- 0x00,0x7C,0x08,0x04,0x04,0x78,// n 78
- 0x00,0x38,0x44,0x44,0x44,0x38,// o 79
- 0x00,0xFC,0x24,0x24,0x24,0x18,// p 80
- 0x00,0x18,0x24,0x24,0x18,0xFC,// q 81
- 0x00,0x7C,0x08,0x04,0x04,0x08,// r 82
- 0x00,0x48,0x54,0x54,0x54,0x20,// s 83
- 0x00,0x04,0x3F,0x44,0x40,0x20,// t 84
- 0x00,0x3C,0x40,0x40,0x20,0x7C,// u 85
- 0x00,0x1C,0x20,0x40,0x20,0x1C,// v 86
- 0x00,0x3C,0x40,0x30,0x40,0x3C,// w 87
- 0x00,0x44,0x28,0x10,0x28,0x44,// x 88
- 0x00,0x1C,0xA0,0xA0,0xA0,0x7C,// y 89
- 0x00,0x44,0x64,0x54,0x4C,0x44,// z 90
- 0x00,0x00,0x08,0x7F,0x41,0x00,// { 91
- 0x00,0x00,0x00,0x7F,0x00,0x00,// | 92
- 0x00,0x00,0x41,0x7F,0x08,0x00,// } 93
- 0x00,0x08,0x04,0x08,0x10,0x08,// ~ 94
- };
- /*********************ASCII字模数据*/
-
font.h
- #ifndef __FONT_H
- #define __FONT_H
- #include "sys.h"
-
- /*ASCII字模数据声明*/
- extern const uint8_t OLED_F8x16[][16];
- extern const uint8_t OLED_F6x8[][6];
-
- #endif
main.c
- #include "stm32f10x.h"
- #include "led.h"
- #include "oled.h"
- #include "delay.h"
-
-
- int main(void)
- { int i=0;
- delay_init();//延时函数初始化
- oledInit();//oled初始化
- oledShowChar(0,0,'A',OLED_8X16);//(0,0)位置开始写A,字号为OLED_8X16
- oledShowString(0,16,"hello world",OLED_8X16);//(0,16)位置输出hello world,字号为OLED_8X16
- oledUpdate();//更新显存,刷新实际显示
- while(1)
- {
- i++;
- if(i==26) i=0;
- oledShowChar(0,0,'A'+i,OLED_8X16);//(0,0)位置循环显示A-Z,字号为OLED_8X16
- oledUpdate();//更新显存,刷新实际显示
- delay_ms(500);
- }
- }
-
-
1.SCL一直是主机控制吗
是的
2.读数据时,为什么不直接读数据呢,而是先通过写命令找到寄存器,再发送读命令
通信协议规定,理论上应该也可以这么做
3.主机(单片机)选择IO口电路原理图并没有外接上拉电阻
一般外接模块内部接了上拉电阻,所以stm32这边不用加
4.为什么再iic读写后加了正点原子的延时函数就无法正常通信
延时函数没有初始化
实际效果
0.96寸iic接口oled显示
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。