int main(void){
DDRB=0x00;
PORTB=0xFF;
int i;
PORTD=0x00;
DDRD=(1<<LED)|(1<<LED2);
SFIOR |=(1<<PSR2);
TCCR2 |=(1<<WGM20)|(1<<COM21)|(1<<WGM21)|(1<<CS21);// Mode 4 set OC2 at BOTTOM
sei();
while(1){
if(PINB2==0){ //BUTTON chân PB2 ; xuất ra chân PORTD
PORTD=0x00;
}else {PORTD=0x40;}
for(i=0;i<=255;i++){
pwm_write(i);
_delay_ms(1);
}
for(i=255;i>=0;i--){
pwm_write(i);
_delay_ms(1);
}
}
return 0;
}
DDRB=0x00;
PORTB=0xFF;
int i;
PORTD=0x00;
DDRD=(1<<LED)|(1<<LED2);
SFIOR |=(1<<PSR2);
TCCR2 |=(1<<WGM20)|(1<<COM21)|(1<<WGM21)|(1<<CS21);// Mode 4 set OC2 at BOTTOM
sei();
while(1){
if(PINB2==0){ //BUTTON chân PB2 ; xuất ra chân PORTD
PORTD=0x00;
}else {PORTD=0x40;}
for(i=0;i<=255;i++){
pwm_write(i);
_delay_ms(1);
}
for(i=255;i>=0;i--){
pwm_write(i);
_delay_ms(1);
}
}
return 0;
}