⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi.h.bak

📁 STC12LE5412RC单片机上通过nRF905芯片实现数据无线收发功能的源码。
💻 BAK
字号:
#include "reg52stc.h"
void SPIInit(void);					  //
//void SPIWrite(unsigned char);
//unsigned char SPIRead(void);
//void SPIMasterIdle(void);
unsigned char SPIReadWrite(unsigned char);

//*****************************************************//
//函数名:
//输入参数:
//输出参数:
//功能描述:
//*****************************************************//
void SPIInit(void)
{
//   P3M0  = P3M0&0xe3; //CD,AM,DR to dual port
//   P3M1  = P3M1&0xe3;
   AUXR |= 0x37;  //允许spi中断
   P1M0  = 0x00;  //preserved for 0x00 40 a0
   P1M1  = 0x00;  //set CSN to be dual port, MOSI and SCK are push pull for master in active,MISO is high impedance
   SPCTL = 0xd1;  //0xd1,CSN to decide if client,SPI enable,MSB first,SPICLK is high while idle,cpu_clock/4
   SPSTAT= 0xc0;  //clear SPIF and WCOL
}
//*****************************************************//
//函数名:
//输入参数:
//输出参数:
//功能描述:
//*****************************************************//
unsigned char SPIReadWrite(unsigned char wdata)
{
  unsigned char tdata;  
  SPSTAT=0xc0; //try
  SPDAT=wdata;
  while((SPSTAT&0x80)==0);
  tdata=SPDAT;
  return tdata;
}
//*****************************************************//
//函数名:
//输入参数:
//输出参数:
//功能描述:
//*****************************************************//
/*void SPIWrite(unsigned char wdata)
{
  unsigned char i;
  SPDAT=wdata;
  for(i=0;i<5;i++);
  while((SPSTAT&0x80)==0);
  SPSTAT=0xc0;   //reset SPIF and WCOL
}*/
//*****************************************************//
//函数名:
//输入参数:
//输出参数:
//功能描述:
//*****************************************************//
/*void SPIMasterIdle(void)
{
  P1M0=P1M0|0xA0; //set MOSI and SCK high impedance to avoid confliction
}*/

//*****************************************************//
//函数名:
//输入参数:
//输出参数:
//功能描述:
//*****************************************************//
/*unsigned char SPIRead(void)
{
   unsigned char rdata;
   while((SPSTAT&0x80)==0);
   rdata=SPDAT;
   SPSTAT=0xc0;
   return rdata;
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -