專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

繼電器控制

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2010年10月02日   【字體:
_____________________________________________________________________

功能:用杜邦線把繼電器輸入端口和P1^1連接起來,按鍵S1吸合,按鍵S2釋放繼電器

時(shí)間:2010—7—20

_____________________________________________________________________

 

#include<reg52.h>

sbit key1=P3^0;
sbit key2=P3^1;
sbit RELAY = P1^1;

void delay(unsigned int cnt)
{

        while(--cnt);
}


main()
{
        while(1)
        { 
                if(!key1) 
                {
                        delay(5000);
                        if(!key1)    //去抖動后是否按下相應(yīng)按鍵
                        {
                                RELAY=1;    //繼電器吸合
                        }
                }

                if(!key2)
                {
                        delay(5000);
                        if(!key2)    //去抖動后是否按下相應(yīng)按鍵


                        {
                                RELAY=0;    //繼電器釋放
                        }
                }

        }
}
關(guān)閉窗口

相關(guān)文章