我正在尝试使用 mx232 将数据从 atmega328 连续发送到 pc,并且我正在使用 tera term 来显示来自 com5 的数据。这里的问题是,无论我从 atmega 发送哪个字符,发送的数据总是相同的字符。代码在下面,并附上了 tera 术语的输出照片
#define F_CPU 8000000UL
#define BAUD_RATE 9600
#define RBC 51
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
void define_inputs_and_outputs(){
DDRC |= (DDC5);
DDRD |= (1<<DDD1);
}
void init_serial_transmit(){
UCSR0B = (1<<TXEN0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
//set baud rate
UBRR0H = 0;
UBRR0L = RBC;
}
void serialPutString(char* string, unsigned int size){
for (int i=0; i<size; i++)
{
while(!(UCSR0A & (1<<UDRE0)));
UDR0 = (int) string[i];
}
}
void stop_serial(){
UCSR0A = 0;
UCSR0B = 0;
UCSR0C = 0;
UDR0 = 0;
}
void init_serial_receive(){
return;
}
void blink(){
PORTC |= (1<<PORTC5);
_delay_ms(300);
PORTC &= ~(1<<PORTC5);
}
int main(void)
{
/* Replace with your application code */
define_inputs_and_outputs();
init_serial_transmit();
//_delay_ms(10000);
while (1){
UDR0 = 8;
serialPutString("moha",4);
blink();
}
}