|
本帖最后由 dragon19790000 于 2017-4-14 20:02 編輯
12c2052AD 最小系統(tǒng)和PT2272 4通道遙控模塊
只能按 K1、K2、K3、K4的順序開(kāi),關(guān)的時(shí)候,也只能按照 K1、K2、K3、K4的順序關(guān),不能隨意開(kāi)啟和關(guān)閉
求助大神指導(dǎo)!!!
原理圖
源代碼如下:
#include <STC12C2052AD.H>
#define uchar unsigned char
#define uint unsigned int
sbit LED1=P1^0; //定義LED端口
sbit LED2=P1^1; //定義LED端口
sbit LED3=P1^2; //定義LED端口
sbit LED4=P1^3; //定義LED端口
sbit key1=P3^5; //按鍵接口定義
sbit key2=P3^4; //按鍵接口定義
sbit key3=P3^3; //按鍵接口定義
sbit key4=P3^2; //按鍵接口定義
void Delay_xms(uint x) //xms延時(shí)函數(shù)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<122;j++);
}
void main(void) //主函數(shù)
{
while(1)
{
if(key1 == 0)
{
Delay_xms(10);
if(key1 == 0)
LED1 = ~LED1;
while(!key1);
}
if(key2 == 0)
{
Delay_xms(10);
if(key2 == 0)
LED2 = ~LED2;
while(!key2);
}
if(key3 == 0)
{
Delay_xms(10);
if(key3 == 0)
LED3 = ~LED3;
while(!key3);
}
if(key4 == 0)
{
Delay_xms(10);
if(key4 == 0)
LED4 = ~LED4;
while(!key4);
}
}
}
|
|