标题: 火焰传感器单片机c代码 [打印本页]

作者: intersting    时间: 2018-12-19 21:06
标题: 火焰传感器单片机c代码
#include<reg52.h>
#include <intrins.h>
void led();
sbit out=P2^3;//定义火焰传感器DO输出引脚
//sbit led=P2^4;
void delay(int x)
{
        int i,j;
        for(i=0;i<x;i++)
                for(j=0;j<110;j++);
}
void led()
{
        unsigned char LED;
        LED = 0xfe;          //0xfe = 1111 1110
         while(1)
        {
                     P1 = LED;
               delay(250);
                LED = LED << 1;    //循环右移1位,点亮下一个LED "<<"为左移位
                if(P2 == 0x00 )        
                          {
                                  LED = 0xfe;
                           } // 0xfe = 1111 1110                                    
        }
}
int main()
{
        while(1)
        {         
             if(out==0)//如果检测到火焰并且小于设定的值,火焰传感器返回一个0低电平,注意当模块接通电源时DO脚是1高电平。
             {
                      led();//调用跑马灯led
             }
}}




作者: admin    时间: 2018-12-20 02:31
补全原理图或者详细说明一下电路连接即可获得100+黑币




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1