Programming USART Using AVR Microcontroller
Programming USART Using AVR Microcontroller
Technology, Jamshoro
Department of Telecommunication
Engineering
Programming USARTs
By:
Serial Communication
Baud Rates
Baud Rate is synonymous to symbols per second or pulses per
1200
2400
4800
9600
19200
38400
57600
115200
RS-232 Protocol
RS 232 Voltage levels
-3 to -25 (Logic HIGH)
+3 to +25
(Logic LOW)
Data bit sequence
IDEAL (Logic HIGH)
Start bit (Logic LOW)
First bit as LSB (B0)
.
.
.
8th bit as MSB (B7)
Parity bit (if pre-set in settings)
Stop bits (can be 1 or 2 depends on settings)
Programing in AVR
Registers:
UDR (USART Data Register)
UBRRL & UBRRH Register (16-bit)
Where:
Fosc = Oscillator Frequency
X is the value to be loaded in UBRR Register
Desired Baud rate can be any from:
1200
2400
4800
9600
19200
38400
57600
115200
UBRR
URSEL = 0
URSEL = 1
UBRRH
UCSRC
UCSRA
UCSRB
UCSRC
Working Steps:
1. Select Baud Rate (UBRR)
2. Enable TX/RX or Both (UCSRB)
3. Select Character size - default is 8 (UCSRC)
For Transmission:
Check if UDRE (Transmission Buffer) is empty, if yes,
load data to UDR
For Receiving:
Check if RXC (Receive Complete), if yes, copy data from
UDR
USART
Transmit
Program
#include "avr/io.h"
int main()
{
UBRRL=0x33;
UCSRB=0x18;
UCSRC=0x86;
DDRB=0xFF;
while(1)
{
if(UCSRA & (1 << 5))
UDR = 'A';
Proteus Schematic
Proteus Results