1.功能
2.程序
#include <REGX51.H>
#define uint unsigned int
#define uchar unsigned char
sbit LED1=P2^0;
sbit LED2=P2^1;
sbit S1=P1^0;
sbit S2=P1^1;
sbit S3=P1^2;
sbit S4=P1^3;
void delay(uint MS);
void lock_on(void);
void lock_off(void);
void main(void)
{
while(1)
{
if(S1==0)
{
delay(10);
if(S1==0)
{
lock_off();
}
}
if(S2==0)
{
delay(10);
if(S2==0)
{
lock_on();
}
}
if(S3==0)
{
delay(10);
if(S3==0)
{
lock_off();
}
}
if(S4==0)
{
delay(10);
if(S4==0)
{
lock_off();
}
}
}
}
void lock_on(void)
{
LED1=1;
LED2=0;
}
void lock_off(void)
{
LED1=1;
LED2=0;
}
void delay(uint MS)
{
uint i,j;
for(i=0;i<MS;i++)
for(j=0;j<125;j++)
;
}
3.原理图