Source Code:


.equ MOSI = 3 ;for ATmega328 .equ SCK = 5 .equ SS = 2 LDI R17,0xFF ;Port D is output OUT DDRD,R17 LDI R17,(1<<MOSI)|(1<<SCK)|(1<<SS) OUT DDRB,R17 ;MOSI,SCK, and SS output LDI R17,(1<<SPE)|(1<<MSTR)|(1<<SPR0) ;enable SPI OUT SPCR,R17 ;master, CLK = fck/16 Transmit: CBI PORTB,SS ;enable slave device LDI R17,'G' ;move G letter to R17 OUT SPDR,R17 ;start transmission of G Wait: IN R20,SPSR SBRS R20,SPIF ;wait for transmission RJMP Wait ;to complete IN R18,SPDR ;read received data into R18 OUT PORTD,R18 ;move R18 to PORTD SBI PORTB,SS ;disable slave device RJMP Transmit ;do it again