Created
February 20, 2018 07:20
-
-
Save sosnovskyas/1c2675abd63635a9742b6e3cb285cd87 to your computer and use it in GitHub Desktop.
tiny10: Fade PB0 and PB1 up and down using PWM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
int main(void) | |
{ | |
int i; | |
// PB0 and PB1 outputs | |
DDRB = (1<<PB0) | (1<<PB1); | |
// Timer0 in mode 14, fast PWM with ICR0 as top. | |
// Enable OC0A and OC0B, lower mode bits | |
TCCR0A = (1<<COM0A1) | (1<<COM0B1) | (1<<WGM01); | |
// Set top to 1000 | |
ICR0 = 1000; | |
// Start timer with prescaler 1:8 and set upper mode bits | |
TCCR0B = (1<<CS01) | (1<<WGM03) | (1<<WGM02); | |
while(1) | |
{ | |
for (i = 0; i <= 1000; i++) | |
{ | |
OCR0A = i; | |
OCR0B = 1000-i; | |
_delay_ms(1); | |
} | |
for (i = 1000; i >= 0; i--) | |
{ | |
OCR0A = i; | |
OCR0B = 1000-i; | |
_delay_ms(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment