unsigned char FlagReg;
int x;
int i;
int maal;
int dimming=128;
sbit ZC at FlagReg.B0;
void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
INTCON.INTF = 0;
}
}
void delay(int maal){
for (x=1; x< maal; x++) {
delay_us(75);
}
}
void main() {
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTA = 0;
ADCON1 = 7; //Disable ADC
TRISA = 0xFF; //Make all PORTA inputs
PORTC = 0;
TRISC = 0; //PORTC all output
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)
{
for (i=5; i<= 128; i++){
if(ZC){
dimming=i;
vdelay_ms(dimming);
PORTC.B0=1;
delay_us(250);
PORTC.B0=0;
ZC=0;
delay_ms(10);
}
}
} }