Rainbow-electronics ATmega8515L Instrukcja Użytkownika Strona 126

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 223
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 125
126
ATmega8515(L)
2512A–AVR–04/02
The following codeexamplesshowhow to initializethe SPI as a Slave andhow to per-
formasimple reception.
Note: 1. Theexample codeassumes that the part specificheaderfileis included.
Assembly Code Example
(1)
SPI_SlaveInit:
; Set MISO output, all others input
ldi r17,(1<<DD_MISO)
out DDR_SPI,r17
; Enable SPI
ldi r17,(1<<SPE)
out SPCR,r17
ret
SPI_SlaveReceive:
; Wait for reception complete
sbis SPSR,SPIF
rjmp SPI_SlaveReceive
; Read received data and return
in r16,SPDR
ret
CCode Example
(1)
void SPI_SlaveInit(void)
{
/* Set MISO output, all others input */
DDR_SPI = (1<<DD_MISO);
/* Enable SPI */
SPCR = (1<<SPE);
}
char SPI_SlaveReceive(void)
{
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)))
;
/* Return data register */
return SPDR;
}
Przeglądanie stron 125
1 2 ... 121 122 123 124 125 126 127 128 129 130 131 ... 222 223

Komentarze do niniejszej Instrukcji

Brak uwag