Serial port Atmega128中的串行通信

Serial port Atmega128中的串行通信,serial-port,avr-gcc,serial-communication,Serial Port,Avr Gcc,Serial Communication,我想通过串行总线发送一些字符串到PC。在cute com中,它显示的字符串和一些字符丢失,并且在字符串的开始和结束处附加了一些十六进制数。我不知道为什么会出现这个问题,请帮助解决这个问题。我的密码在这里 #include <avr/io.h> #include <string.h> #include <avr/interrupt.h> #define F_CPU 16000000UL #include <util/delay.h>

我想通过串行总线发送一些字符串到PC。在cute com中,它显示的字符串和一些字符丢失,并且在字符串的开始和结束处附加了一些十六进制数。我不知道为什么会出现这个问题,请帮助解决这个问题。我的密码在这里

 #include <avr/io.h>  
 #include <string.h>
 #include <avr/interrupt.h>
 #define F_CPU 16000000UL
 #include <util/delay.h>    
 #define USART_BAUDRATE 9600    // Baud Rate value
 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
 void usart_init() {

//Enable communication in duplex mode
UCSR1A = (1 << U2X1);
UCSR1B |= (1 << RXEN1) | (1 << TXEN1);   // Turn on the transmission and reception circuitry
UCSR1C &= ~(1 << UMSEL1);
UCSR1C |= (1<<USBS1) | (1 << UCSZ10) | (1 << UCSZ11);

UBRR1L = BAUD_PRESCALE;                 // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRR1H = (BAUD_PRESCALE >> 8);          // Load upper 8-bits of the baud rate value.. 
}

void serial_write(unsigned char data) {

while(!(UCSR1A & (1<<UDRE1)))
    ;
    UDR1 = data;
    _delay_ms(10);
}

 void transmitString(unsigned char *str) {

int i;
for(i=0;i<strlen(str);i++) {
    serial_write(str[i]);
    _delay_ms(1);
}
}

int main() {
cli();
usart_init();
unsigned char buffer[20];
strcpy(buffer, "Walk Alone");
while(1) {  
    transmitString(buffer);
    //_delay_ms(250);
}
return 0;
}
#包括
#包括
#包括
#定义F_CPU 1600000UL
#包括
#定义USART_波特率9600//波特率值
#定义波特率预刻度(((F_CPU/(USART_波特率*16UL))-1)
void usart_init(){
//启用双工模式下的通信

UCSR1A=(1首先,这个问题属于


要回答您的问题,请使用函数
strcpy()
strlen()
预期为
字符*
而非
无符号字符*
检查

AVR微控制器使用两个频率振荡器运行。默认情况下,控制器使用1MHz的内置振荡器。在程序中,F_CPU为16MHz,这导致数据显示为垃圾。要选择外部振荡器,请设置co的保险丝位控制器。控制器选择外部振荡器进行操作。