來源:侃單片機 作者:etiller 修改:limiji /*正常操作電壓為2.7~3.6V,實驗中發(fā)現(xiàn)當(dāng)電壓超過4.25V后讀出的狀態(tài)字節(jié)為9A(正常 */ /*的狀態(tài)字節(jié)值為9D),并且讀寫數(shù)據(jù)均不準(zhǔn)確,所以應(yīng)當(dāng)保證卡片的供電電壓不超過 */ /*4.25V。 */ /*SPI規(guī)范:Data is always clocked into the device on the rising edge of SCK a-*/ /* nd clocked out of the device on the falling edge of SCK.All instruction-*/ /* s,addresses and data are transferred with the most significant bit(MSB) */ /* first. */ /* 2005-06-02*/
#define UCHAR unsigned char #define UINT unsigned int
sbit SPI_CS = P2^2; sbit SPI_SCK = P2^4; sbit SPI_SO = P2^6; sbit SPI_SI = P2^5;
sbit SPI_RESET = P2^3; sbit SPI_WP = P2^1;
unsigned char SPI_HostReadByte(void){ unsigned char i,rByte=0; for(i=0;i<8;i++){ SPI_SCK=0;
SPI_SCK=1; rByte<<=1; rByte =SPI_SO; } return rByte; } void SPI_HostWriteByte(unsigned char wByte){ unsigned char i; for(i=0;i<8;i++){ if((wByte<<i)&0x80) {SPI_SI=1;} else {SPI_SI=0;} SPI_SCK=0;
SPI_SCK=1;
} }
/*Status Register Format: */ /* ----------------------------------------------------------------------- */ /* bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 */ /* -------- -------- -------- -------- -------- -------- -------- -------- */ /* RDY/BUSY COMP 0 1 1 1 X X */ /* ----------------------------------------------------------------------- */ /* bit7 - 忙標(biāo)記,0為忙1為不忙。 */ |