STM32 IIC 实验

1.

 可以选择I2C1,也可以选择I2C2,或者同时选择,同时运行

 

配置时钟信号

为节约空间,选择这两个,然后选择GENERATE CODE

二、HAL_I2C_Mem_Write

I2C_HandleTypeDef *hi2c:I2C设备句柄
uint16_t DevAddress:目标器件的地址,七位地址必须左对齐
uint16_t MemAddress:目标器件的目标寄存器地址
uint16_t MemAddSize:目标器件内部寄存器地址数据长度
uint8_t *pData:待写的数据首地址
uint16_t Size:待写的数据长度
uint32_t Timeout:超时时间
返回值: HAL_StatusTypeDef HAL 状态( OK busy ERROR TIMEOUT
向OLED写入命令的封装:
void Oled_Write_Cmd(uint8_t dataCmd)
{HAL_I2C_Mem_Write(&hi2c1,0x78,0x00,I2C_MEMADD_SIZE_8BIT,&dataCmd,1,0xff);
}
OLED 写数据的封装:最大的区别是目标器件的目标寄存器地址变成了0x40
void Oled_Write_Data(uint8_t dataData)
{
HAL_I2C_Mem_Write(&hi2c1,0x78,0x40,I2C_MEMADD_SIZE_8BIT,&dataData,1,0xff);}

 三、初始化Oled(官方手册上面有),清屏函数,调入图片的亮点到数组,显示函数。

初始化Oled:

void Oled_Init(void){
Oled_Write_Cmd(0xAE);//--display offOled_Write_Cmd(0x00);//---set low column addressOled_Write_Cmd(0x10);//---set high column addressOled_Write_Cmd(0x40);//--set start line address  Oled_Write_Cmd(0xB0);//--set page addressOled_Write_Cmd(0x81); // contract controlOled_Write_Cmd(0xFF);//--128   Oled_Write_Cmd(0xA1);//set segment remap Oled_Write_Cmd(0xA6);//--normal / reverseOled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)Oled_Write_Cmd(0x3F);//--1/32 dutyOled_Write_Cmd(0xC8);//Com scan directionOled_Write_Cmd(0xD3);//-set display offsetOled_Write_Cmd(0x00);//Oled_Write_Cmd(0xD5);//set osc divisionOled_Write_Cmd(0x80);//Oled_Write_Cmd(0xD8);//set area color mode offOled_Write_Cmd(0x05);//Oled_Write_Cmd(0xD9);//Set Pre-Charge PeriodOled_Write_Cmd(0xF1);//Oled_Write_Cmd(0xDA);//set com pin configuartionOled_Write_Cmd(0x12);//Oled_Write_Cmd(0xDB);//set VcomhOled_Write_Cmd(0x30);//Oled_Write_Cmd(0x8D);//set charge pump enableOled_Write_Cmd(0x14);//Oled_Write_Cmd(0xAF);//--turn on oled panel	}

清屏函数

void Oled_Screen_Clear(void){char i,n;Oled_Write_Cmd (0x20);                    //set memory addressing modeOled_Write_Cmd (0x02);                    //page addressing modefor(i=0;i<8;i++){Oled_Write_Cmd(0xb0+i);               //éè??ò3μ??·£¨0~7£?Oled_Write_Cmd(0x00);                 //éè????ê??????aáDμíμ??·Oled_Write_Cmd(0x10);                 //éè????ê??????aáD??μ??·   for(n=0;n<128;n++)Oled_Write_Data(0x00); 			}	
}

设置图片的点阵,可以通过电脑画图软件画

通过取模软件生成数据将图片的亮点放到数组:

unsigned char bmpImager[] = {/*--  调入了一幅图像:E:\丁1.bmp  --*/
/*--  宽度x高度=128x64  --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0xE0,
0xE0,0xE0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,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,0xE0,0xFC,
0xFF,0x3F,0x0F,0x03,0x01,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x07,0x07,0x07,0x07,0x0F,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x1E,0x1F,
0x1F,0x1F,0x1F,0x3F,0x3F,0x3F,0x3F,0x7B,0x73,0x73,0xF1,0xE1,0xC1,0xC1,0x81,0x80,
0x10,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x3C,0x1C,0x1C,0x1C,
0x1C,0x1E,0x0C,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,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,0xE0,0xFC,0xFF,0x3F,0x07,
0x00,0x00,0x02,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,0xC7,0xC7,0x87,0x07,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,0xFF,0xFF,0xFF,0x07,0x07,0x07,0x07,0x07,
0x07,0x07,0x07,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x03,0x07,
0x07,0x0F,0x1E,0x1E,0x1C,0x3C,0x38,0x78,0xF0,0xF0,0xE0,0xC0,0xC8,0x1C,0x1C,0x1C,
0x1C,0x1C,0x1C,0x1C,0x1E,0x0E,0x0F,0x0F,0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0xF0,0xFC,0xFE,0x9F,0xC6,0xF0,0xFF,0x7F,0x1F,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0xE0,
0xF0,0xF8,0x7E,0x3F,0x0F,0x07,0x87,0xCF,0xEE,0xFE,0xFE,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,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,0x1F,0xFF,0xFF,0xF0,0x80,0x00,
0x00,0x00,0x00,0x00,0x03,0x07,0x07,0x07,0x07,0x03,0x01,0x00,0x00,0x80,0xC0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x07,0x0F,0x0E,0x0E,0x0F,0x07,0x07,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xF8,0xFF,0x7F,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,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,0x0F,0x1F,0x7E,
0xF8,0xF0,0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,
0x0F,0x1F,0x3E,0x7C,0xF8,0xF8,0xFF,0xFF,0x1F,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,0x70,0x78,0x3C,0x1E,0x1F,0x0F,0x07,0x03,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,0x01,0x01,0x03,0x07,0x07,0x07,0x07,0x0F,0x0E,0x0E,0x0E,0x1E,0x1C,0x1C,0x1C,
0x1C,0x1C,0x1C,0x3C,0x38,0x39,0x39,0x39,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,
0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x3C,0x1E,0x1F,0x0F,0x07,0x03,0x01,
0x01,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,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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);//page0--page7//每个page从0列Oled_Write_Cmd(0x00);Oled_Write_Cmd(0x10);//0到127列,依次写入0,每写入数据,列地址自动偏移for(j = 128 * i; j<(128 * (i+1));j++){Oled_Write_Data(image[j]);}}
}

四、主函数

直接在while(1)循环之前添加即可。

//1. OLED初始化Oled_Init();//2. 选择一个位置//2.1 确认页寻址模式Oled_Write_Cmd(0x20);Oled_Write_Cmd(0x02);Oled_Screen_Clear();Oled_Show_Image(bmpImager);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/182217.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android Studio(RecyclerView)

前言 ListView的缺点&#xff0c;在RecyclerView得到了补充改善&#xff08;横纵向排列子元素、多列布局等等&#xff09; 代码 前面在适配器章节已经介绍了其对应的适配器&#xff0c;这里就简单展示一下多列布局的页面效果和相关代码 <androidx.recyclerview.widget.Recyc…

css-inpu边框

效果图&#xff1a; input {width: 225px;height: 25px;background-color: #1469bd00;border: #aca9a97d solid 1px;color: white;font-size: 15pt;box-sizing: conte-box; }input:focus {border-style: solid;border-color: #03a9f4;box-shadow: 0 0 15px #03a9f4;outline: …

微信支付更换证书最详细方法

6、在【商户平台】&#xff0c;输入操作密码&#xff0c;安全验证后生成证书串 7、在【商户平台】&#xff0c;复制证书串 8、在【证书工具】&#xff0c;粘贴证书串&#xff0c;点击下一步&#xff0c;申请证书成功 &#xff08;若提示"证书与本地公私钥不匹配&qu…

【JavaScript】零碎知识点总结_2

1. 引入网站图标 可以直接放在根目录 还可以 link 引入&#xff08;推荐&#xff09; <linkrel"shortcut icon"href"./assets/favicon.ico"type"image/x-icon">2. 转换为数字 123 -> 123 除 做字符串拼接&#xff0c;算术运算符都…

浅述边缘计算场景下的云边端协同融合架构的应用场景示例

云计算正在向一种更加全局化的分布式节点组合形态进阶&#xff0c;而边缘计算是云计算能力向边缘侧分布式拓展的新触角。随着城市建设进程加快&#xff0c;海量设备产生的数据&#xff0c;若上传到云端进行处理&#xff0c;会对云端造成巨大压力。如果利用边缘计算来让云端的能…

Flutter 07 框架和三棵树(Widgets、Elements和RenderObjects)

一、Flutter框架的整体结构&#xff1a; Flutter是Google推出并开源的跨平台开发框架&#xff0c;主打跨平台、高保真、高性能。开发者可以通过Dart语 言开发Flutter应用&#xff0c;一套代码同时运行在ios和Android平台。不仅如此&#xff0c;Flutter还支持Web、桌面、嵌 入应…

浅析应急疏散照明设计在高层建筑中的应用

【摘要】作为工程设计人员&#xff0c;对高层建筑的应急照明设计应有足够的认识和重视&#xff0c;以保证在出现失火事件时&#xff0c;可以有效地引导建筑内的人员安全逃离、正确疏散&#xff0c;这是建筑设计的*大价值所在。在设计应急照明时&#xff0c;应根据当地的情况选择…

软件测试从0offer到20k,你只差银行测试这一步!!!

金融类软件测试 举个栗子&#xff0c;银行里的软件测试工程师。横向跟互联网公司里的测试来说&#xff0c;薪资相对稳定&#xff0c;加班少甚至基本没有&#xff0c;业务稳定。实在是测试类岗位中的香饽饽&#xff01; 一、什么是金融行业 金融业是指经营金融商品的特殊行业&am…

【vscode】Window11环境下vscode使用Fira Code字体【教程】

【vscode】Window11环境下vscode使用Fira Code字体【教程】 文章目录 【vscode】Window11环境下vscode使用Fira Code字体【教程】1. 下载Fira Code字体2. 安装Fira Code字体3. 配置vscode4. 效果如下Reference 如果想要在Ubuntu环境下使用Fira Code字体&#xff0c;可以参考我的…

AI技术再刷屏!明星集体“说”外语,有何风险?

近日&#xff0c;一段美国歌手泰勒斯威夫特“说”中文的短视频在网络刷屏&#xff0c;引发热议。 视频中&#xff0c;泰勒斯威夫特“说”着流利中文&#xff0c;音色和讲母语时的音色类似&#xff0c;甚至连口型都能对上。 类似的视频还有很多外国人“说”地道中文、很多中国…

FFmpeg直播能力更新计划与新版本发布

// 编者按&#xff1a;客户端作为直接面向用户大众的接口&#xff0c;随着技术的发展进化与时俱进&#xff0c;实现更好的服务是十分必要的。FFmpeg作为最受欢迎的视频和图像处理开源软件&#xff0c;被相关行业的大量用户青睐&#xff0c;而随着HEVC标准的发布到广泛使用&am…

“网站不安全”该如何解决

当我们的网站被客户访问的时候&#xff0c;经常会出现提示不安全的情况&#xff0c;导致客户的不信任&#xff0c;从而出现客户流失的现象&#xff0c;这种情况我们应该如何解决呢&#xff1f; 首先&#xff0c;我们要确定网站会出现不安全的原因&#xff0c;一般来说&#xff…

GraphQL入门与开源的GraphQL引擎Hasura体验

背景 Hasura 是一个开源的 GraphQL 引擎&#xff0c;它可以帮助开发人员快速构建和部署现代应用程序的后端。它提供了一个自动化的 GraphQL API &#xff0c;可以直接连接到现有的数据库&#xff0c;并提供实时数据推送和订阅功能。 Hasura 团队总部位于印度。 下载安装 脚本…

Android开发知识学习——从Retrofit原理来看HTTP

文章目录 Retrofit 使用方法简介Retrofit 源码结构总结扔物线读源码的思路与方式 Retrofit 使用方法简介 导包 implementation com.squareup.retrofit2:retrofit:最新版本创建一个 interface 作为 Web Service 的请求集合&#xff0c;在里面用注解 &#xff08;Annotation&…

修复RGBA的png为RGB的png

修改IHDR里面的color type 修改IHDR的crc 删除sBit和sRGB两个chunk

设置Linux时间格式

一、事因 不知道什么时候我在输入ls -l 命令时候的显示变成了。 -rw-r--r-- 1 bossftp ftp 6796376499 915 05:31 rac_full_20230915.gz -rw-r--r-- 1 bossftp ftp 6804104515 104 05:25 rac_full_20231024.gz -rw-r--r-- 1 bossftp ftp 6804365525 105 05:29 rac_full_202…

开源六轴协作机械臂MechArm 拖动示教模型案例

介绍 今天&#xff0c;我将向大家展示一个我独立设计并实现的机械臂模型。这个模型的核心功能是实现实时的手势追踪——只需用手轻轻拖拽&#xff0c;机械臂就能立即跟随你的动作进行移动。 我之所以想要创造这样一个模型&#xff0c;是因为在一些危险环境中&#xff0c;我们可…

【缓存】Spring全家桶中@CacheEvict无效情况共有以下几种

Spring全家桶中CacheEvict无效情况共有以下几种 一、背景介绍二、原因分析三、解决方案 一、背景介绍 SpringBoot中使用Cacheable注解缓存数据&#xff0c;使用CacheEvict注解删除缓存。但是在项目使用过程中&#xff0c;发现使用CacheEvict注解删除缓存无效。 拓展&#xff…

软件测试需不需要懂代码?

无论是刚入测试行业的萌新&#xff0c;还是已经在测试行业闯荡了两三年的小司机们&#xff0c;都会琢磨一个问题&#xff1a;如果要持续发展下去&#xff0c;我要不要懂代码&#xff1f; 在软件测试初级阶段&#xff0c;不需要编程能力。但是任何一个职业&#xff0c;都会追求…

【ubuntu】搭建lamp架构

一、准备工作 1、更新源 apt-get updateapt #就是一个管理包的工具&#xff0c;理解为centos中的yum update #表示让apt执行更新的操作&#xff0c;更新的内容为软件列表。#为什么要更新软件列表&#xff1f; 就时本地会隔断时间进行同步镜像站的资源包&#xff0c;但是我…