'UBRR0H' was not declared in this scope

#6509723
Lesenswert?

Hallo Zusammen,

Ich bekomme die für mich unerkläriche Meldung vom Compiler:


  recipe for target 'Uart.o' failed
  'UBRR0H' was not declared in this scope
  'UBRR0L' was not declared in this scope
  'UCSR0B' was not declared in this scope
  'RXEN0' was not declared in this scope
  'TXEN0' was not declared in this scope
  'RXCIE0' was not declared in this scope
  'UCSR0C' was not declared in this scope
  'USBS0' was not declared in this scope
  'UCSZ00' was not declared in this scope


Ich nutze Atmel STudio 7.

Ich habe diese Uart Function in Uart.cpp

void USART_Init( unsigned int ubrr)
{
  /*Set baud rate */
  UBRR0H = (unsigned char)(ubrr>>8);
  UBRR0L = (unsigned char)ubrr;
  /*Enable receiver and transmitter */
  UCSR0B = (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0);
  /* Set frame format: 8data, 2stop bit */
  UCSR0C = (1<<USBS0)|(3<<UCSZ00);

Im Hauptprogramm habe ich entsprechend Uart.h included:

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include "Uart.h"

die Header Datei dazu schaut wie folgt aus:
#ifndef UART_H_
#define UART_H_

#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1

void USART_Init(unsigned int ubrr);


#endif /* UART_H_ */


Warum zu Hölle bringt mir Atmel STudio die Fehlermeldung?
Die Register sollten den Compiler doch beakannt sein, da ich ja avr/io.h 
ziemlich am Anfang include.

Habt ihr ne Idee? Was mach ich falsch?
#6509766
Lesenswert?

pegel schrieb:
> Warum für die paar Zeilen Uart.cpp?
Da kommt natürlich noch mehr rein, sollte ein struktiertes Programm 
werden...
>
> Wie heisst die main mit Nachnamen?

main.cpp

>
> Kann es sein, dass es das beliebte
> extern "C"
> Problem ist?
Was ist das beliebte extern "C" Problem...?
>
> Michael K. schrieb:

>> Main.ccp
>
> ???
Sorry, hab mich vertippt sollte main.cpp heißen..
Gast #6509817
Lesenswert?

#ifdef __cplusplus
extern "C" {
#endif

// gesamter Inhalt der main.cpp

#ifdef __cplusplus
}
#endif

Übrigens kann man die komplette main.cpp in extern "C" setzen,
dann gilt das für alle benutzten .c Dateien im Projekt.

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