@基于stm32的adc检测波形 0.96oled显示(spi/iic)移植gui库(开源)。
使用标准库开发,未使用dsp官方库。

adc采集到电压并且在oled上显示。

支持0-3.3v电压采集显示波形,如若需要更大范围请串联电阻利用分压计算。
基于stm32f103标准库,使用独立模式。GPIOC_PIN4作为adc采集引脚。
oled个人使用了0.96寸oled(spi接口)作为显示设备。
在这里插入图片描述

效果演示。

之后可能会上传b战包含开源链接一些说明等。

adc采集中断服务函数

这个服务函数在stm32f10x_it.c处

void ADC_IRQHandler(void)
{	
	if (ADC_GetITStatus(ADCx,ADC_IT_EOC)==SET) 
	{
		// 读取ADC的转换值
		ADC_ConvertedValue = ADC_GetConversionValue(ADCx);
	}
	ADC_ClearITPendingBit(ADCx,ADC_IT_EOC);
}

main.c函数

/**
  ******************************************************************************
  * @file    stm32_fft_spi_oled.c
  * @author  wei&fire
  * @version V1.0
  * @date    2022-06-18
  * @brief   输入信号进行fft,使用128*64点阵的OLED显示测试工程,仅适用于SD1306驱动spi通信方式显示屏
  ******************************************************************************
  *
  * 实验平台:野火 ISO STM32 开发板 
  * 邮箱    :384563117@qq.com
  * 作者:zzwei
	* gui作者:https://github.com/hello-myj/stm32_oled
  ******************************************************************************
  */ 
	
#include "stm32f10x.h"
#include "delay.h"
#include "bsp_usart.h"
#include "test.h"
#include "draw_api.h"
#include "bsp_adc.h"
#include "stdlib.h"
unsigned char x1,y1,len1;
unsigned int num1,num2,num3,num4,num5;
unsigned char i1,i2,i3,i4;
unsigned int h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15;
unsigned int h[];

extern __IO uint16_t ADC_ConvertedValue;
float ADC_ConvertedValueLocal; 
char* str;
char* str1;
char* str2;
char* str3;
char* str4;
char* str5;
char* R1;
char* vmax; 
char* vmin;
char* RYIN;
char* RYANG;


void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
} 

char *Float2String(float value)
{
	char* str = (char*)malloc(10);
	int Head = (int)value;
	int Point = (int)((value - Head)*10.0);
	sprintf(str, "%d.%d", Head, Point);

	return str;
}
static char table[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

void num2char(char *str, double number, uint8_t g, uint8_t l)
{
    uint8_t i;
    int temp = number/1;
    double t2 = 0.0;
    for (i = 1; i<=g; i++)
    {
        if (temp==0)
            str[g-i] = table[0];
        else
            str[g-i] = table[temp%10];
        temp = temp/10;
    }
    *(str+g) = '.';
    temp = 0;
    t2 = number;
    for(i=1; i<=l; i++)
    {
        temp = t2*10;
        str[g+i] = table[temp%10];
        t2 = t2*10;
    }
    *(str+g+l+1) = '\0';
}


int main(void)
{
	  /* 嵌套向量中断控制器组选择 */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	DelayInit();
//	USART_Config();
	InitGraph();	
	// ADC 初始化
	ADCx_Init();//adc初始化
	char str[20];//float》str类型转换需要
	num5=0;
	num1=62;num2=124;
	h2=2;
	h1=0;
	i4=0;
	h11=0;
	h12=3;
	while(1)
	{
		h4=ADC_ConvertedValueLocal;
		h4=(5-h4)*10;
		ADC_ConvertedValueLocal =(float) ADC_ConvertedValue/4096*3.3;//中断中获取到adc值转换为float 
    num2char(str, ADC_ConvertedValueLocal, 2, 8);//float转换char* str
		DrawString(num5,num5,str);//显示(int,int,char* str)
		DrawLine(num5,num1,num2,num1);//x
		DrawLine(num5,num1,num5,num5);//y
		h1=ADC_ConvertedValueLocal;
		h14=h1;
		h1=(5-h1)*10;
		h3=h2-1;
		DrawLine(h3,h1,h2,h4);//绘制线
		h5=h4-h1;
		if(h4>h1 && h5>=1)
		{
		h6=h4-10;
		str1=Float2String(ADC_ConvertedValueLocal);
		DrawString(h2,h6,str1);//显示(int,int,char* str)v
		h5=0;
		DelayMs(30000);//延时 
		}
			if(h4<h1 && h5>=1)
		{
		h6=h4+20;
		str1=Float2String(ADC_ConvertedValueLocal);
		DrawString(h2,h6,str1);//显示(int,int,char* str)v
		h5=0;	
		DelayMs(30000);//延时 
		}	
		h2=h2+1;
		UpdateScreen();//更新屏幕数据
	  DelayMs(30000);//延时 	
		if(h2>=128)
		{
		ClearScreen();
		h2=0;			
		}
	}
}

说明

作者:zzwei
本开源项目基于stm32固件库编程 移植了https://github.com/hello-myj/stm32_oled
作者gui库电压检测示波器开发。
(1).gui库说明
oled库说明:
该库只是一个绘图图形库,只能适用于stm32系列的12864oled屏,驱动芯片为ssd1306,若需被其他平台使用,请自行移植

连接引脚:
STM32的硬件I2C:
IIC_1: PB6 – SCL; PB7 – SDA
IIC_2: PB10-- SCL; PB11 --SDA(还未验证)
STM32的硬件SPI:
SPI_1:暂未添加,若需请在oled_driver.h自行配置
SPI_2:PB10–RES; PB11–DC; PB12–CS;PB13–D0;PB15–D1;
暂未添加软件模拟,后续会添加

图形库文件说明:
draw_api.h:所需的各类api绘图方法
oled_config.h:配置o文件, 用于配置led屏
oled_config.c:配置文件所需的接口
oled_driver.c:oled屏驱动
oled_draw.c:各类绘图方法
oled_basic.c:底层和算法支撑
oled_color.c:颜色控制
oled_buffer.c:屏幕缓冲区和临时缓冲区
oled_font.c:字体
oled_bmp.c:bmp取模图形存放位置,
oled_debug.c可调用OledPrintf方法,效果与printf一致。

其他:
使用的取模工具为:PCtoLCD2002,已放入tool文件夹中,使用方法请参考tool/取模设置
注意:硬件IIC出现卡死现象,请关掉串口初始化并重新上电
该库还不完善,还在持续更新,
开源链接:
https://download.csdn.net/download/clonearm/85803877
[点击链接](https://download.csdn.net/download/clonearm/85803877)
欢迎大家复现。key1 与key2 可以自己配置就不加多叙述

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐