我用的夏普的红外传感器测一下距离,,adc转化模块是按照原子哥教程写的,就是mian里面用了if判断输出距离,,,显示屏不现实距离
下面是mian函数
int main(void)
{
float temp;
u16 adcx;
Adc_Init();
SystemInit();
OLED_Init();
LCD_Print(15, 0, "GUYOUJIE",TYPE16X16,TYPE8X16);
LCD_Print(15, 16, "DISTANCE",TYPE16X16,TYPE8X16);
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_1,10);
temp=(float)adcx*(3.3/4096);
if (temp>0.38&&temp<0.45)
{
LCD_Print(16, 32, "80cm",TYPE16X16,TYPE6X8);
}
else if (temp>0.45&&temp<0.65)
{
LCD_Print(16, 32, "50cm",TYPE16X16,TYPE6X8);
}
else if (temp>0.65&&temp<0.80)
{
LCD_Print(16, 32, "40cm",TYPE16X16,TYPE6X8);
}
else if (temp>0.80&&temp<1.05)
{
LCD_Print(16, 32, "30cm",TYPE16X16,TYPE6X8);
}
else if (temp>1.05&&temp<1.25)
{
LCD_Print(16, 32, "25cm",TYPE16X16,TYPE6X8);
}
else if (temp>1.25&&temp<1.50)
{
LCD_Print(16, 32, "20cm",TYPE16X16,TYPE6X8);
}
else if (temp>1.50&&temp<1.95)
{
LCD_Print(16, 32, "15cm",TYPE16X16,TYPE6X8);
}
else if (temp>1.95&&temp<2.50)
{
LCD_Print(16, 32, "10cm",TYPE16X16,TYPE6X8);
}
else if (temp>2.50&&temp<2.95)
{
LCD_Print(16, 32, "8cm",TYPE16X16,TYPE6X8);
}
else if (temp>2.95&&temp<3.05)
{
LCD_Print(16, 32, "7cm",TYPE16X16,TYPE6X8);
}
else if (temp>3.05&&temp<3.15)
{
LCD_Print(16, 32, "5cm",TYPE16X16,TYPE6X8);
}
else if (temp>3.15&&temp<3.3)
{
LCD_Print(16, 32, "6cm",TYPE16X16,TYPE6X8);
}
}
}
求教大家为什么不可以显示啊 ,
|