本文经过单片机进行12通道解码。
原理图
PCB
内部结构
面板:赤色指示灯为巡检指示灯,绿色指示灯为通道作业指示灯。
程序代码:
#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; //发动看门狗
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号键
case 0x2f:bzw1=1;break;//out1 2号键
case 0x3f:bzw2=1;break;//out2 3号键
case 0x4f:bzw3=1;break;//out3 4号键
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++)
{;}}
}