标题: STM32 AD采集电压 显示屏显示程序 [打印本页]

作者: D不爱吃鱼zzZ    时间: 2019-7-13 14:00
标题: STM32 AD采集电压 显示屏显示程序
这是我自己写的AD采集电压显示
亲测好用

单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "core_cm3.h"
  3. #include "system.h"
  4. #include "delay.h"
  5. #include "nokia_5110.h"
  6. #include "adc.h"
  7. int main(void)
  8. {       
  9.        
  10.         float temp;
  11.         u16 adcx;
  12.         u8 num = 0;
  13.        
  14.        
  15.         delay_init(72);
  16.         delayms(500);
  17.         LCD_init(); //初始化液晶   
  18.         LCD_clear();
  19.         Adc_Init();       



  20.         //PC13置零 LED亮
  21.         RCC ->APB2ENR |= 1 << 4;                        //使能PC时钟
  22.         GPIOC -> CRH &= 0xFF0FFFFF;                //清除PC13设置
  23.         GPIOC -> CRH |= 0x00300000;                //通用推挽输出,50MHz
  24.         GPIOC -> BRR = 1<< 13;
  25.        
  26.         while(1)
  27.         {
  28.                
  29.                
  30.                
  31.                 adcx=Get_Adc_Average(ADC_Channel_9,20);//adc通道9,取20个ADC计算平均值
  32.                 LCD_write_english_string(0,0,"ADC:");//显示ADC
  33.                 LCD_set_XY(24,0);
  34.                 LCD_write_char(adcx/1000%10 + '0');
  35.                 LCD_set_XY(30,0);
  36.                 LCD_write_char(adcx/100%10 + '0');
  37.                 LCD_set_XY(36,0);
  38.                 LCD_write_char(adcx/10%10 + '0');
  39.                 LCD_set_XY(42,0);
  40.                 LCD_write_char(adcx%10 + '0');
  41.                 temp=(float)adcx*(3.3/4096);//adc12位
  42.                 adcx=temp;
  43.                 LCD_set_XY(0,3);
  44.                 LCD_write_char(adcx%10 + '0');//显示电压值1.0
  45.                
  46.                 temp-=adcx;
  47.                 temp*=1000;
  48.                
  49.                 adcx=temp;
  50.         LCD_set_XY(13,3);
  51.                 LCD_write_char(adcx/100%10 + '0');//显示电压值0.1
  52.                 LCD_set_XY(19,3);
  53.                 LCD_write_char(adcx/10%10 + '0');//显示电压值0.01
  54.                 LCD_set_XY(25,3);
  55.                 LCD_write_char(adcx%10 + '0');//显示电压值0.001
  56.                 delayms(50);       
  57.                 LCD_write_english_string(7,3,".");
  58.                 LCD_write_english_string(31,3,"V");
  59.         LCD_write_chinese_string(0,1,14,4,0,2);

  60.         }
  61. }
复制代码

所有资料51hei提供下载:
ADC LCD.7z (187.77 KB, 下载次数: 40)




作者: admin    时间: 2019-7-14 03:11
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1