This program provides basic USART routines. This code is a part of pAVRlib.
In examples/ you'll find a small test program.
The software UART is written based on Application Note AVR305.
Initialize
Before you use this routines, you need define F_CPU (in Hz) and USART_BAUD.
.equ F_CPU = 1000000
.equ USART_BAUD = 4800Furthermore you need to define the ports if you use AVR without a hardware USART (e.g. ATtiny25).
; PB3 and PB4 (Pin 2 and 3 of ATtiny25/45/85)
.equ USART_DDR = DDRB
.equ USART_PORT = PORTB
.equ USART_PIN = PINB
.equ USART_RXD = 3
.equ USART_TXD = 4
See also examples/usart-test.asm.
Subroutines
void USART_INITIALIZE() (in: (none), out: (none))
set up the port and baudrate.
void USART_TRANSMIT(char) (in: r24, out: (none))
send a byte.
char USART_RECEIVE() (in: (none), out: r24)
receive a byte.
Example
This is a simple echo program.
rcall USART_INITIALIZE
loop:
rcall USART_RECEIVE
rcall USART_TRANSMIT
rjmp loop