MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB LED
SETB SS
CLR BUSY
MOV SPCTL,#50H ;Enable SPI master mode
MOV SPSTAT,#0C0H ;Clear interrupt flag
MOV IE2,#ESPI ;Enable SPI interrupt
SETB EA
LOOP:
JB BUSY,$
SETB BUSY
CLR SS ;Pull down the slave SS pin
MOV SPDAT,#5AH ;Send test data
JMP LOOP
END
20.6.2 Slave Routine of Single Master Single Slave Mode (Interrupt Mode)
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
sfr SPSTAT = 0xcd;
sfr SPCTL = 0xce;
sfr SPDAT = 0xcf;
sfr IE2 = 0xaf;
#define ESPI 0x02
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
sbit LED = P1^1;
void SPI_Isr() interrupt 9