Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
For that, you need to fire the triac at a specific time after the zero-cross.
#include <mega8535.h>
#include <delay.h>
interrupt [EXT_INT0] void ext_int0_isr(void)
{
PORTD=0x02; // Output delay
delay_ms(2);
PORTD=0x00;
}
void main(void)
{
DDRD=0x02; // PORTD pin1 as output
DDRB=0x01; // PORTB pin0 as TRIAC input (MCU output)
GICR|=0x40; // Interrupt at PORTD pin2
MCUCR=0x01;
MCUCSR=0x00;
GIFR=0x40;
#asm("sei")
PORTB = 0X01; // initially triacs off
while(1)
{
while(PORTD.2 == 1) // zero crossing detected
{
PORTB = 0x01;
delay_us(500);
PORTB =0x00;
}
while(PORTD.2 == 0) // half cycle of ac reached
{
PORTB = 0x01;
delay_us(500);
PORTB = 0x00;
}
}
}