Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- // LED på OCR0A
- int main(void)
- {
- TCCR0A = (1 << COM0A1) | (0 << COM0A0)
- | (0 << COM0B1) | (0 << COM0B0)
- | (1 << WGM01) | (1 << WGM00);
- TCCR0B = (0 << WGM02)
- | (0 << CS02) | (1 << CS01) | (0 << CS00);
- OCR0A = 0;
- DDRB |= (1 << PB0);
- uint8_t dir = 1;
- while (1)
- {
- if (dir)
- {
- if (OCR0A <= 254)
- {
- OCR0A += 1;
- }
- else
- {
- OCR0A = 255;
- dir = 0;
- }
- }
- else
- {
- if (OCR0A >= 1)
- {
- OCR0A -= 1;
- }
- else
- {
- OCR0A = 0;
- dir = 1;
- }
- }
- _delay_ms(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment