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

2024-05-09 00:36

本文主要是介绍使用单片机在图形点阵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

 

这篇关于使用单片机在图形点阵LCD上绘制波形图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/971890

相关文章

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

git使用的说明总结

Git使用说明 下载安装(下载地址) macOS: Git - Downloading macOS Windows: Git - Downloading Windows Linux/Unix: Git (git-scm.com) 创建新仓库 本地创建新仓库:创建新文件夹,进入文件夹目录,执行指令 git init ,用以创建新的git 克隆仓库 执行指令用以创建一个本地仓库的

【北交大信息所AI-Max2】使用方法

BJTU信息所集群AI_MAX2使用方法 使用的前提是预约到相应的算力卡,拥有登录权限的账号密码,一般为导师组共用一个。 有浏览器、ssh工具就可以。 1.新建集群Terminal 浏览器登陆10.126.62.75 (如果是1集群把75改成66) 交互式开发 执行器选Terminal 密码随便设一个(需记住) 工作空间:私有数据、全部文件 加速器选GeForce_RTX_2080_Ti