|
stc12c5a60s2 甲醛程序
void main()
{
timer0();
init_uart0(); //初始化串口功能
LCD_Init(); //初始化液晶
DelayMs(50); //延时有助于稳定
LCD_Clear(); //清屏
DelayUs2x(10);
Uart0SendString("01",2); //发送数据
buzzer = 0;DelayMs(50); buzzer = 1;
while (1)
{
if(disFlag == 1) //更新显示
{
disFlag = 0 ;//显示标志
sprintf(dis0,"nowV: %05.1fv ",voltA); //打印 );//打印
LCD_Write_String(0,0,dis0);
jiaQuan = pow (10,((-2.631+1.528*voltA+(-0.125)*voltA*voltA)));//该计算公式从手册中来Log(ppm) = (-2.631) + 1.528 * (Vout) + (0.125) * (Vout)*(Vout)2
sprintf(dis1,"JQ:%4.1fppm ",jiaQuan);//显示甲醛大小
LCD_Write_String(0,1,(unsigned char *)dis1);
if(jiaQuan>=2)//浓度过高
{buzzer = !buzzer;}
else
{buzzer = 1;}
uNum++;
if(uNum>=4)//延时计数到
{
uNum = 0; //重新计数
Uart0SendString(dis0,16); //发送数据
DelayMs(5);
Uart0SendString("\r\n",2); //发送数据
DelayMs(5);
Uart0SendString(dis1,16); //发送数据
DelayMs(5);
Uart0SendString("\r\n",2); //发送数据
}
}
if(readADflag == 1) //读取ad标志 定时器中置1
{
InitADC(0); //读取电压
readADflag=0; //清除标志
}
}
}
|
|