unsigned char FlagReg;
sbit ZC at FlagReg.B0;
int angle,v1;
unsigned int v;
void interrupt(){
if (INTCON.INTF){
ZC = 1;
INTCON.INTF = 0;
}
}
void main() {
PORTB = 0;
PORTC=0;
TRISB = 0x01; //RB0 input for interrupt
TRISA=0x01; //Input for potentiometer
TRISC.b6=0; //Output for driving the TRIAC
TRISC.B0=0;
OPTION_REG.INTEDG =0; //interrupt on falling edge
INTCON.INTF = 0; //clear interrupt flag
INTCON.INTE = 1; //enable external interrupt
INTCON.GIE = 1; //enable global interrupt
while (1){
if (ZC){ //zero crossing occurred
PORTC.B6 = 1; //Send a 8ms pulse
delay_ms(1);
PORTC.B6 = 0;
ZC = 0;
}
PORTC.B0=1 ; //Turn on LED on RC0
delay_ms(1500);
PORTC.B0=0; //Turn off LED on RC0
Delay_ms(1000);
}
}