avr I/O definitions

Gast #3354852
Lesenswert?

build kann nicht ausgeführt werden:
fehler:

expected unqualified-id before 'volatile'
expected ')' before 'volatile'
1
// uC frequency
2
#ifndef  F_CPU            // must be written before delay.h
3
#define  F_CPU 3686400UL        // loop frequency
4
#endif
5

6
// ! LIBRARYS
7
#include <avr/io.h>
8
#include <util/delay.h>
9
#include <avr/interrupt.h>
10
#include <avr/sleep.h>
11
#include "lcd-routines.h"
12
#include "CLED.h"
13
//#include "CServo.h"
14

15
// ! definitions I/O
16
DDRB &= ~((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7));    // set as input  // is equal to: (1 << DDB1)
17
DDRC |=  ((1 << PC0) | (1 << PC1) | (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5) | (1 << PC6));          // set as output
18
//DDRD          // DDRD is used for LCD
19

20
// ! activate intern pull-up resistors
21
PORTB |= ((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7));    // set pull-up R
22

23
// ! initialize all outputs
24
PORTB &= ~((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB6));    // low


ändere ich die reihenfolge auf fcpu, dann i/o, dann librarys kennt er 
DDRx nicht.
#3354858
Lesenswert?

Du brauchst ganz dringend ein C-Buch

Ausführbare Anweisungen können nicht ausserhalb von Funktionen stehen
1
#ifndef  F_CPU            // must be written before delay.h
2
#define  F_CPU 3686400UL        // loop frequency
3
#endif
4

5
// ! LIBRARYS
6
#include <avr/io.h>
7
#include <util/delay.h>
8
#include <avr/interrupt.h>
9
#include <avr/sleep.h>
10
#include "lcd-routines.h"
11
#include "CLED.h"
12
//#include "CServo.h"
13

14

15
int main()
16
{
17
  // ! definitions I/O
18
  // set as input  // is equal to: (1 << DDB1)
19
  DDRB &= ~((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) |
20
            (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7));
21
  // set as output
22
  DDRC |=  ((1 << PC0) | (1 << PC1) | (1 << PC2) | (1 << PC3) |
23
            (1 << PC4) | (1 << PC5) | (1 << PC6));
24
  //DDRD          // DDRD is used for LCD
25

26
  // ! activate intern pull-up resistors
27
  // set pull-up R
28
  PORTB |= ((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) |
29
            (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7));
30

31
  // ! initialize all outputs
32
  // low
33
  PORTB &= ~((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) |
34
             (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB6));
35

36
  while( 1 )
37
  {
38

39
  }
40
}
Gast #3354942
Lesenswert?

macro µC schrieb:
> micro uc schrieb:
>> expected unqualified-id before 'volatile'
>> expected ')' before 'volatile'
>
> Karl Heinz Buchegger schrieb:
>> Ausführbare Anweisungen können nicht ausserhalb von Funktionen stehen
>
> Und warum meckert der Compiler das nicht direkt an, sondern brabbelt
> irgendein überhaupt nicht konstrukives Zeugs daher?

Weil er nicht weiß, daß es sich um etwas handelt, das eigentlich in eine 
Funktion gehört. DDRB ist ein Makro, das erstmal ersetzt wird. Da kommt 
dann auch das volatile her. Es ergibt sich dann was, das an der Stelle 
keinen Sinn ergibt, also meckert der Compiler das entsprechend an. Er 
testet aber nicht durch, ob es in irgendeinem anderen Kontext vielleicht 
Sinn ergeben könnte, nur um dir dann zu sagen, wo dein Code vielleicht 
eigentlich stehen müßte.

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