使用单片机在图形点阵LCD上绘制波形图

使用单片机在图形点阵LCD上绘制波形图

需求:

假如有一组浮点数据,是通过AD转换得到的,保存在数组MyArray[]中,采集点数为len,采集周期为T,现在想用单片机在LCD上绘制出这组数据对应的波形图,该如何实现呢?

在图形点阵LCD上制波形图,主要是为了提高采集数据的可视化效果,其次是为了提升产品的竞争力。我的理解就是为了好看。

一、绘图原理

1、定义波形图的显示区域

在绘图之前,我们需要先规划好显示区域。在12864的点阵屏中,X轴坐标为0~127,Y轴坐标为0~63,因此,我们定义波形图的显示参数如下:

#define  Picture_Xmin  10   //波形图在LCD中的最小x坐标

#define  Picture_Ymin  25   //波形图在LCD中的最小y坐标

#define  Picture_Xpp   108  //波形图在LCD中的最大长度

#define  Picture_Ypp   35   //波形图在LCD中的最大高度

#define  Picture_Xmax  (Picture_Xmin+Picture_Xpp) //波形图在LCD中的最大x坐标

#define  Picture_Ymax  (Picture_Ymin+Picture_Ypp) //波形图在LCD中的最大y坐标

注意:Picture_Xmax<128, Picture_Ymax<64

2、求数组MyArray[]中的最大值,最小值和峰峰值

采集数据的最大峰峰值数据,在绘图时,落在波形图的最大高度处,纵坐标反而是最小的。因此,我们采用最大值和采集点数据减法计算,得到其纵坐标。这样,就可以绘制曲线图了。

float MaxValue; //用来保存MyArray[]中的最大值

float MinValue; //用来保存MyArray[]中的最小值

float APPValue; //用来保存MyArray[]中的最大峰峰值

//函数功能:计算“最大值,最小值和峰峰值”

void Calculate_MaxValue_MinValue_ And_APPValue (float *s,u16 len)

{

         u16 i;

    float f;

         MaxValue = s[0]; //默认最大值为第1

         MinValue = s[0]; //默认最小值为第1

         for(i=0;i<len;i++)

         {

                   f=s[i];

                   if( MaxValue < f ) MaxValue= f;//保存最大值

                   if( MinValue > f ) MinValue= f;//保存最小值

         }

         APPValue = MaxValue - MinValue;//求最大峰峰值

}

3、画图

void DrawPicture (float *s,u16 len)

{

         u16 i;

         s16 x0;

         s16 y0;

         s16 x1;

         s16 y1;

    float f;

         for(i=1;i<len;i++)//绘制曲线图

         {

                   f=i-1; f=f*Picture_Xpp; f=f/len; x0=f;

                   f=MaxValue-s[i-1]; f=f*Picture_Ypp; f=f/APPValue; y0=f;

             f=i; f=f*Picture_Xpp; f=f/len; x1=f;

                   f=MaxValue-s[i]; f=f*Picture_Ypp; f=f/APPValue; y1=f;

                   x0=x0+Picture_Xmin;

                   x1=x1+Picture_Xmin;

                   y0=y0+Picture_Ymin;

                   y1=y1+Picture_Ymin;

                   if(x1<Picture_Xmin) x1=Picture_Xmin;

                   if(x1>Picture_Xmax) x1=Picture_Xmax;

                   if(y1<Picture_Ymin) y1=Picture_Ymin;

                   if(y1>Picture_Ymax) y1=Picture_Ymax;

                   LCD12864_Draw_Line(x0,y0,x1,y1);//连接两点

                   delay_ms(10);

                   IWDG_ReloadCounter();  //喂狗

         }

}

4、测试数据

float zgg[500]={\

0.015,0.017,0.015,0.013,0.015,0.017,0.012,0.010,0.016,0.005,\

0.010,0.008,0.011,0.007,0.010,0.010,0.012,0.009,0.014,0.010,\

0.010,0.011,0.004,0.018,0.010,0.011,0.012,0.017,0.007,0.011,\

0.011,0.011,0.019,0.013,0.015,0.010,0.006,0.015,0.012,0.008,\

0.009,0.014,0.008,0.011,0.011,0.012,0.012,0.011,0.009,0.009,\

0.008,0.011,0.009,0.016,0.013,0.009,0.017,0.011,0.009,0.016,\

0.016,0.018,0.350,1.455,1.846,1.301,0.915,3.114,2.057,2.492,\

2.492,1.810,2.786,2.759,4.029,3.502,4.158,5.301,4.977,4.885,\

5.187,5.089,7.498,6.864,5.561,5.556,5.785,5.099,5.084,6.788,\

6.813,5.818,7.310,6.542,6.588,7.890,8.497,9.550,7.780,8.992,\

7.991,6.775,7.861,6.070,7.436,7.526,7.428,7.831,8.010,9.033,\

7.712,8.285,10.741,7.642,8.600,8.875,7.750,8.004,8.427,8.585,\

7.681,8.896,9.189,9.090,10.693,10.375,9.289,12.039,10.143,9.360,\

9.090,9.897,9.763,8.382,10.486,10.310,8.447,8.390,10.005,8.476,\

7.379,7.649,6.994,5.216,7.270,6.369,5.622,6.346,5.542,6.544,\

6.661,6.028,6.296,6.355,5.758,4.138,4.123,4.447,2.778,3.776,\

4.231,2.986,3.303,2.086,3.364,3.159,2.510,2.722,2.905,3.149,\

2.334,2.342,4.827,2.402,2.498,3.293,2.702,2.400,0.975,2.333,\

2.484,2.320,1.738,1.826,2.401,1.606,1.907,4.055,2.452,2.557,\

3.185,4.060,3.783,2.288,3.517,3.073,3.835,3.548,3.397,3.621,\

3.277,4.059,6.163,4.788,5.490,5.926,4.776,5.832,5.375,5.931,\

5.641,6.116,6.494,5.810,6.589,6.170,5.996,7.143,6.010,7.020,\

6.084,7.609,7.766,6.424,8.962,7.657,7.651,8.441,8.822,8.056,\

8.056,9.544,10.316,8.953,11.235,9.466,9.439,11.076,9.861,10.979,\

11.175,11.397,11.229,11.782,12.640,11.227,11.199,15.345,12.014,13.559,\

12.358,13.194,13.410,13.420,15.032,14.768,15.588,16.330,15.671,16.423,\

16.384,15.650,17.480,19.635,17.554,17.906,18.879,20.133,18.643,19.774,\

19.774,20.218,20.108,21.673,20.306,19.601,17.923,18.702,19.537,17.518,\

17.518,17.309,15.661,17.110,16.761,16.466,18.900,18.883,19.926,19.239,\

19.339,18.480,20.742,17.802,18.132,18.887,17.559,15.768,16.246,17.168,\

16.190,15.683,15.908,16.724,15.345,15.535,17.338,16.310,15.740,19.018,\

19.018,15.470,16.562,16.356,15.073,16.106,15.629,13.992,14.893,13.934,\

13.934,13.543,13.498,15.776,13.819,13.940,13.533,14.011,14.911,12.808,\

14.547,13.968,13.734,12.015,12.165,12.483,10.434,9.705,11.537,9.156,\

10.918,10.678,9.082,9.774,9.481,10.021,8.808,8.753,9.036,9.195,\

7.963,6.926,7.067,8.801,5.732,6.574,6.389,5.748,5.210,4.475,\

3.889,4.680,3.835,3.285,3.593,3.524,1.565,1.988,4.024,0.016,\

0.015,2.159,0.017,0.016,0.123,0.020,0.014,0.016,0.013,0.015,\

0.015,0.013,0.012,0.013,0.006,0.008,0.010,0.011,0.015,0.009,\

0.012,0.009,0.010,0.009,0.012,0.014,0.010,0.013,0.010,0.011,\

0.012,0.008,0.015,0.012,0.009,0.013,0.018,0.007,0.008,0.012,\

0.009,0.005,0.016,0.014,0.015,0.011,0.009,0.016,0.013,0.011,\

0.006,0.011,0.016,0.003,0.008,0.009,0.016,0.001,0.012,0.014,\

0.007,0.018,0.010,0.013,0.005,0.017,0.016,0.014,0.012,0.906,\

1.162,1.221,2.657,1.665,1.798,1.308,1.938,1.553,2.034,2.732,\

3.292,2.987,3.215,5.045,4.450,4.327,5.036,5.694,6.738,5.664,\

5.955,5.343,5.202,5.067,5.883,5.216,5.913,5.819,6.587,6.393,\

6.486,7.045,8.264,7.951,7.846,7.259,7.427,6.607,7.599,6.556,\

6.556,7.572,7.113,5.954,7.276,9.913,7.580,8.802,11.101,8.764,\

8.764,8.794,7.993,7.160,8.247,8.147,7.197,7.849,9.611,8.391\

};

void Test_DrawPicture(void)

{

  Calculate_MaxValue_MinValue_ And_APPValue(zgg,500);

  DrawPicture(zgg,500);

}

5、测试结果:

若修改Picture_Ymin和Picture_Ypp,则可以放大曲线图。

对于128*64图形点阵LCD,需要注意:Picture_Xmax<128, Picture_Ymax<64

 

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

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

相关文章

本地连接服务器Jupyter【简略版】

首先需要在你的服务器激活conda虚拟环境&#xff1a; 进入虚拟环境后使用conda install jupyter命令安装jupyter&#xff1a; 安装成功后先不要着急打开&#xff0c;因为需要设置密码&#xff0c;使用jupyter notebook password命令输入自己进入jupyter的密码&#xff1a; …

新能源汽车动力电池浸没式冷却方案介绍与未来趋势

前言 新能源汽车的兴起标志着汽车工业的一次革命&#xff0c;其中动力电池的设计与性能成为了关键。浸没式冷却方案作为一种新兴的技术&#xff0c;为动力电池系统提供了有效的散热解决方案&#xff0c;其在未来的发展趋势备受关注。 一 动力电池浸没式冷却方案介绍 首先&am…

用python写算法——栈笔记

栈 栈的定义相关算法题 栈的定义 1.它是一种运算受限的线性表。限定仅在表尾进行插入和删除操作的线性表。这一端被称为栈顶&#xff0c;相对地&#xff0c;把另一端称为栈底。向一个栈插入新元素又称作进栈、入栈或压栈&#xff0c;它是把新元素放到栈顶元素的上面&#xff0…

IIS配置SSL,根据pem和key生成pfx,openssl的版本不能太高

1、生成pfx文件 供应商给的文件是pef和key后缀的两个文件&#xff0c;在IIS里不好导入(如果有知道好导入的可以给我留言&#xff0c;谢谢。)。 1.1 下载OpenSSL工具&#xff0c;并安装。 主要用于将.pem文件转成.pfx文件。 下载OpenSSL的链接&#xff1a;http://slproweb.com/…

设计模式-结构型-适配器模式-Adapter

地址类 public class Address {public void street() {System.out.println("普通的街道");}public void zip() {System.out.println("普通的邮政编码");}public void city() {System.out.println("普通的城市");} } 荷兰地址类 public class …

飞书API(8):MySQL 入库定制版本

一、引入 通用版能解决百分之八九十的任务&#xff0c;剩下的部分任务需要进行定制。 先说明通用版本和定制版本有什么不同&#xff0c;通用版本就是只管大的数据类型&#xff0c;将数据处理为对应的类型入库&#xff0c;而定制版本会考虑局部列的数据类型&#xff0c;。举个…

10分钟了解Golang泛型

泛型是Golang在1.18版本引入的强大工具&#xff0c;能够帮助我们在合适的场合实现简洁、可读、可维护的代码。原文: Go Generics: Everything You Need To Know 导言 可能有人会觉得Go泛型很难&#xff0c;因此想要借鉴其他语言&#xff08;比如Java、NodeJS&#xff09;的泛型…

基于STM32单片机的室内温湿度及PM2.5浓度监测报警系统

基于STM32单片机的室内温湿度及PM2.5浓度监测报警系统 摘要&#xff1a; 本文设计并实现了一个基于STM32单片机的室内温湿度及PM2.5浓度监测报警系统。该系统通过集成温湿度传感器和PM2.5传感器&#xff0c;实时监测室内环境参数&#xff0c;并将数据通过液晶显示屏实时显示。…

docker修改默认安装路径

docker安装之后默认在 /etc/docker 在/etc/docker 文件下有一个daemon -json 没有就新增 {"registry-mirrors": ["https://kfwkfulq.mirror.aliyuncs.com","https://2lqq34jg.mirror.aliyuncs.com","https://pee6w651.mirror.aliyuncs.c…

【计算机网络】物理层传输介质 习题3

双绞线是用两根绝缘导线绞合而成的&#xff0c;绞合的目的是( )。 A.减少干扰 B.提高传输速度 C.增大传输距离 D.增大抗拉强度 在电缆中采用屏蔽技术带来的好处主要是( ) A.减少信号衰减 B. 减少电磁干扰辐射 C.减少物理损坏 D. 减少电缆的阻抗 利用一根同轴电缆互连主机构成…

Linux-页(page)和页表

本文在页表方面参考了这篇博客&#xff0c;特别鸣谢&#xff01; 【Linux】页表的深入分析 1. 页帧和页框 页帧&#xff08;page frame&#xff09;是内存的最小可分配单元&#xff0c;也开始称作页框&#xff0c;Linux下页帧的大小为4KB。 内核需要将他们用于所有的内存需求&a…

Linux(Ubuntu24.04) 安装 MinIO

本文所使用的 Ubuntu 系统版本是 Ubuntu 24.04 ! # 1、下载 MinIO wget https://dl.min.io/server/minio/release/linux-amd64/minio# 2、添加可执行权限 chmod x minio# 3、导出环境变量&#xff0c;用于设置账号密码&#xff0c;我设置的账号和密码都是 minioadmin export MI…

[蓝桥杯]真题讲解:AB路线(BFS+分层图)

[蓝桥杯]真题讲解&#xff1a;AB路线&#xff08;BFS分层图&#xff09; 一、视频讲解二、正解代码1、C2、python33、Java 一、视频讲解 [蓝桥杯]真题讲解&#xff1a;AB路线&#xff08;BFS分层图&#xff09; 二、正解代码 1、C #include<bits/stdc.h> #define INF …

PyCharm 集成 Git

目录 1、配置 Git 忽略文件 2、定位Git 3、使用pycharm本地提交 3.1、初始化本地库 3.2、添加到暂存区 3.3、提交到本地库 3.4、切换版本 4、分支操作 4.1、创建分支 4.2、切换分支 4.3、合并分支 5、解决冲突 1、配置 Git 忽略文件 作用&#xff1a;与项目的实际…

问题:幂等性 分布式session

web项目中请求线程到service层的时候远程调用服务之前是串行化执行每个任务都要get阻塞等待任务完成&#xff0c;举例当用户在购物车页面点击去结算就会请求后台toTrade请求获取订单确认的详情数据并渲染到订单详情页&#xff0c;现在在toTrade请求中使用异步任务编排Completab…

Linux下安装mysql8.0(以tar.xz包安装--编译安装)

前言&#xff1a;原文在我的博客网站中&#xff0c;持续更新数通、系统方面的知识&#xff0c;欢迎来访&#xff01; Linux下安装mysql8.0&#xff08;以tar.xz包安装--编译安装&#xff09;https://myweb.myskillstree.cn/126.html 目录 一、下载对应自己glic版本的MySQL …

1.基于python的单细胞数据预处理-降维可视化

目录 降维的背景PCAt-sneUMAP检查质量控制中的指标 参考&#xff1a; [1] https://github.com/Starlitnightly/single_cell_tutorial [2] https://github.com/theislab/single-cell-best-practices 降维的背景 虽然特征选择已经减少了维数&#xff0c;但为了可视化&#xff0…

C++语法|智能指针的实现及智能指针的浅拷贝问题、auto_ptr、scoped_ptr、unique_ptr、shared_ptr和weak_ptr详细解读

文章目录 1.自己实现智能指针智能指针引起的浅拷贝问题尝试定义自己的拷贝构造函数解决浅拷贝 2.不带引用计数的智能指针auto_ptrscoped_ptrunique_ptr&#xff08;推荐&#xff09; 3.带引用计数的智能指针模拟实现引用计数shared_ptr和weak_ptr循环引用&#xff08;交叉引用&…

DDD架构理论详解

文章目录 一、概念入门1. 概念简介2. DDD的核心理念3. 范式4. 模型5. 框架6. 方法论7. 软件设计的主要活动 二、DDD核心理论1. Domain领域层都包含什么&#xff1f;2. 聚合、实体和值对象3. 仓储&#xff0c;封装持久化数据4. 适配&#xff08;端口&#xff09;&#xff0c;调用…

AI应用案例:新闻文本分类

随着科学技术的不断发展&#xff0c;互联网技术得以快速的发展和普及&#xff0c;并已在各行各业得到了广泛的应用&#xff0c;从中致使了网络上的信息呈现出爆炸式的增长状态&#xff0c;达到了“足不出户&#xff0c;万事皆知”的境况&#xff0c;充分体现了互联网新闻给生活…