不到十行的程序,就是没法实现功能

2019-07-15 19:52发布

#include<reg51.h>//库文件
#define uchar unsigned char//宏定义无符号字符型
#define uint unsigned int //宏定义无符号整型
sbit LED=P1^0;// (即P1.0)为指示端

sbit DOUT=P2^0;// (即P2.0)为传感器的输入端
void delay_50ms(int t)
{
        int j;
        for(;t>0;t--)
            for(j=6245;j>0;j--);
}
/********************************************************************
主函数
*********************************************************************/
void main()
{
   while(1) //无限循环
{
   LED=1;//熄灭P1.0口灯
   if(DOUT==0)//当浓度高于设定值时 ,执行条件函数
     {
        delay_50ms(20);//延时抗干扰
          if(DOUT==0)//确定 浓度高于设定值时 ,执行条件函数
            {
                LED=0;//点亮P1.0口灯
                        }
                  else
                  {
                         LED=1;
                    }
            }
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
7条回答
767763503
2019-07-16 04:07
你的应该是煤气传感器的程序吧
#include<reg52.h>
sbit DOUT=P2^7;       
sbit AOUT=P2^6;
sbit Beep =  P1^4 ;
void delay(unsigned int i)
{
    char j;
    for(i; i > 0; i--)
        for(j = 200; j > 0; j--);
}
void main()
{
        while(1)
        {
            if(DOUT==0)
                        {
                                 Beep= 1;
                                 delay(5);
                                 Beep= 0;
                                 delay(5);
                     }
        }
}
你试试吧  不是LED是蜂鸣器的

一周热门 更多>