adc采集
完整代码下载:
ADC采集.7z
(231.52 KB, 下载次数: 19)
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart1.h"
- #include "lcd.h"
- #include "adc.h"
- //ALIENTEK Mini STM32开发板范例代码15
- //ADC实验
- //广州市星翼电子科技有限公司
-
- int main(void)
- {
- u16 adcx,adcx1;
- float temp,temp1;
- delay_Init(); //延时函数初始化
- usart1_Init(9600); //串口初始化为9600
- LED_Init(); //初始化与LED连接的硬件接口
- LCD_Init();
- Adc_Init(); //ADC初始化
- POINT_COLOR=RED;//设置字体为红色
- LCD_ShowString(60,50,200,16,16,"Mini STM32");
- LCD_ShowString(60,70,200,16,16,"ADC TEST");
- LCD_ShowString(60,90,200,16,16,"GROUP5");
- LCD_ShowString(60,110,200,16,16,"2016/12/27");
- //显示提示信息
- POINT_COLOR=BLUE;//设置字体为蓝色
- LCD_ShowString(60,130,200,16,16,"ADC_CH1_VAL:");
- LCD_ShowString(60,150,200,16,16,"ADC_CH1_VOL:0.000V");
- LCD_ShowString(60,180,200,16,16,"ADC_CH2_VAL:");
- LCD_ShowString(60,200,200,16,16,"ADC_CH2_VOL:0.000V");
- while(1)
- {
- adcx=Get_Adc_Average(ADC_Channel_1,10);
- adcx1=Get_Adc_Average(ADC_Channel_2,10);
- LCD_ShowxNum(156,130,adcx,4,16,0);//显示ADC的值
- LCD_ShowxNum(156,180,adcx1,4,16,0);//显示ADC的值
- temp=(float)adcx*(3.3/4096);
- temp1=(float)adcx1*(3.3/4096);
- adcx=temp;
- adcx1=temp1;
- LCD_ShowxNum(156,150,adcx,1,16,0);//显示电压值
- LCD_ShowxNum(156,200,adcx1,1,16,0);//显示电压值
- temp-=adcx;
- temp1-=adcx1;
- temp*=1000;
- temp1*=1000;
- LCD_ShowxNum(172,150,temp,3,16,0X80);
- LCD_ShowxNum(172,200,temp1,3,16,0X80);
- delay_ms(250);
- }
- }
复制代码
|