《单片机控制二氧化碳传感器程序(5页).doc》由会员分享,可在线阅读,更多相关《单片机控制二氧化碳传感器程序(5页).doc(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-第 1 页单片机控制二氧化碳传感器程序-第 2 页#include/头文件#include#define uchar unsigned char/宏定义无符号字符型#define uintunsignedint/宏定义无符号整型typedef unsigned char BYTE;typedef bit BOOL;sbit ST=P30;/A/D 启动转换信号sbit OE=P31;/数据输出允许信号sbit EOC=P32;/A/D 转换结束信号sbit CLK=P33;/时钟脉冲sbit LCD_RS=P20;sbit LCD_RW=P21;sbit LCD_EN=P22;uchar m
2、;uintAD0809,i,cdisplay,ppm;uint ppmdou;/定义数据类型void delay(int ms)/延时子程序while(ms-)for(i=0;i1072)ppm=400;else if(1049cdisplay)&(cdisplay=1072)ppmdou=(500-(cdisplay-1049)*(100/(1072-1049);ppm=(uint)ppmdou;elseif(1036cdisplay)&(cdisplay=1049)ppmdou=(600-(cdisplay-1036)*(100/(1049-1036);/ppmdou=(500-(ppmd
3、-1049)*(100/(1072-1049);ppm=(uint)ppmdou;else if(1023cdisplay)&(cdisplay=1036)ppmdou=(700-(cdisplay-1023)*(100/(1036-1023);ppm=(uint)ppmdou;else if(1016cdisplay)&(cdisplay=1023)ppmdou=(800-(cdisplay-1016)*(100/(1023-1016);ppm=(uint)ppmdou;else if(1006cdisplay)&(cdisplay=1016)ppmdou=(900-(cdisplay-10
4、06)*(100/(1016-1006);ppm=(uint)ppmdou;elseif(1000cdisplay)&(cdisplay=1006)-第 5 页ppmdou=(1000-(cdisplay-1000)*(100/(1016-1000);ppm=(uint)ppmdou;else if(966cdisplay)&(cdisplay=1000)ppmdou=(2000-(cdisplay-966)*(1000/(1000-966);ppm=(uint)ppmdou;else if(947cdisplay)&(cdisplay=966)/2000-3000ppmdou=(3000-(
5、cdisplay-947)*(1000/(966-947);ppm=(uint)ppmdou;else if(924cdisplay)&(cdisplay=947)/3000-4000ppmdou=(4000-(cdisplay-924)*(1000/(947-924);ppm=(uint)ppmdou;else if(907cdisplay)&(cdisplay=924)/4000-6000ppmdou=(6000-(cdisplay-907)*(2000/(924-907);ppm=(uint)ppmdou;else if(891cdisplay)&(cdisplay=907)/6000-
6、8000ppmdou=(8000-(cdisplay-891)*(2000/(907-891);ppm=(uint)ppmdou;else if(874cdisplay)&(cdisplay=891)/8000-10000ppmdou=(10000-(cdisplay-874)*(2000/(891-874);ppm=(uint)ppmdou;else if(0cdisplay)&(cdisplay=874)/8000-10000ppm=10000;lcd_pos(0 x81);lcd_wdat(ppm/10000+0 x30);lcd_pos(0 x82);lcd_wdat(ppm%10000)/1000+0 x30);lcd_pos(0 x83);lcd_wdat(ppm%1000)/100+0 x30);lcd_pos(0 x84);lcd_wdat(ppm%100)/10+0 x30);lcd_pos(0 x85);lcd_wdat(ppm%10+0 x30);lcd_pos(0 x86);lcd_wdat(p);lcd_pos(0 x87);lcd_wdat(p);lcd_pos(0 x88);lcd_wdat(m);