Rainbow-electronics ATmega8515L Manuel d'utilisateur Page 138

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 223
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 137
138
ATmega8515(L)
2512A–AVR–04/02
be placeddirectly in themainroutine, orbe combinedwith initialization code for other
I/O modules.
Data Transmission The
USART Transmitter
The USART Transmitter is enabledbysetting the
Transmit Enable
(TXEN) bit in the
UCSRB Register. When theTransmitter is enabled, thenormalportoperation of the
TxD pin is overridden by the USART and given the function as thetransmittersserial
output. The baudrate, modeof operation andframe format must be set up once before
doing any transmissions. If synchronous operation is used, the clock on the XCK pin will
beoverridden and used as transmission clock.
Sending Frames with 5 to 8
Data Bits
A data transmission is initiatedbyloading thetransmit bufferwith the data to betrans-
mitted.The CPUcan load thetransmit bufferbywriting to the UDR I/Olocation. The
buffereddata in thetransmit bufferwill bemoved to the ShiftRegisterwhen the Shift
Register isready to send anewframe. The ShiftRegister isloadedwith newdata if it is
in idle state (no ongoing transmission) or immediately after the last stopbit of the previ-
ousframe is transmitted. When the Shift Register isloadedwith newdata, it will transfer
one complete frame at the rate given by the baudregister, U2Xbit orbyXCKdepending
on modeof operation.
The following codeexamplesshow a simple USART transmit function based on polling
of the
Data Register Empty
(UDRE) flag. When using frameswithless than eight bits,
themost significant bitswrittentothe UDRare ignored.The USART has to beinitialized
beforethe function can beused. For theassembly code, the data to be sent is assumed
to be stored in Register R16
Note: 1. Theexample codeassumes that the part specificheaderfileis included.
The function simply waitsfor thetransmit buffer to beemptybychecking the UDREflag,
before loading it with newdata to betransmitted. If the data register empty interruptis
utilized, theinterrupt routine writes the dataintothe buffer.
Assembly Code Example
(1)
USART_Transmit:
;
Wait for empty transmit buffer
sbis UCSRA,UDRE
rjmp USART_Transmit
;
Put data (r16) into buffer, sends the data
out UDR,r16
ret
CCode Example
(1)
void USART_Transmit( unsigned char data )
{
/*
Wait for empty transmit buffer
*/
while ( !( UCSRA & (1<<UDRE)) )
;
/*
Put data into buffer, sends the data
*/
UDR = data;
}
Vue de la page 137
1 2 ... 133 134 135 136 137 138 139 140 141 142 143 ... 222 223

Commentaires sur ces manuels

Pas de commentaire