Rainbow-electronics ATmega8515L Manual do Utilizador Página 139

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 223
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 138
139
ATmega8515(L)
2512A–AVR–04/02
Sending Frames with 9 Data
Bits
If 9-bit characters areused(UCSZ=7),theninthbit must be writtentotheTXB8 bit in
UCSRBbeforethe lowbyte of the character iswritten to UDR. The following code
examplesshow atransmit function that handles9-bit characters. For theassembly
code, the data to be sent is assumed to be stored in Registers R17:R16.
Note: 1. Thesetransmit functions are written to be generalfunctions.Theycan beoptimized if
the contents of the UCSRB isstatic. For example, only theTXB8 bit of the UCSRB
Register is used after initialization.
Theninthbit can beusedfor indicatinganaddress frame when using multi processor
communication modeorfor otherprotocolhandling asfor example synchronization.
Transmitter Flags and
Interrupts
The USART Transmitterhas two flags that indicate itsstate:USART Data Register
Empty(UDRE) and Transmit Complete (TXC). Bothflagscan beusedfor generating
interrupts.
The Data RegisterEmpty(UDRE) flag indicateswhether thetransmit buffer isready to
receive newdata. Thisbit isset when thetransmit buffer is empty, andclearedwhen the
transmit buffercontainsdata to betransmitted that has not yet been moved into the Shift
Register. Forcompatibilitywithfuture devices, always write thisbit to zero when writing
the UCSRA Register.
When the Data RegisterEmptyInterrupt Enable (UDRIE) bit in UCSRB iswrittentoone,
the USART Data RegisterEmptyInterrupt will beexecuted aslong asUDRE isset (pro-
vided that global interrupts areenabled). UDRE isclearedbywriting UDR. When
interrupt-driven data transmission is used, the Data RegisterEmptyInterrupt routine
musteitherwrite newdata to UDRinorder to clearUDRE ordisablethe data register
Assembly Code Example
(1)
USART_Transmit:
;
Wait for empty transmit buffer
sbis UCSRA,UDRE
rjmp USART_Transmit
;
Copy ninth bit from r17 to TXB8
cbi UCSRB,TXB8
sbrc r17,0
sbi UCSRB,TXB8
;
Put LSB data (r16) into buffer, sends the data
out UDR,r16
ret
CCode Example
(1)
void USART_Transmit( unsigned int data )
{
/*
Wait for empty transmit buffer
*/
while ( !( UCSRA & (1<<UDRE))) )
;
/*
Copy ninth bit to TXB8
*/
UCSRB &= ~(1<<TXB8);
if ( data & 0x0100 )
UCSRB |= (1<<TXB8);
/*
Put data into buffer, sends the data
*/
UDR = data;
}
Vista de página 138
1 2 ... 134 135 136 137 138 139 140 141 142 143 144 ... 222 223

Comentários a estes Manuais

Sem comentários