下面的代码,是从c++的代码转化过来的
#include <reg51.h>
#define uint unsigned int #define uchar unsigned char
#define AT45DB161D_READ_MANUFACTURER_AND_DEVICE_ID 0x9F
struct ATD45DB161D_ID
{ uint manufacturer; uint device[2]; uint extendedInfoLength;
};
void ReadManufacturerAndDeviceID(struct ATD45DB161D_ID *id);
/****************************************************/
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; } }
/****************************************************/
void ReadManufacturerAndDeviceID(struct ATD45DB161D_ID *id) { SPI_CS=1; SPI_CS=0; SPI_HostWriteByte(0x9f);
id->manufacturer = SPI_HostReadByte();
SPI_HostWriteByte(0xff);
id->device[0] = SPI_HostReadByte();
SPI_HostWriteByte(0xff);
id->device[1] = SPI_HostReadByte();
SPI_HostWriteByte(0xff);
id->extendedInfoLength = SPI_HostReadByte(); }
ReadManufacturerAndDeviceID(struct ATD45DB161D_ID *id)这个函数只能读出厂家id;1f,而容量id,无法读出,错在那呢
结构体里定义的变量都是uint型,改称uchar才能读出厂家id;1f,这是为啥?
|