#include<AT89X51.H>
#include<stdio.h>
sbit L1=P1^0;
sbit L2=P1^1;
sbit K1=P1^2;
sbit K2=P1^3;
sbit M1=P1^4;
sbit M2=P1^5;
sbit M3=P1^6;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f} ;
unsigned char Count;
unsigned char rebuild(void) //重置人数限数,通过P38位并口输入预置数给j
{unsigned char j;
j=P3;
return(j);
}
unsigned char initial(void) //光控输入信号判断电路产生的信号只有01,10状态
{
if(K1==1)
{
if(K2==0)
return(1);
}
if(K1==0)
{
if(K2==1)
return(0);
}
}
void delay10ms(void)
{
unsigned char i,j,k;
for(i=20;i>0;i--)
{for(j=20;j>0;j--)
{for(k=248;k>0;k--);
}
}
}
void main(void)
{
Count=0;
P0=table[Count/10];
P2=table[Count%10];
while(1)
{
if(L1==1)
{delay10ms();
if(L2==1)
Count++;
if(Count<=rebuild())
{if(initial()==1)
{
M1=1;
M2=0;
M3=0;
}
else
{
M1=0;
M2=0;
M3=0;
}
}
if(Count<=2*rebuild())
{if(initial()==1)
{
M1=1;
M2=1;
M3=0;
}
else
{
M1=0;
M2=0;
M3=0;
}
}
if(Count>2*rebuild())
{if(initial()==1)
{
M1=1;
M2=1;
M3=1;
}
else
{
M1=0;
M2=0;
M3=0;
}
}
}
if(L2==1)
{delay10ms();
if(L1==1)
Count--;
if(Count<=rebuild())
{if(initial()==1)
{
M1=1;
M2=0;
M3=0;
}
else
{
M1=0;
M2=0;
M3=0;
}
}
if(Count<=2*rebuild())
{if(initial()==1)
{
M1=1;
M2=1;
M3=0;
}
else
{
M1=0;
M2=0;
M3=0;
}
}
if(Count>2*rebuild())
{if(initial()==1)
{
M1=1;
M2=1;
M3=1;
}
else
{
M1=0;
M2=0;
M3=0;
}
}
}
P0=table[Count/10];
P2=table[Count%10];
}
}
我建议你还是用红外接收头来做,这个光敏不好掌握
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |