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]
>
1 | #define MYBRR FOSC/16/BAUD-1
|
Stupid, but may work. You should clarify your intention using braces.
>
1 | #define MYBRR (FOSC/16)/BAUD-1
|
Much better is it with implicite rounding:
>
1 | #define MYBRR (FOSC/16+BAUD/2)/BAUD-1
|
>
1 | UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
|
>
1 | //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.
>
1 | /* USART receive function */
|
>
1 | unsigned char USART_Receive(void)
|
>
>
1 | while(!(UCSRA & (1 << RXC))); //Wait until data is received
|
>
>
1 | return UDR; //Get the data from buffer and return it
|
>
Poor implementation. It doesn't care the possebility of transmission
errors.
> 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...