|
请大侠帮我看下我写的对不对?为什么感觉没写进去
void SPI_send(unsigned char dat)
{
unsigned short i=0;
for(i=0;i<8;i++)
{
SCLK=0;
if((dat&0x80)==0x80) SPI_DO=1;
else SPI_DO=0;
SCLK=1;
dat=(dat<<1);
}
SCLK=0;
}
unsigned char SPI_get(void)
{
unsigned char i=0,dat;
SCLK=0;
for(i=0;i<8;i++)
{
dat=(dat<<1);
SCLK=1;
if(SPI_DI==1) dat|=0x01;
else dat&=0x01;
SCLK=0;
}
//SCLK=0;
return dat;
}
void m25pe80_Write_nByte(unsigned long addr,unsigned char buffer[], unsigned int len)
{
unsigned int i;
opcode.dat=addr;
opcode.byte[3]=0x02;
while(m25pe80_RDSR()&0x01) ;
m25pe80_WREN();
SPI_S=0;
for(i=4;i>0;i--)
{
SPI_send(opcode.byte[i-1]);
//delay(10);
}
for(i=0;i
{
SPI_send(buffer[i]);
// delay(10);
}
// delay(10);
SPI_S=1;
m25pe80_WRDI();
}
void m25pe80_Read(unsigned long addr,unsigned int len, unsigned char *read_data)
{
unsigned int i;
opcode.dat=addr;
opcode.byte[3]=0x03;
while(m25pe80_RDSR()&0x01) ;
SPI_S=0;
//delay(1);
for(i=4;i>0;i--)
{
SPI_send(opcode.byte[i-1]);
}
for(i=0;i
{
SPI_send(0); //·¢Ëí1¸öèÎòaêy¾Y×Ö½ú
*(read_data+i)=SPI_get();
}
//delay(1);
SPI_S=1;
}
|
|