Uart
Uart
KEYWORDS:
HARDWARE UART #004
This document is originally distrubuted by AVRfreaks.net, and may be distributed, reproduced, and modified
without restrictions. Updates and additional design notes can be found at: www.avrfreaks.net
Introduction This document provides a short introduction to the use of the hardware UART present in
most AVR devices. There are several existing application notes regarding the UART
(AVR304, AVR305 and AVR306). Issues outside the boundaries of this document might
be resolved in one of these.
www.avrfreaks.net 1
Design Note #004 – Date: 02/02
Code examples The following code should be self-explanatory if the comments are read.
Polled UART
C Code Assembly
//include definitions for the AT90S8515 ;include definitions for the AT90S8515
#define ENABLE_BIT_DEFINITIONS .include "8515def.inc"
#include <io8515.h>
;definitions
//initialize UART .def temp = r16 ;temporary data
void InitUART(unsigned char baudrate)
{ lditemp,low(RAMEND)
UBRR = baudrate; outSPL,temp
//enable receiver and transmitter lditemp,high(RAMEND)
UCR |= (1<<RXEN)|(1<<TXEN); outSPH,temp;init Stack Pointer
} rjmpstart;reset handler
forever:
rjmp forever ;eternal loop