SPI —
SPI
SPI(Serial Peripheral Interfacer ) SPI RAM EEPROM FlashROM A D D A LED LED I O UART SPI I O SPI I O
AT89C205l SPI EEPROM 93CA6 1 I O SPI
93C46 SPI
93CA6 SPI 4 I O (SK) DO DI CS (MSB) (LsB) 93C46 SPI 2
SPI
SPI AT89C2051 SPI 1 AT89C2051 EEPROM 93C46 P1 0 SPI SDO P1 2 SPI SCK P1 3 SPI SCS P1 1 SPI SDI
P1 2(SCK) 0( )
AT89C2051 P1 0 1 (1) 2 (10) 6 (A5A4A3A2A1A0) P1 1 1 (0) l6 ( )
AT89C2051 P1 0 1 (1) 2 (01) 6 (A5A4A3A2A1A0) P1 0 l6 ( )
(WEN)) 1 (1) 2 (00) 6 (11XXXX)
(WDS)) 1 (1) 2 (00) 6 (00XXXX)
C51 SPI
// I/O
sbit SDO=P1^0
sbit SDI=P1^1
sbit SCK=P1^ 2
sbit SCS=P1^3
sbit ACC_7= ACC^7
unsigned int SpiRead(unsigned char add)
{
unsigned char i
unsigned int datal6
add&=0x3f /*6 */
add |=0x80 /* l0*/
SDO=1 /* 1 */
SCK=0
SCK=1
for(i=0 i<8 i++)/* */
{
if(add&0x80==1)
SDO=1
else
SDO=0
SCK=0 /* */
SCK=1
add<<= 1
}
SCK=1 /* 1 */
SCK=0
datal6<<= 1;/* 16 */
for(i=0 i<16 i++)
{
SCK= 1
_nop_()
if(SDI==1)
datal6|=0x01
SCK =0
datal6< < =1
}
return datal6
}
SCK ( ) ( ) ) P1 2(SCK)