while (1)
{
if (((PC_IDR&0x08)==0x00)&&(flag_stop==0))//stop signal from Hall1
{
flag_stop=1;
flag_start=0;
TIM2_CR1=0x00;//close TIME2
PB_ODR&=0xcf;//turn off LED
PD_ODR|=0x0c;//send start signal to master and open the buzzer
Delay(50);
for (i=0;i<4;i++)//send time to master
{
PD_ODR=0x08&((s/10)<<i);//4bit
Delay(50);
}
for (i=0;i<4;i++)//send time to master
{
PD_ODR=0x08&((s%10)<<i);//4bit
Delay(50);
}
PD_ODR&=0x00;//reset PD
Delay(1000);
PD_ODR|=0x20;//send control K1 to master
}
if (((PC_IDR&0x10)==0x00)&&(flag_stop==0))//stop signal from Hall2
{
flag_stop=1;
flag_start=0;
TIM2_CR1=0x00;//close TIME2
PB_ODR&=0xcf;//turn off LED
PD_ODR|=0x0c;//send start signal to master and open the buzzern
Delay(50);
for (i=0;i<4;i++)//send time to master
{
PD_ODR=0x08&((s/10)<<i);//4bit
Delay(50);
}
for (i=0;i<4;i++)//send time to master
{
PD_ODR=0x08&((s%10)<<i);//4bit
Delay(50);
}
PD_ODR&=0x00;//reset PD
Delay(1000);
PD_ODR|=0x40;//send control K2 to master
}
if ((((PC_IDR&0x08)==0x08)||((PC_IDR&0x10)==0x10))&&(flag_start==0))//start signal form Hall1 or Hall2
{
flag_stop=0;
flag_start=1;
PD_ODR&=0xf7;//reset PD3
s=0;//reset second
TIM2_CR1=0x01;//open TIME2
/**
if (s>=60)
{
s=0;
TIM2_CR1=0x00;//close TIME2
PB_ODR|=0x30;//turn on LED
PD_ODR|=0x08;//send stop signal to master
Delay(450);
}
**/
}
}