#include<reg52.h>
#include<intrins.h>
#define data P2
#define uint unsigned int
void delay10ms(void);
void delay500ms(void);
void found(void);
void initEx0(void);
sbit start_signal = P1^2;
sbit stop_singal = P1^3;
sbit up_to_down = P1^4;
sbit down_to_up = P1^5;
sbit inter_signal = P3^2;
uint fp = 1;
int main()
{
initEx0();
while(1)
{
if(!(start_signal && stop_singal && up_to_down && down_to_up))
{
delay10ms();
if(!(start_signal && stop_singal && up_to_down && down_to_up))
{
inter_signal = 0;
}
}
switch(fp)
{
case 0:data = 0x01;delay500ms();while(1){data = _crol_(data,1);delay500ms();if(!(start_signal && stop_singal && up_to_down && down_to_up))break;}break;
case 1:data = 0x00;break;
case 2:while(1){data = data = _crol_(data,1);delay500ms();if(!(start_signal && stop_singal && up_to_down && down_to_up))break;}break;
case 3:while(1){data = data = _cror_(data,1);delay500ms();if(!(start_signal && stop_singal && up_to_down && down_to_up))break;}break;
default:data = 0x00;break;
}
}
return 0;
}
void delay10ms(void)
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
void delay500ms(void)
{
unsigned char a,b,c;
for(c=23;c>0;c--)
for(b=152;b>0;b--)
for(a=70;a>0;a--);
}
void found(void)
{
if(start_signal == 0)
{
delay10ms();
if(start_signal == 0)
{
while(!start_signal);
fp = 0;
}
}
if(stop_singal == 0)
{
delay10ms();
if(stop_singal == 0)
{
while(!stop_singal);
fp = 1;
}
}
if(up_to_down == 0)
{
delay10ms();
if(up_to_down == 0)
{
while(!up_to_down);
fp = 2;
}
}
if(down_to_up == 0)
{
delay10ms();
if(down_to_up == 0)
{
while(!down_to_up);
fp = 3;
}
}
while(!(start_signal && stop_singal && up_to_down && down_to_up));
}
void initEx0()
{
EA = 1;
EX0 = 1;
IT0 = 1;
}
void Ex0_intr() interrupt 0
{
found();
inter_signal = 1;
}