這是我自己寫的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)
2019-7-14 03:11 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|