JMP ISREXIT
MASTER:
SETB SS ;Pull up the SS pin of the slave
MOV SPCTL,#40H ;Reset to slave and standby
ISREXIT:
CPL LED
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB SS
SETB LED
SETB KEY
MOV SPCTL,#40H ;Enable SPI slave mode and standby
MOV SPSTAT,#0C0H ;Clear interrupt flag
MOV IE2,#ESPI ;Enable SPI interrupt
SETB EA
LOOP:
JB KEY,LOOP ;Wait for the key to trigger
MOV SPCTL,#50H ;Enable SPI master mode
CLR SS ;Pull down the slave SS pin
MOV SPDAT,#5AH ;Send test data
JNB KEY,$ ;Wait for the keys to be released
JMP LOOP
END
20.6.6 Routine of Mutual Master-Slave Mode (Polling 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;