×
嵌入式 > 技术百科 > 详情

stm8 io口 spi模拟,可用于RC522

发布时间:2020-12-17 发布时间:
|

/////////////////////////////////////////////////////////////////////

//功    能: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);  

  

}  

 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
激光跟踪仪市场2023年有望达5.216亿美元