stm32的基础问题,求大神赐教,万分感谢。
时间:10-02
整理:3721RD
点击:
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "adc.h"
int main(void)
{
u16 adcx,adcx1,adcx2,adcx3,adc4;
float temp,temp1,temp2,temp3;
delay_init(); //?óê±oˉêy3?ê??ˉ
NVIC_Configuration(); //éè??NVIC?D??·?×é2:2???à??ó??è??£?2???ìó|ó??è??
uart_init(9600); //′??ú3?ê??ˉ?a9600
LED_Init(); //LED???ú3?ê??ˉ
LCD_Init();
Adc_Init(); //ADC3?ê??ˉ
POINT_COLOR=RED;//éè??×?ì??aoìé?
LCD_ShowString(60,70,200,16,16,"ADC TEST");
LCD_ShowString(60,90,200,16,16,"2017/3/2");
POINT_COLOR=BLUE;
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,"ADC_CH0_VAL:");
LCD_ShowString(60,190,200,16,16,"ADC_CH0_VOL:0.000V");
LCD_ShowString(60,210,200,16,16,"ADC_CH0_VAL:");
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_1,10);
adcx2=adcx;
LCD_ShowxNum(156,130,adcx,4,16,0);
temp=(float)adcx*(3.3/4096);
adcx=temp;
LCD_ShowxNum(156,150,adcx,1,16,0);//
temp-=adcx;
temp*=1000;
LCD_ShowxNum(172,150,temp,3,16,0X80);
adcx1=Get_Adc_Average(ADC_Channel_2,10);
adcx3=adcx1;
LCD_ShowxNum(156,170,adcx1,4,16,0);//
temp1=(float)adcx1*(3.3/4096);
adcx1=temp1;
LCD_ShowxNum(156,190,adcx1,1,16,0);//
temp1-=adcx1;
temp1*=1000;
LCD_ShowxNum(172,190,temp1,3,16,0X80);
temp2=(adcx2-adcx3)/(adcx2+adcx3)*2;
adc4=temp2;
LCD_ShowxNum(156,210,adc4,4,16,0);
LED0=!LED0;
delay_ms(250);
}
}
主要是最后一行的temp2 为什么不能把它赋值给adc4 然后在lcd上显示 ,其他的都没毛病 ,就在这里,不好使,求教为什么。 这个是adc采集的 我把adcx和adcx1这两个采集的数进行了一下子运算,想把它在lcd上显示 ,可是不好使,呜呜呜 ,求大神指点,万分感谢!
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "adc.h"
int main(void)
{
u16 adcx,adcx1,adcx2,adcx3,adc4;
float temp,temp1,temp2,temp3;
delay_init(); //?óê±oˉêy3?ê??ˉ
NVIC_Configuration(); //éè??NVIC?D??·?×é2:2???à??ó??è??£?2???ìó|ó??è??
uart_init(9600); //′??ú3?ê??ˉ?a9600
LED_Init(); //LED???ú3?ê??ˉ
LCD_Init();
Adc_Init(); //ADC3?ê??ˉ
POINT_COLOR=RED;//éè??×?ì??aoìé?
LCD_ShowString(60,70,200,16,16,"ADC TEST");
LCD_ShowString(60,90,200,16,16,"2017/3/2");
POINT_COLOR=BLUE;
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,"ADC_CH0_VAL:");
LCD_ShowString(60,190,200,16,16,"ADC_CH0_VOL:0.000V");
LCD_ShowString(60,210,200,16,16,"ADC_CH0_VAL:");
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_1,10);
adcx2=adcx;
LCD_ShowxNum(156,130,adcx,4,16,0);
temp=(float)adcx*(3.3/4096);
adcx=temp;
LCD_ShowxNum(156,150,adcx,1,16,0);//
temp-=adcx;
temp*=1000;
LCD_ShowxNum(172,150,temp,3,16,0X80);
adcx1=Get_Adc_Average(ADC_Channel_2,10);
adcx3=adcx1;
LCD_ShowxNum(156,170,adcx1,4,16,0);//
temp1=(float)adcx1*(3.3/4096);
adcx1=temp1;
LCD_ShowxNum(156,190,adcx1,1,16,0);//
temp1-=adcx1;
temp1*=1000;
LCD_ShowxNum(172,190,temp1,3,16,0X80);
temp2=(adcx2-adcx3)/(adcx2+adcx3)*2;
adc4=temp2;
LCD_ShowxNum(156,210,adc4,4,16,0);
LED0=!LED0;
delay_ms(250);
}
}
主要是最后一行的temp2 为什么不能把它赋值给adc4 然后在lcd上显示 ,其他的都没毛病 ,就在这里,不好使,求教为什么。 这个是adc采集的 我把adcx和adcx1这两个采集的数进行了一下子运算,想把它在lcd上显示 ,可是不好使,呜呜呜 ,求大神指点,万分感谢!
你说的这个“不能”具体是什么情况?是不能显示还是显示的数据不对?
你的temp2的计算式应该是错的,* 和 / 是同一级的,你这个式子计算过程是:前面括号的除以后面括号的,结果再乘以2,这应该不是你想要的结果。