Rainbow-electronics ATmega64M1 Instrukcja Użytkownika Strona 158

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 343
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 157
158
8209A–AVR–08/09
ATmega16M1/32M1/64M1
Note: 1. The example code assumes that the part specific header file is 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
C Code 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 157
1 2 ... 153 154 155 156 157 158 159 160 161 162 163 ... 342 343

Komentarze do niniejszej Instrukcji

Brak uwag