使用单片机在图形点阵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

 

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

在做题中学习(50):搜索插入位置

35. 搜索插入位置 - 力扣&#xff08;LeetCode&#xff09; 解法&#xff1a;二分查找 思路&#xff1a;题目是有序的&#xff0c;时间复杂度O(logN),二分没跑了&#xff0c;题目说如果找不到target&#xff0c;返回它应该被插入位置的下标&#xff0c;所以可以分析一下示例2&…

电子书3D翻页制作技巧大揭秘,轻松将文档转化为逼真仿真书!

随着数字化时代的到来&#xff0c;电子书已成为阅读的主流形式之一。然而&#xff0c;普通的电子书往往缺乏纸质书的质感和互动性&#xff0c;让人感到有些遗憾。今天&#xff0c;将为你揭秘电子书3D翻页制作技巧&#xff0c;让你轻松将文档转化为逼真仿真书&#xff01; 1.要制…

中国热门高端dating约会交友软件有哪些?国内权威Dating App红黑排行榜推荐

在dating 软件刷了无数个男人后终于脱单啦&#xff0c;跟大家分享一些我的个人感受 1、二狗 颜值⭐️⭐️⭐️ 真实性 ⭐️⭐️⭐️⭐️⭐️ 用户质量⭐️⭐️⭐️⭐️ ⭕️优点&#xff1a;整体用户质量较高&#xff0c;用户集中在金融、互联网和体制内行业。用户需进行学历、…

Oopsie从80端口到获取root权限的渗透过程

Oopsie 需要用到的工具burpnmapnc手写代码信息收集 由于是靶场的原因单一没有子站所以收集到ip就可以nmap扫描 拿到IP第一件事就是扫描端口 nmap -T4 -sV -sC -sS 10.129.24.79 -T4:提升扫描速度 -sV&#xff1a;查看详细版本 -sC:使用默认类别的脚本进行扫描 可更换其他类别…

ADC模-数转换原理与实现

1. 今日摸鱼计划 今天来学习一下ADC的原理&#xff0c;然后把ADC给实现 ADC芯片:ADC128S102 视频&#xff1a; 18A_基于SPI接口的ADC芯片功能和接口时序介绍_哔哩哔哩_bilibili 18B_使用线性序列机思路分析SPI接口的ADC芯片接口时序_哔哩哔哩_bilibili 18C_基于线性序列机的S…

“情况不明,对子先行”攻略

掼蛋作为一种策略性极强的游戏&#xff0c;不仅考验牌技&#xff0c;更考验玩家的智慧和策略布局。这里主要介绍一下当牌力不足的时候的普通策略—情况不明&#xff0c;对子先行。 当你的牌力不强&#xff0c;或者牌局情况不明朗时&#xff0c;自己手上有有比较多的对子&#x…

【前端】前端数据本地化的多种实现方式及其优劣对比

前端数据本地化的多种实现方式及其优劣对比 在现代Web开发中&#xff0c;提高页面响应速度和改善用户体验是核心目标之一。数据本地化是其中一种实现方式&#xff0c;它通过在客户端存储数据来减少服务器请求&#xff0c;从而加快数据载入速度和改善用户的体验。本文将介绍前端…

面试大全资料分享-工作无忧

找工作啦 面试大全资料分享 关注公众号 回复 面试大全 即可获取下载链接.

Chromium编译指南2024 Windows11篇-GN 工具生成构建文件(六)

前言 在《Chromium编译指南2024&#xff08;五&#xff09;》我们已经获取了 Chromium 的源代码并且同步了相关的第三方依赖。 现在&#xff0c;我们将进一步学习如何使用 GN 工具生成构建文件&#xff0c;为后续的编译工作做好准备。 1. 使用gn工具生成构建文件 再次在Win…

C#里如何设置输出路径,不要net7.0-windows

官网介绍&#xff1a; 更改生成输出目录 - Visual Studio (Windows) | Microsoft Learn <PropertyGroup> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendRuntimeIdentifierToOutputPath>false</Appen…

Shell编程之条件语句与case语句

一、条件测试操作 Shell环境根据命令执行后的返回状态值&#xff08;$?&#xff09;来判断是否执行成功&#xff0c;当返回值为0&#xff08;真true&#xff09;时表示成功&#xff0c;返回值为非0值&#xff08;假false&#xff09;时表示失败或异常 test命令 测试表达式是…

FPGA学习笔记(1)——Vivado和HLS

1 Vivado设计 1.1 FPGA基本知识 Xilinx Atrix-7使用6输入LUT结构&#xff08;0-63&#xff09;CLB&#xff1a;可配置逻辑块Slice&#xff1a;每个CLB包含2个Slice(包含查找表LUT和8位寄存器REG)布线池&#xff1a;围绕在CLB周围&#xff0c;衔接FPGA的资源调度I/O块&#xf…

由北京车展想到的,技术红利时代的“重启”

北京车展刚刚落幕&#xff0c;雷军和周鸿祎成为网红&#xff0c;国产品牌站上王座。与此同时&#xff0c;马斯克“光速”访华&#xff0c;FSD酝酿入华再掀新竞争。华为在车展前发布的智驾新品牌“乾崑”&#xff0c;同样在现场广受关注。它们的精彩&#xff0c;让燃油车羡慕。 …

六西格玛备考攻略:无从下手?一文让你豁然开朗

当你决定备考六西格玛时&#xff0c;可能会感到有些无从下手。毕竟&#xff0c;这是一个涉及多个领域和方面的综合性考试&#xff0c;需要掌握的知识点和技能也非常广泛。但是&#xff0c;只要你有一个清晰的学习计划和一些有效的备考方法&#xff0c;就能够顺利地通过考试。以…

STM32F405 FOC 使用Timer 触发 ADC采集

STM32F405 FOC 使用Timer 触发 ADC 1. ADC采集模式2. 高级Timer模式3. ADC1 连续采集3.1 DMA软件触发3.2 DMATIM触发 4. ADC 注入模式采集5. 最终使用方法 1. ADC采集模式 根据STM32F405数据手册&#xff0c;可以看到ADC block diagram&#xff0c;ADC主要有两种触发模式&…

【VUE】el-descriptions 描述列表

Descriptions 描述列表 列表形式展示多个字段。 <el-descriptions title"用户信息"><el-descriptions-item label"用户名">kooriookami</el-descriptions-item><el-descriptions-item label"手机号">18100000000</e…

巨资回流,量子投资热潮再起

一股新的信心和资金浪潮正在席卷量子计算产业。 2023年4月30日&#xff0c;澳大利亚联邦政府和昆士兰州政府宣布共同出资9.4亿澳元&#xff08;约合6.2亿美元&#xff09;&#xff0c;支持美国初创企业PsiQuantum在布里斯班附近建设一台大型量子计算机。这项投资是最新的迹象之…

Linux中动态库的用法及优缺点?怎样制作动态库和静态库?

一、什么是gcc gcc的全称是GNU Compiler Collection&#xff0c;它是一个能够编译多种语言的编译器。最开始gcc是作为C语言的编译器&#xff08;GNU C Compiler&#xff09;&#xff0c;现在除了c语言&#xff0c;还支持C、java、Pascal等语言。gcc支持多种硬件平台. 在 Linux…

Leetcode—706. 设计哈希映射【简单】(constexpr)

2024每日刷题&#xff08;127&#xff09; Leetcode—706. 设计哈希映射 数组实现代码 class MyHashMap { public:MyHashMap() {memset(arr, -1, sizeof(arr));}void put(int key, int value) {arr[key] value;}int get(int key) {if(arr[key] -1) {return -1;} return arr…

可视化:智慧能源解决方案,降本增效,运筹帷幄。

智慧能源可视化解决方案是一种利用先进的技术和工具&#xff0c;将能源数据以直观、可视的方式呈现出来&#xff0c;帮助企业更好地管理能源使用&#xff0c;降低成本&#xff0c;提高效率的解决方案。 以下是一些智慧能源可视化解决方案可以帮助企业降本增效、智连未来的方式&…