小型SDI 2x1切换开关

采用STC15F104E作为核心控制器件。
注:若用于商业用途,请提前联系。否则可能会引起法律问题。

#include
   
   
    
    
#include
    
    
     
     

#define SEL0_LED	P30
#define SEL1_LED	P31
#define SEL0_SW		P32
#define SEL1_SW 	P33
#define RELAY0		P34

unsigned char Curr_Sel = 255;

void Inp_Sel(unsigned char i)	// 该函数结构,为多输入切换预留
{
	if(i != Curr_Sel)
	{
		switch(i)
		{
			case 0:	Curr_Sel = 0; SEL0_LED = 1; SEL1_LED = 0; RELAY0 = 1; break;
			case 1: Curr_Sel = 1; SEL0_LED = 0; SEL1_LED = 1; RELAY0 = 0; break;
			default: break;
		}
	}
}

void Delay100ms()		//@6.000MHz
{
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 3;
	j = 72;
	k = 161;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void main()
{
	unsigned char keyport;

	P33 = 1;
	P3M0 = 0x13;
	P3M1 = 0x10;
	Inp_Sel(0);
	while(1)
	{
		keyport = P3 & 0x0c;
		if(keyport != 0x0c)
		{
			Delay100ms();
			if(keyport == (P3 & 0x0c))
			{
				switch(keyport)
				{
					case 0x08: Inp_Sel(0); break;
					case 0x04: Inp_Sel(1); break;
				}
				while((keyport & 0x0c) == 0x0c);
			}
		}
	}
}

    
    
   
   

头文件:
//包含本头文件后,不用另外再包含"REG51.H"

//内核特殊功能寄存器        // 复位值   描述
sfr ACC         =   0xE0;   //0000,0000 累加器Accumulator
sfr B           =   0xF0;   //0000,0000 B寄存器
sfr PSW         =   0xD0;   //0000,0000 程序状态字
sbit CY         =   PSW^7;
sbit AC         =   PSW^6;
sbit F0         =   PSW^5;
sbit RS1        =   PSW^4;
sbit RS0        =   PSW^3;
sbit OV         =   PSW^2;
sbit P          =   PSW^0;
sfr SP          =   0x81;   //0000,0111 堆栈指针
sfr DPL         =   0x82;   //0000,0000 数据指针低字节
sfr DPH         =   0x83;   //0000,0000 数据指针高字节

//I/O 口特殊功能寄存器
sfr P0     

你可能感兴趣的:(小型SDI 2x1切换开关)