while-Schleife Variablenvergleich

Gast #4648709
Lesenswert?
• ▲
▼
Hallo Zusammen,

Ich bin momentan meine ersten Schritte mit einem Microcontroller zu 
machen, was soweit auch klappt. Ich hätte nur eine kleine Frage die mir 
bestimmt jemand beantworten kann:

Ich habe Folgendes Problem:
Das Programm bleibt immer in der While Schleiße stecken (2. while 
Schleife) und habe schon einiges geändert. Der Timer läuft und die 
Anzahl der überläufe wird auch gezählt.
1
while(1)
2
{
3
    if( ! (Taster_PIN &  (1<<TASTER)))
4
    {
5
    TCCROB = (1<<CS01);
6
         while (! (anzahl == 9000))
7
         {
8
              if (TIFR0 & (1<<TOV0);
9
              { 
10
               TIFR0 = (1<<TOV0);
11
               anzahl = anzahl + 1;
12
              }
13
         }
14
    LED_PORT ^= (1<<LED_RED) | (1<<LED_GRN);
15
    TCCR0B &= ~(1<<CS01):
16
    anzahl = 0;
17
}

Es wäre nett wenn mit jemand eine kurze erläuterung meines Fehler zu 
geben.
Danke schonmal
Gast #4648749
Lesenswert?
• ▲
▼
Danke das hat mir schon geholfen anzahl war vorher uint8 variabel. habe 
das nun geändert und es klappt
1
*/
2

3
#include <avr/io.h>
4
#include <util/delay.h>
5

6
/* PORT / DDR / PIN Definitionen für Übersichtlichkeit */
7
#define LED_DDR      DDRD
8
#define LED_PORT    PORTD
9
#define LED_RED      PD2
10
#define LED_GRN      PD3
11

12
#define TASTER_PORT    PORTD
13
#define TASTER_DDR    DDRD
14
#define TASTER_PIN    PIND
15
#define TASTER_1    PD4
16
#define TASTER_2    PD5
17

18
uint16_t anzahl;
19
  
20
  
21
int main()
22
{  
23

24
anzahl=0;
25

26

27
while(1)
28
{
29
       if  ( ! (TASTER_PIN & (1<<TASTER_2)))
30
       {  
31
       TCCR0B = (1<<CS01);
32
             while( ! (anzahl == 9000))
33
             {
34
                if (TIFR0 & (1<<TOV0))
35
                {
36
                 TIFR0 = (1<<TOV0);
37
                 anzahl = anzahl + 1;
38
                }
39
            
40
       }
41
LED_PORT ^= (1<<LED_RED) | (1<<LED_GRN);  
42
      TCCR0B &= ~(1<<CS01);
43
anzahl = 0;                
44
}
45
}
46

47
      
48

49

50

51
  
52
  
53

54
  return 0;
55
}

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