/
//功 能:SPI写数据
//输 入: 无
// 无返回值
/
void Write_SPI(unsigned char num)
{
unsigned char count=0;
for(count=0;count<8;count++)
{
if((num&0x80)==0x80)
RC522_MOSI_HIGH;
else
RC522_MOSI_LOW;
asm("nop");asm("nop");
num<<=1;
RC522_SCK_LOW;
asm("nop");asm("nop");
RC522_SCK_HIGH;
asm("nop");asm("nop");
}
}
/
//功 能:SPI读数据
//输 入: 无
//返 回: 无
/
unsigned char Read_SPI(void)
{
unsigned char SPICount; // Counter used to clock out the data
unsigned char SPIData;
SPIData = 0; //下降沿有效
for (SPICount = 0; SPICount < 8; SPICount++) // Prepare to clock in the data to be read
{
SPIData <<=1; // Rotate the data
RC522_SCK_LOW;
asm("nop");asm("nop"); // Raise the clock to clock the data out of the MAX7456
if((PA_IDR & (1<<6))==(1<<6))
{
SPIData|=0x01;
}
RC522_SCK_HIGH;
asm("nop");asm("nop");
// Drop the clock ready for the next bit
} // and loop back
return (SPIData);
}
//功 能:SPI写数据
//输 入: 无
// 无返回值
/
void Write_SPI(unsigned char num)
{
unsigned char count=0;
for(count=0;count<8;count++)
{
if((num&0x80)==0x80)
RC522_MOSI_HIGH;
else
RC522_MOSI_LOW;
asm("nop");asm("nop");
num<<=1;
RC522_SCK_LOW;
asm("nop");asm("nop");
RC522_SCK_HIGH;
asm("nop");asm("nop");
}
}
/
//功 能:SPI读数据
//输 入: 无
//返 回: 无
/
unsigned char Read_SPI(void)
{
unsigned char SPICount; // Counter used to clock out the data
unsigned char SPIData;
SPIData = 0; //下降沿有效
for (SPICount = 0; SPICount < 8; SPICount++) // Prepare to clock in the data to be read
{
SPIData <<=1; // Rotate the data
RC522_SCK_LOW;
asm("nop");asm("nop"); // Raise the clock to clock the data out of the MAX7456
if((PA_IDR & (1<<6))==(1<<6))
{
SPIData|=0x01;
}
RC522_SCK_HIGH;
asm("nop");asm("nop");
// Drop the clock ready for the next bit
} // and loop back
return (SPIData);
}