51单片机血糖值AD转换
根据如图怎么编写AD转换公式呀?,yun是连接的是运算放大电路的电压,放大了100倍
现在是要通过输入的电压转换成血糖值,公式是:血糖值=0.45电流值+2.2,电流与电压的关系是V=IR,R设置的是1k。
血糖值正常范围在4.5mmol/l到11.2mol/l
血糖值正常情况下电压为0.5到2v
希望帮忙解答,
可以的话加我v695486413
#include<reg52.h>
#include<math.h>
#include<absacc.h>
#define uint unsigned int
#define uchar unsigned char
sbit ADC_START=P2^1;
sbit ADC_OE=P2^7;
sbit EOC=P2^5;
sbit LCD_EN=P2^2;
sbit LCD_RS=P2^0;
sbit SPK=P1^0;
unsigned char ADC_DATA=0,dula,wela;
unsigned int Rank_DATA=0,Present=0,VoltaData_Lit=0,VoltaData_Lit_MAX;
//*********延时函数********//
void delay_ms(uint x)//延时1ms
{ uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void write_com(uchar com)//向液晶显示屏LCD1602写命令
{ LCD_RS=0;
P0=com;
delay_ms(50);
LCD_EN=1;
delay_ms(50);
LCD_EN=0;
} //检查没问题
void write_data(uchar date)//向液晶显示屏LCD1602写数据
{ LCD_RS=1;
P0=date;
delay_ms(50);
LCD_EN=1;
delay_ms(50);
LCD_EN=0;
} //检查没问题
//*************液晶显示屏LCD1602初始化*************//
void LCD_init()
{ dula=0;
wela=0; //记得上网查找LCD初始化操作程序
LCD_EN=0;
P1=0Xfe;//不懂
write_com(0X38);//显示模式设置
write_com(0X0e);//打开光标
write_com(0X06);//字符指针加一
write_com(0X01);//清屏显示
write_com(0X80);//字符首地址
}
//**************************************************//
//**函数名称:ADC_handle(void)
//*函数功能:ADC0808的驱动函数 这里跟参考资料不一样
//**************************************************//
void ADC_handle()
{ ADC_START=0;
ADC_START=1;
ADC_START=0;
while(EOC==0);//等待转换完成
ADC_OE=1;
ADC_DATA=P3;//读取转换后的值
ADC_OE=0;
}
//*********************主函数***********************//
void main()
{ uchar i=0;
SPK=0;
LCD_init();
//Initialize();//这个不懂
write_com(0X85);//初始化LCD1602
write_data('W');
write_data('e');
write_data('l');
write_data('c');
write_data('o');
write_data('m');
write_data('e');//液晶屏显示"Welcome"
write_com(0X80+0X40);
write_data('D');
write_data('a');
write_data('t');
write_data('a');
write_data(':');//以上的没问题
while(1)
{ ADC_handle();
Present=(ADC_DATA*100)/5*256;//计算AD转换的数据和电压关系,本系统设计的是5V 放大100倍
//VoltaData_Lit=Present*45;
VoltaData_Lit=VoltaData_Lit*5;
VoltaData_Lit=VoltaData_Lit+2200;
VoltaData_Lit=VoltaData_Lit+250;
VoltaData_Lit=(VoltaData_Lit*50);
VoltaData_Lit=VoltaData_Lit+50; //以上的程序都不懂
VoltaData_Lit=VoltaData_Lit*45/100;
VoltaData_Lit=VoltaData_Lit+2.2;
write_com(0X86+0X40);
write_data((VoltaData_Lit)/10000+0X30);
write_data((VoltaData_Lit%10000)/1000+0X30);
write_data('.');
write_data((VoltaData_Lit%1000)/100+0X30);
write_data((VoltaData_Lit%100)/10+0X30); //这里以上也不懂
write_data('V');
write_data('m');
write_data('m');
write_data('o');
write_data('l');
write_data('/');
write_data('L');//液晶屏显示血糖单位“Vmmol/L"
if(VoltaData_Lit>=11200|VoltaData_Lit<=4500)
{ SPK=1;
write_com(0X85);
write_data('D');
write_data('a');
write_data('n');
write_data('g');
write_data('e');
write_data('r');
write_data('!');//液晶屏显示“Danger!”
}
else
{ SPK=0;//防止一直通电给喇叭造成损坏
write_com(0X85);
write_data('N');
write_data('o');
write_data('m');
write_data('a');
write_data('l');
write_data(' ');
write_data(' ');
}
}
}