ATMEGA325-16AJ ATMEL [ATMEL Corporation], ATMEGA325-16AJ Datasheet - Page 159

no-image

ATMEGA325-16AJ

Manufacturer Part Number
ATMEGA325-16AJ
Description
8-bit Microcontroller with In-System Programmable Flash
Manufacturer
ATMEL [ATMEL Corporation]
Datasheet
Sending Frames with 9 Data
Bit
2570A–AVR–09/04
If 9-bit characters are used (UCSZ = 7), the ninth bit must be written to the TXB8n bit in
UCSRnB before the low byte of the character is written to UDRn. The following code
examples show a transmit function that handles 9-bit characters. For the assembly
code, the data to be sent is assumed to be stored in registers R17:R16.
Notes:
The ninth bit can be used for indicating an address frame when using multi processor
communication mode or for other protocol handling as for example synchronization.
Assembly Code Example
C Code Example
USART_Transmit:
void USART_Transmit( unsigned int data )
{
}
; Wait for empty transmit buffer
sbis UCSR0A,UDRE0
rjmp USART_Transmit
; Copy 9th bit from r17 to TXB80
cbi
sbrc r17,0
sbi
; Put LSB data (r16) into buffer, sends the data
out
ret
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0))) )
/* Copy 9th bit to TXB80 */
UCSR0B &= ~(1<<TXB80);
if ( data & 0x0100 )
/* Put data into buffer, sends the data */
UDR0 = data;
1. These transmit functions are written to be general functions. They can be optimized if
2. The example code assumes that the part specific header file is included.
UCSR0B |= (1<<TXB80);
the contents of the UCSRnB is static. For example, only the TXB8n bit of the UCS-
RnB Register is used after initialization.
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 “LDS” and “STS” combined with “SBRS”, “SBRC”, “SBR”, and
“CBR”.
UCSR0B,TXB80
UCSR0B,TXB80
UDR0,r16
;
(1)(2)
(1)(2)
ATmega325/3250/645/6450
159

Related parts for ATMEGA325-16AJ