#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.zg4o1577.cn/bbs/) | Powered by Discuz! X3.1 |