I am using an Arduino Uno, and I need to create a program that calculates the actual baud rate and the percent error for all standard baud rate in Arduino monitor program.
First, look at the code used by the Arduino core library to configure
the USART baud rate register: it's in
HardwareSerial::begin(). The general formula is
uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
but beware of the hard-coded exception. You can replicate that part of the code in your own.
Then, look at the ATmega328P datasheet. More specifically, at section 24.4.1. Internal Clock Generation – The Baud Rate Generator. Here you find the formula
BAUD = F_CPU / (8*(UBRR0 + 1))
U2X0 bit has been set (again, beware of the hard-coded
exception). Combine both formulas and you get the actual baud rate.