AVR Studio 4 Simulation

OP #2134256
Lesenswert?

Hallo!

Ich möchte ein Programm für einen Atmega 32 im AVR Studio 4 Simulieren.
Nur leider Funktioniert das nicht so ganz.
Hier mein Code:
1
#include <avr/io.h>
2
#include <compat/deprecated.h> 
3
#include <inttypes.h>
4
#include <avr/interrupt.h>
5
#define TRUE 1
6
#define FALSE 0
7

8
//toggle bit Key1
9
  uint8_t key2Toggle = FALSE;
10
  
11
SIGNAL(SIG_INTERRUPT0) {
12
  key2Toggle = key2Toggle ^ TRUE;
13
}
14

15
int main(void) {
16
  
17
  // Port Output enable
18
  sbi(DDRB, PB4);
19
  //sbi(PORTB, PB4);
20
  
21
  // Port D PD2 Input enable
22
  cbi(DDRD, PD2);
23
  
24
  //activate Pull up Resistor
25
  sbi(PORTD, PD2);
26
  
27
  //Rising edge for INT0
28
  MCUCR |= (1<<ISC01) | (1<<ISC00);
29
  
30
  //Allow INT0
31
  GICR |= (1<<INT0);
32
  
33
  //Allow global interrupt
34
  sei();
35
  
36
  // main program 
37
  while(TRUE)
38
  {
39
  if(key2Toggle == TRUE) {
40
    // Port enable
41
    sbi(PORTB, PB4);      
42
    }
43

44
  if(key2Toggle == FALSE) {
45
    // Port disable
46
    cbi(PORTB, PB4);    
47
  }    
48
  
49
  }
50
  
51
}

Also der Interrupt funktioniert (key2Toggel wird auf true gesetzt) nur 
bleibt das Programm immer in der zweiten if Anweisung bei cbi "hängen".

Hat da jemand eine Idee warum das so ist?
Die while schleife müsste ja immer von neuem beginnen oder?

godi
OP #2134733
Lesenswert?

Vielen Dank!

Mit volatil funktioniert es.
Hat da der Compiler die if Anweisung wegoptimiert?

Ich habe da noch ein weitere Frage:
Wenn ich im main vor der while Schleife eine Variable (uint8_t) anlege 
und diese mit Watch beobachten will dann kann er keinen Wert anzeigen 
sondern er schreibt "Location not valid".
Muss ich da noch irgendeine Einstellung machen?

godi
OP #2134744
Lesenswert?

godi godi schrieb:
> Ich habe da noch ein weitere Frage:
> Wenn ich im main vor der while Schleife eine Variable (uint8_t) anlege
> und diese mit Watch beobachten will dann kann er keinen Wert anzeigen
> sondern er schreibt "Location not valid".
> Muss ich da noch irgendeine Einstellung machen?

Aso anscheinend muss ich diese Variable auch mit voltaile anlegen.

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