PWM ATTiny 2313 RGB LED _GCC

OP #1942104
Lesenswert?

Guten Tag,

Ich versuche seit kurzem eine led zu dimmen, jedoch dies gelingt nicht. 
Vielleicht habt ihr eine Lösung. Hier mein Code ;)

lg Ben
1
#include <avr/io.h>
2
#include <util/delay.h>
3

4
int main()
5
{
6
  
7

8
  TCCR1A = (0<<WGM11) | (1<<WGM10) | (1<<COM1A1);
9
  TCCR1B = (1<<CS12) | (1<<CS10);
10
  ICR1 = 0x6FFF;
11
  OCR1A = 0x2FFF;
12
 
13
  while( 1 ) 
14
  {
15
  PORTB ^= ( 1 << PB3 );  
16
    _delay_ms(1000); 
17
  PORTB ^= ( 0 << PB3 ); 
18
    _delay_ms(1000);
19
  }
20
  return 0;
21
}
OP #1942138
Lesenswert?

okay aber wie aktiviere ich nun den Timer, sodass die LED an Port B3 
langsam ein geht und aus geht?

1
#include <avr/io.h>
2
#include <util/delay.h>
3

4
int main()
5
{
6
  
7

8
  TCCR1A = (0<<WGM11) | (1<<WGM10) | (1<<COM1A1);
9
  TCCR1B = (1<<CS12) | (1<<CS10);
10
  ICR1 = 0x6FFF;
11
  OCR1A = 0x2FFF;
12
 
13
  while( 1 ) 
14
  {
15
    ????
16
  }
17
  return 0;
18
}
Gast #1942148
Lesenswert?

1
ISR(TIMER0_OVF_vect) {
2
  static uint8_t tick;
3

4
  if (tick < red_pwm)
5
    PORTB |= _BV(LED_RED);
6
  else
7
    PORTB &=~_BV(LED_RED);
8

9
  if (tick < green_pwm)
10
    PORTB |= _BV(LED_GREEN);
11
  else
12
    PORTB &=~_BV(LED_GREEN);
13

14
  if (tick < blue_pwm)
15
    PORTB |= _BV(LED_BLUE);
16
  else
17
    PORTB &=~_BV(LED_BLUE);
18

19

20
  tick++;
21
}
22

23
in main z.B.:
24

25
 TCCR0A = 0;
26
 TCCR0B = _BV(CS00); // F_OSC Timer Freq
27
 TIMSK = _BV(TOIE0);
28
  sei();

Alles hier aus der Codesammlung geklaut ;)

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren