用51單片機(jī)解碼的12通道315M遙控器DIY
本文通過單片機(jī)進(jìn)行12通道解碼。
本文引用地址:http://www.ex-cimer.com/article/201808/384844.htm原理圖
PCB
內(nèi)部結(jié)構(gòu)
面板:紅色指示燈為巡檢指示燈,綠色指示燈為通道工作指示燈。
程序代碼:
#include
sfr WDT_CONTR=0xe1;//看門狗初始化
#define uchar unsigned char
#define uint unsigned int
#define uint unsigned int
sbit run=P3^7;
sbit out=P3^2;
sbit out1=P3^3;
sbit out2=P3^4;
sbit out3=P3^5;
bit bzw;
bit bzw1;
bit bzw2;
bit bzw3;
void jsdb();
void shuchu();
void delay(uint k);
/*********************************************************/
void main()
{
P1=0xff;
out=1;
out1=1;
out2=1;
out3=1;
WDT_CONTR=0x35; //啟動(dòng)看門狗
while(1)
{
run=1;
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
run=0;
delay(200);
jsdb();
shuchu();
WDT_CONTR=0x35;
}
}
/********************************************************/
void jsdb()
{
switch(P1)
{
case 0x1f:bzw=1;break;//out 1號(hào)鍵
case 0x2f:bzw1=1;break;//out1 2號(hào)鍵
case 0x3f:bzw2=1;break;//out2 3號(hào)鍵
case 0x4f:bzw3=1;break;//out3 4號(hào)鍵
default:{bzw=0;bzw1=0;bzw2=0;bzw3=0;}break;
}
}
void shuchu()
{
if(bzw)
{
delay(100);
out=~out;
run=1;
delay(500);
run=0;
delay(500);
run=0;
delay(500);
bzw=0;
}
if(bzw1)
{
delay(100);
out1=~out1;
run=1;
delay(500);
run=0;
delay(500);
run=1;
delay(500);
bzw1=0;
}
if(bzw2)
{
delay(100);
out2=~out2;
run=1;
delay(500);
run=0;
delay(500);
run=1;
delay(500);
bzw2=0;
}
if(bzw3)
{
delay(100);
out3=~out3;
run=1;
delay(500);
run=0;
delay(500);
run=1;
delay(500);
bzw3=0;
}
}
void delay(uint k)
{
uint i,j;
for(i=0;i {
for(j=0;j121;j++)
{;}}
}
評(píng)論