I am trying out a simulation in proteus, establishing a connection between atmega2560 and a virtual terminal. I have written C code in microchip studio, uploaded the code to the atmega2560. The simulation produces weird characters on the monitor.

Can someone help?

#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <string.h>
 
#define F_CPU 8000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

void USART_Init() {
    UBRR0H = (unsigned char)(BAUD_PRESCALE >> 8);
    UBRR0L = (unsigned char)(BAUD_PRESCALE);
    UCSR0B = (1 << RXEN0) | (1 << TXEN0);
    UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
}

void USART_Transmit(const char data[]) {
    int length = strlen(data);
    for (int k = 0; k < length; k++) {
    while (!(UCSR0A & (1 << UDRE0)));
    UDR0 = data[k];
    }
}

int main() {
    USART_Init();
    USART_Transmit("Hello, World!\r\n");
    //_delay_ms(1000);
    while (1) {
    // Delay for 1 second
    }
    return 0;
}

Results of simulation

0

There are 0 answers