Rainbow-electronics Atmega169L Bedienungsanleitung Seite 156

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 317
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 155
156
ATmega169V/L
2514AAVR08/02
The following simple USART initialization code examples show one assembly and one
C function that are equal in functionality. The examples assume asynchronous opera-
tion using polling (no interrupts enabled) and a fixed frame format. The baud rate is
given as a function parameter. For the assembly code, the baud rate parameter is
assumedtobestoredinther17:r16Registers.
Note: 1. The example code assumes that the part specific header file is included.
For I/O Registers located in extended I/O map, IN, OUT, SBIS, SBIC, CBI,
and SBI instructions must be replaced with instructions that allow access to
extended I/O. Typically LDSand STScombined with SBRS, SBRC, SBR, and
CBR.
More advanced initialization routines can be made that include frame format as parame-
ters, disable interrupts and so on. However, many applications use a fixed setting of the
baud and control registers, and for these types of applications the initialization code can
be placed directly in the main routine, or be combined with initialization code for other
I/O modules.
Assembly Code Example
(1)
USART_Init:
;
Set baud rate
out UBRRH, r17
out UBRRL, r16
;
Enable receiver and transmitter
ldi r16, (1<<RXEN)|(1<<TXEN)
out UCSRB,r16
;
Set frame format: 8data, 2stop bit
ldi r16, (1<<USBS)|(3<<UCSZ0)
out UCSRC,r16
ret
C Code Example
(1)
void USART_Init( unsigned int baud )
{
/*
Set baud rate
*/
UBRRH = (unsigned char)(baud>>8);
UBRRL = (unsigned char)baud;
/*
Enable receiver and transmitter
*/
UCSRB = (1<<RXEN)|(1<<TXEN);
/*
Set frame format: 8data, 2stop bit
*/
UCSRC = (1<<USBS)|(3<<UCSZ0);
}
Seitenansicht 155
1 2 ... 151 152 153 154 155 156 157 158 159 160 161 ... 316 317

Kommentare zu diesen Handbüchern

Keine Kommentare