这是我自己写的AD采集电压显示
亲测好用
单片机源程序如下:
- #include "stm32f10x.h"
- #include "core_cm3.h"
- #include "system.h"
- #include "delay.h"
- #include "nokia_5110.h"
- #include "adc.h"
- int main(void)
- {
-
- float temp;
- u16 adcx;
- u8 num = 0;
-
-
- delay_init(72);
- delayms(500);
- LCD_init(); //初始化液晶
- LCD_clear();
- Adc_Init();
- //PC13置零 LED亮
- RCC ->APB2ENR |= 1 << 4; //使能PC时钟
- GPIOC -> CRH &= 0xFF0FFFFF; //清除PC13设置
- GPIOC -> CRH |= 0x00300000; //通用推挽输出,50MHz
- GPIOC -> BRR = 1<< 13;
-
- while(1)
- {
-
-
-
- adcx=Get_Adc_Average(ADC_Channel_9,20);//adc通道9,取20个ADC计算平均值
- LCD_write_english_string(0,0,"ADC:");//显示ADC
- LCD_set_XY(24,0);
- LCD_write_char(adcx/1000%10 + '0');
- LCD_set_XY(30,0);
- LCD_write_char(adcx/100%10 + '0');
- LCD_set_XY(36,0);
- LCD_write_char(adcx/10%10 + '0');
- LCD_set_XY(42,0);
- LCD_write_char(adcx%10 + '0');
- temp=(float)adcx*(3.3/4096);//adc12位
- adcx=temp;
- LCD_set_XY(0,3);
- LCD_write_char(adcx%10 + '0');//显示电压值1.0
-
- temp-=adcx;
- temp*=1000;
-
- adcx=temp;
- LCD_set_XY(13,3);
- LCD_write_char(adcx/100%10 + '0');//显示电压值0.1
- LCD_set_XY(19,3);
- LCD_write_char(adcx/10%10 + '0');//显示电压值0.01
- LCD_set_XY(25,3);
- LCD_write_char(adcx%10 + '0');//显示电压值0.001
- delayms(50);
- LCD_write_english_string(7,3,".");
- LCD_write_english_string(31,3,"V");
- LCD_write_chinese_string(0,1,14,4,0,2);
- }
- }
复制代码
所有资料51hei提供下载:
ADC LCD.7z
(187.77 KB, 下载次数: 40)
|