#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "adc.h"
/************************************************
ALIENTEK精英STM32开发板实验17
ADC 实验
技术支持:
www.openedv.com
淘宝店铺:http://eboard.taobao.com
关注微信公众平台微信号:"正点原子",免费获取STM32资料。
广州市星翼电子科技有限公司
作者:正点原子 @ALIENTEK
************************************************/
int main(void)
{
u16 adcx;
float temp1,temp2;
u16 x;
u16 y;
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
LED_Init(); //LED端口初始化
LCD_Init();
Adc_Init(); //ADC初始化
POINT_COLOR=RED;//设置字体为红 {MOD}
LCD_ShowString(60,50,200,16,16,"Elite STM32");
LCD_ShowString(60,70,200,16,16,"ADC TEST");
LCD_ShowString(60,90,200,16,16,"
ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2019/3/8");
//显示提示信息
POINT_COLOR=BLUE;//设置字体为蓝 {MOD}
LCD_ShowString(60,130,200,16,16,"ADC_CH0_VAL:");
LCD_ShowString(60,150,200,16,16,"ADC_CH0_VOL:0.000V");
LCD_ShowString(60,170,200,16,16,"Digital Signal0:");
LCD_ShowString(60,190,200,16,16,"ADC_CH1_VAL:");
LCD_ShowString(60,210,200,16,16,"ADC_CH1_VOL:0.000V");
LCD_ShowString(60,230,200,16,16,"Digital Signal1:");
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_5,400);
LCD_ShowxNum(156,130,adcx,4,16,0);//显示ADC的值
temp1=(float)adcx*(4.0/4096);
adcx=temp1;
LCD_ShowxNum(156,150,adcx,1,16,0);//显示电压值
temp2=temp1-adcx;
temp2*=1000;
LCD_ShowxNum(172,150,temp2,3,16,0X80);
if(temp1>3.3)
x=0;
else
if(temp1>2.64)
x=1;
else
if(temp1>1.98)
x=2;
else
if(temp1>1.32)
x=3;
else
if(temp1>0.66)
x=4;
else
if(temp1>0)
x=5;
LCD_ShowxNum(188,170,x,1,16,0);
adcx=Get_Adc_Average(ADC_Channel_1,400);
LCD_ShowxNum(156,190,adcx,4,16,0);//显示ADC的值
temp1=(float)adcx*(4.0/4096);
adcx=temp1;
LCD_ShowxNum(156,210,adcx,1,16,0);//显示电压值
temp2=temp1-adcx;
temp2*=1000;
LCD_ShowxNum(172,210,temp2,3,16,0X80);
//减去整数部分
//放大1000倍
//显示小数部分。
if(temp1>3.3)
y=0;
else
if(temp1>2.64)
y=1;
else
if(temp1>1.98)
y=2;
else
if(temp1>1.32)
y=3;
else
if(temp1>0.66)
y=4;
else
if(temp1>0)
y=5;
LCD_ShowxNum(188,230,y,1,16,0);
LED0=!LED0;
delay_ms(50);
}
}
后缀CSV就可以了
一周热门 更多>