Rainbow-electronics ATmega128L Manual de usuario Pagina 175

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 331
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 174
175
ATmega128(L)
2467B09/01
The following code example shows a simple USART receive function based on polling
of the Receive Complete (RXC) flag. When using frames with less than eight bits the
most significant bits of the data read from the UDR will be masked to zero. The USART
has to be initialized before the function can be used.
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 LDS and STS combined with SBRS, SBRC, SBR, and CBR.
The function simply waits for data to be present in the receive buffer by checking the
RXC flag, before reading the buffer and returning the value.
Assembly Code Example
(1)
USART_Receive:
; Wait for data to be received
sbis UCSRA, RXC
rjmp USART_Receive
; Get and return received data from buffer
in r16, UDR
ret
C Code Example
(1)
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
Vista de pagina 174
1 2 ... 170 171 172 173 174 175 176 177 178 179 180 ... 330 331

Comentarios a estos manuales

Sin comentarios