// Copyright 2006 Yamane Akira //ICC-AVR application builder : 2005/07/18 0:20:02 // Target : M48 // Crystal: 4.0000Mhz // SPI Sample Program for Slave // Receive MOSI Data and Output PORTD corresponding Bit // Also Output to MISO, the data 0 to 0xFF // Programmed by Akira Yamane #include #include void port_init(void) { PORTB = 0x10; DDRB = 0x10; // MISO set to Output PORTC = 0x00; DDRC = 0x00; PORTD = 0xFF; DDRD = 0xFF; } //SPI initialize void spi_init(void) { volatile char IOReg; SPCR = 0x40; // (1 << SPE); SPSR = 0x00; // Clock Rate bit set to 00 } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); spi_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EIMSK = 0x00; TIMSK0 = 0x00; //timer 0 interrupt sources TIMSK1 = 0x00; //timer 1 interrupt sources TIMSK2 = 0x00; //timer 2 interrupt sources PCMSK0 = 0x00; //pin change mask 0 PCMSK1 = 0x00; //pin change mask 1 PCMSK2 = 0x00; //pin change mask 2 PCICR = 0x00; //pin change enable PRR = 0x00; //power controller SEI(); //re-enable interrupts //all peripherals are now initialized } unsigned char SPI_SlaveRxTx(unsigned char sdata) { SPDR = sdata; //wait for SPIF while (!(SPSR & (1<