Rainbow-electronics ATmega128L Uživatelský manuál Strana 175

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 331
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 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;
}
Zobrazit stránku 174
1 2 ... 170 171 172 173 174 175 176 177 178 179 180 ... 330 331

Komentáře k této Příručce

Žádné komentáře