Alex Kapphahn wrote:
> Currently, I am testing my code in Proteus:
What, the f**k is Proteus? For what is it good for?
> I am writing a code for a MCU until that will transmit data via UART
> (RS232). [ATmega8A]
#define MYBRR FOSC/16/BAUD-1
Stupid, but may work. You should clarify your intention using braces.
#define MYBRR (FOSC/16)/BAUD-1
Much better is it with implicite rounding:
#define MYBRR (FOSC/16+BAUD/2)/BAUD-1
UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
//Frame format setting: 8 Data, 2 Stop bit
Your code partially doesn't match the provided comment. Matches for
number of data bits, but doesn't match for number of stop bits.
/* USART receive function */
unsigned char USART_Receive(void)
while(!(UCSRA & (1 << RXC))); //Wait until data is received
return UDR; //Get the data from buffer and return it
Poor implementation. It doesn't care the possebility of transmission
> n Proteus, the virtual terminal displays 0. However, I am expecting to
> see 10.
You shouldn't. If you send a char with value 10, you will receive a char
with value 10 (in the case there is no transmission error and sender and
receiver uses same frame format).
You can expect to get a visible "10" in the only case, the receiving
terminal replaces received, but unprintable characters with decimal
strings, describing their values.
> Proteus bug or logic error?
Probably your error. Either you made a mistake in your code or you don't
understand what "Proteus" does. Whatever "Proteus" is...