📄 spi.c.bak
字号:
//#include <MC68HC908JB16.h> /* include peripheral declarations */
//#define GDO0_PIN PTA_PTA4 //input
#define GDO2_PIN PTA_PTA4 //input
#define CC2500_MISO PTA_PTA6 // Master In / Slave Out (input)
#define CC2500_MOSI PTA_PTA5
#define CC2500_SCK PTA_PTA7 // Serial Clock (output)
#define CC2500_NCS PTE_PTE1 // Slave Select (output to chip select)
#define delayus() asm("nop;nop;nop;nop")
/**************************************************
Name: IO_RP_Init
Descrip: 系统IO初始化
Input: 无
Output: 无
***************************************************/
unsigned char const rr[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
/*void SPI_Reset()
{
CC2500_MOSI = 0;
CC2500_MISO = 0;
CC2500_SCK = 0;
CC2500_NCS = 0;
delayus();
} */
//write one byte to spi
void SPIPut (char SPI_byte)
{
unsigned char SPI_count; // counter for SPI transaction
//DisableInterrupts;
for (SPI_count = 0; SPI_count < 8; SPI_count++) // single byte SPI loop
{
if((SPI_byte &rr[SPI_count] /*0x80*/)>0) // put current outgoing bit on MOSI
CC2500_MOSI=1;
else
CC2500_MOSI=0;
CC2500_SCK = 0x01; // set SCK high
// SPI_byte = SPI_byte << 1; // shift next bit into MSB
//SPI_byte |= MISO; // capture current bit on MISO
// delayus();
CC2500_SCK = 0x00; // set SCK low
}
// EnableInterrupts;
}
//read one byte from spi
unsigned char SPIGet ()
{
unsigned char SPI_count,SPI_data; // counter for SPI transaction
//DisableInterrupts;
SPI_data =0;
for (SPI_count = 0; SPI_count < 8; SPI_count++) // single byte SPI loop
{
// SPI_data = SPI_data << 1; // shift next bit into MSB
CC2500_SCK = 0x01; // set SCK high
//delayus();
// SPI_data |= CC2500_MISO; // put current outgoing bit on MOSI
if(CC2500_MISO)
SPI_data|=rr[SPI_count];
CC2500_SCK = 0x00; // set SCK low
//delayus();
}
//EnableInterrupts;
return SPI_data;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -