標(biāo)題: 多按鍵控制繼電器如何修改單片機(jī)程序(已經(jīng)實(shí)現(xiàn)了單按鍵控制) [打印本頁(yè)]

作者: 林森    時(shí)間: 2018-12-22 18:14
標(biāo)題: 多按鍵控制繼電器如何修改單片機(jī)程序(已經(jīng)實(shí)現(xiàn)了單按鍵控制)
現(xiàn)在已經(jīng)實(shí)現(xiàn)了一個(gè)按鍵控制一個(gè)一個(gè)繼電器啟動(dòng)5s了,想多加幾個(gè)按鍵同時(shí)控制一個(gè)繼電器,怎么改動(dòng)呢

#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit key =P1^0;
sbit relay =P1^2;
uint count;//
void init()//
{
        TMOD=0x01;
TH0=0xD8;
TL0 = 0xF0;//10ms*100=1s
TR0=1;
ET0=1;
EA=1;

}
void main()
{
init();
        while(1)
        {
        if (key==0);
        {
        TR0=1;
        while(!key);
        }
        }
}
void timer0() interrupt 1
{
        TH0=0xD8;
  TL0 = 0xF0;
        count++;
        if(count ==100)
        {
        relay =0;
        }
        if(count == 500)
        {
        relay =1;
                count = 0;
                TR0 = 0;
        }
        if(relay ==1 && key==1)
        {
        
                count=0;
                TR0 = 0;
               
        }
}


作者: ssk7793    時(shí)間: 2018-12-22 20:02
同理,在if處加入按鍵判斷
作者: 夢(mèng)園心田    時(shí)間: 2018-12-23 22:46
在if中把按鍵條件與上去如(...&&key1==&&key2==0...)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1