ATmega128 - UCSROA未声明(首次使用此功能)

时间:2014-11-27 11:06:30

标签: avr atmega

我对ATmega128(UART)有疑问 该程序通过UART发送Hello消息。

以下是我的代码。

#include <avr/io.h>

void putch(unsigned char data)
{
    while((UCSROA & 0x20) == 0);
    UDR0 = data;
    UCSROA |= 0x20;
}

int main()
{
    unsigned char text[] = "Hello! World!\r\n";
    unsigned char i = 0;

    DDRE = 0xFE;
    UCSROA = 0x00;
    UCSROB = 0x18;
    UCSROC = 0x06;
    UBRROH = 0x00;
    UBRROL = 0x03;

    while(text[i] != '\0')
    putch(text[i++]);
    return 0;

}

这是错误消息。

Build succeeded with 0 Warnings... 
avr-gcc  -mmcu=atmega128 -Wall -gdwarf-2 -std=gnu99   -DF_CPU=7372800UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Hello.o -MF dep/Hello.o.d  -c  ../Hello.c 
../Hello.c: In function 'putch': 
../Hello.c:5: error: 'UCSROA' undeclared (first use in this function) 
../Hello.c:5: error: (Each undeclared identifier is reported only once 
../Hello.c:5: error: for each function it appears in.) 
../Hello.c: In function 'main': 
../Hello.c:16: error: 'UCSROA' undeclared (first use in this function) 
../Hello.c:17: error: 'UCSROB' undeclared (first use in this function) 
../Hello.c:18: error: 'UCSROC' undeclared (first use in this function) 
../Hello.c:19: error: 'UBRROH' undeclared (first use in this function) 
../Hello.c:20: error: 'UBRROL' undeclared (first use in this function) 
make: *** [Hello.o] Error 1 Build failed with 8 errors and 0 warnings...

我测试了其他计算机的代码。
但是,它没有用。
我不知道如何解决这个问题。

给我一些建议。
谢谢。

1 个答案:

答案 0 :(得分:1)

它不是

UCSR的 0 A

字母&#34; O&#34;,

UCSR0A

号码为0