float phaseA,phaseB,phaseC;
#define pa RB4_bit
#define pb RB1_bit
#define pc RB0_bit
#define role RB3_bit
#define phase 311.23
void main() {
C1INV_bit=0;
C2INV_bit=0;
TRISB=0;
pa=0;
pb=0;
pc=0;
role=0;
ADC_Init();
while(1)
{
phaseA=(ADC_Read(5)*5.0/1023)*101;
phaseB=(ADC_Read(1)*5.0/1023)*101;
phaseC=(ADC_Read(4)*5.0/1023)*101;
if(phaseA>1.1*phase||phaseB>1.1*phase||phaseC>1.1*phase||phaseA<0.9*phase||phaseB<0.9*phase||phaseC<0.9*phase)
{
delay_ms(2);
if(phaseA>1.1*phase||phaseB>1.1*phase||phaseC>1.1*phase||phaseA<0.9*phase||phaseB<0.9*phase||phaseC<0.9*phase)
{
role=1;
if(phaseA>1.1*phase)
{
pa=1;
}
else
{
pa=0;
}
if(phaseB>1.1*phase||phaseB<0.9*phase)
{
pb=1;
}
else
{
pb=0;
}
if(phaseC>1.1*phase||phaseC<0.9*phase)
{
pc=1;
}
else
{
pc=0;
}
}
else
{
role=0;
}
}
}
}