Circuit Schimatic Diagram
Circuit Schimatic Diagram
jpg
int powerFactor()
int a=0,b=0,t=0,x=0;
float tm,pf;
TMR1L=0;
TMR1H=0;
do
if(PORTA.F0 == 1)
T1CON.F0 = 1;
else if(PORTA.F0 == 0 && T1CON.F0 == 1)
T1CON.F0 = 0;
break;
}while(1);
a = (TMR1L | (TMR1H<<8)) * 2;
TMR1L=0;
TMR1H=0;
do
if(PORTA.F0 == 1)
T1CON.F0=1;
if(PORTA.F1==1)
T1CON.F0=0;
break;
}while(1);
b = TMR1L | (TMR1H<<8);
tm = (float)b/a;
pf = cos(tm*2*3.14);
x=abs(ceil(pf*100));
return x;
void main()
char c[]="0.00";
int a,b,d,x,f,e;
float tm,pf;
Lcd_Init();
while(1)
a = powerFactor();
Delay_us(50);
b = powerFactor();
Delay_us(50);
d = powerFactor();
Delay_us(50);
e = powerFactor();
Delay_us(50);
f = powerFactor();
x = (a+b+d+f+e)/5;
c[3]=x%10 + 0x30;
x=x/10;
c[2]=x%10 + 0x30;
x=x/10;
c[0]=x%10 + 0x30;
Lcd_Out(1,1,"Power Factor");
Lcd_Out(2,1,c);
if(x<90)
PORTD.F0 = 1;
PORTD.F0 = 1;
Delay_ms(2000);
else
{
PORTD.F0 = 0;
PORTD.F0 = 0;
Delay_ms(250);