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

news2024/11/24 1:23:34

使用单片机在图形点阵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.coloradmin.cn/o/1666938.html

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

相关文章

python实现动态时钟功能

欢迎关注我👆,收藏下次不迷路┗|`O′|┛ 嗷~~ 一.前言 时钟,也被称为钟表,是一种用于测量、记录时间的仪器。时钟通常由时针、分针、秒针等计时仪器组成,是现代社会不可或缺的一种计时工具。它的发明和使用极大地改变了人类的生活方式和时间观念。 时钟的类型有很多,…

批量文本高效编辑神器:轻松拆分每行内容,一键保存更高效!轻松实现批量拆分与保存

文本处理成为我们日常工作中的一项重要任务。然而&#xff0c;面对大量的文本内容&#xff0c;传统的逐行编辑方式往往显得繁琐且效率低下。那么&#xff0c;有没有一种更高效、更便捷的解决方案呢&#xff1f;答案是肯定的——批量文本高效编辑神器&#xff0c;让您的文本处理…

torch_geometric安装(CPU版本)

①打开官方安装网址&#xff1a;https://pytorch-geometric.readthedocs.io/en/2.3.0/install/installation.html ②对根据Pytorch选择相应版本。此前一直用CUDA不成功&#xff0c;这次使用CPU版本&#xff08;因为不用对应cuda&#xff0c;pytorchcudageometric三者对应起来很…

深入理解Java并发:Future与CompletableFuture详解

知识背景&#xff1a; 在工作过程中有用到CompletableFuture&#xff0c;之前接触不多&#xff0c;特此下来学习一下&#xff0c;与大家一起分享&#xff01; 总体介绍&#xff1a; 在多线程编程中&#xff0c;异步计算是一种常见的需求。其中Future和CompletableFuture是处…

前端AJAX与后台交互技术知识点及案例(续2)

以下笔记均为学习哔站黑马程序员AJAX视频所得&#xff01;&#xff01;&#xff01; AJAX作用&#xff1a;浏览器和服务器之间通信&#xff0c;动态数据交互 axios函数 先引入axios库&#xff0c;可在bootcdn中寻找相关js文件或者对应的script标签 axios({url:http://hmajax…

echarts环形图 legend文字过长显示...鼠标移动上展示全称

legend: {type: scroll,orient: vertical,x: left,y: bottom,top: "42%",left: 13%,data: this.dutyNames,textStyle: { color: #fff },triggerEvent: true,tooltip: {show: true,trigger: item,//鼠标移动上去展示全称},formatter: function (params) {var val &qu…

构建一个快速数据分析(boruta+shap+rcs)的shiny APP

构建一个快速数据分析&#xff08;borutashaprcs&#xff09;的shiny APP 之前提出了一个快速数据分析的流程&#xff0c;包括&#xff1a; 变量筛选&#xff0c;使用Boruta等变量筛选的方法来找出相关的变量&#xff1b;发现规律&#xff0c;使用SHAP分析的散点图、交互作用图…

微服务思想以及实现

文章目录 前言一、什么时候需要拆分微服务1. 创业型项目2. 大型项目 二、怎么拆1. 拆分目标2. 拆分方式 三、微服务之间远程调用1. 实现方式2. 手动发送Http请求&#xff08;RestTemplate&#xff09;3. 服务注册中心3.1 原理3.2 Nacos注册中心3.3 服务注册3.4 服务发现(Discov…

牛客网Java实战项目--仿牛客网社区的学习笔记

仿牛客网社区的学习笔记 1. 项目环境搭建1.1 开发社区首页 2.开发社区登录模块2.1 发送邮件2.2 开发注册功能2.3 会话管理2.4 生成验证码2.5 开发登录、退出功能2.6 显示登录信息 4 Redis实现点赞关注4.1 Spring整合Redis访问Redis的方法&#xff1a; 4.2 Redis实现点赞4.2.1 点…

【图解计算机网络】http1.1,http2.0,http3.0

http1.1&#xff0c;http2.0&#xff0c;http3.0 http1.1长连接管道传输缺点 http2.0头部压缩二进制格式并发传输服务端推送缺点 http3.0无队头阻塞快速建立连接连接迁移 http1.1 长连接 在http1.0的时候&#xff0c;一次http请求就要建立一次TCP连接&#xff0c;这一次的htt…

【计算机网络篇】数据链路层(10)在物理层扩展以太网

文章目录 &#x1f354;扩展站点与集线器之间的距离&#x1f6f8;扩展共享式以太网的覆盖范围和站点数量 &#x1f354;扩展站点与集线器之间的距离 &#x1f6f8;扩展共享式以太网的覆盖范围和站点数量 以太网集线器一般具有8~32个接口&#xff0c;如果要连接的站点数量超过了…

【busybox记录】【shell指令】ls

目录 内容来源&#xff1a; 【GUN】【ls】指令介绍 【busybox】【ls】指令介绍 【linux】【ls】指令介绍 使用示例-默认输出&#xff1a; 列出目录内容 - 默认输出 列出目录内容 - 不忽略以.开头的文件 列出目录内容 - 不忽略以.开头的文件&#xff0c;只忽略.和..文件…

使用Maven对Java独立应用程序进行编译打包

一、 安装Maven 1.解压&#xff0c;移动安装包 sudo tar -zxf ~/apache-maven-3.9.6-bin.tar.gz -C /usr/local/ cd /usr/local/ sudo mv apache-maven-3.9.6/ ./maven-3.9.6 sudo chown -R qiangzi ./maven-3.9.6 二、Java应用程序代码 1.版本信息&#xff1a; Spark-2.1…

picoCTF-Web Exploitation-More SQLi

Description Can you find the flag on this website. Additional details will be available after launching your challenge instance. Hints SQLiLite 先随便输入个账号密码登录一下&#xff0c;得到查询SQL&#xff0c;接下来应该对SQL进行某些攻击来绕过密码登录成功 -- …

如何自定义Linux命令

说明&#xff1a;本文介绍如何将自己常用的命令设置为自定义的命令&#xff0c;以下操作在阿里云服务器CentOS上进行。 修改配置文件 修改配置文件前&#xff0c;先敲下面的命令查看当前系统配置的shell版本 echo $SHELL或者 echo $0区别在于&#xff0c;$SHELL查看的是系统…

【Shell】shell编程之循环语句

目录 1.for循环 例题 2.while循环 例题 3.until循环 1.for循环 读取不同的变量值&#xff0c;用来逐个执行同一组命令 for 变量 in 取值列表 do 命令序列 done [rootlocalhost ~]# for i in 1 2 3 > do > echo "第 $i 次跳舞" > done 第 1 次跳舞 第 …

java基础之面向对象的思想

一、面向对象和面向过程的编程思想对比 面向过程&#xff1a;是一种以过程为中心的编程思想&#xff0c;实现功能的每一步&#xff0c;都是自己实现的&#xff08;自己干活&#xff09;。 面向对象&#xff1a;是一种以对象为中心的编程思想&#xff0c;通过指挥对象实现具体的…

5. 简单说一说uniapp中的语法吧

前言 如果你 知道Vue3并且对Vue3的语法有一定了解&#xff0c;请跳过这一章&#xff0c;由于后续项目主要是基于Vue3TypeScript&#xff0c;因此提前简单概述一些Vue3的基础语法~ 本文的目的是 期望通过对本文的阅读后能对Vue3的每个语法有一个简单的印象&#xff0c;至少要知…

【Linux】动态库与静态库的底层比较

送给大家一句话&#xff1a; 人生最遗憾的&#xff0c;莫过于&#xff0c;轻易地放弃了不该放弃的&#xff0c;固执地坚持了不该坚持的。 – 柏拉图 (x(x_(x_x(O_o)x_x)_x)x) (x(x_(x_x(O_o)x_x)_x)x) (x(x_(x_x(O_o)x_x)_x)x) 底层比较 1 前言2 编译使用比较2 如何加载Than…

连升三级!openGauss单机版从2.1.0经停3.0.0升级至5.0.0

前言 如前文所述&#xff0c;我们的小demo项目起初安装了openGauss的2.1.0版本&#xff0c;由于2.1.0不是长期维护&#xff08;LTS&#xff09;版本&#xff0c;所以要升级到5.0.0LTS。考虑到虽然是DEMO项目&#xff0c;但也有些体验用户&#xff0c;所以为了保障业务连续性&a…