📄 24e1.c
字号:
/*=====================================================================
*
* nRF24E1矿工接收卡程序
* 2007.7.17
* 功能:
* 1.nRF24E1的初始化控制
* 2.nRF24E1的数据jieshou
*
* 济南卓越保留版权
* 版本: 0.1
*
*==============================================================================*/
#include <reg24e1.h>
bit lebal ;
unsigned char idata buf1[90];
struct RFConfig
{
unsigned char n;
unsigned char buf[15];
};
typedef struct RFConfig RFConfig;
RFConfig rconf =
{
15,
0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x41, 0x6f, 0x05
};
void Delay100us(volatile unsigned char n)
{
unsigned char i;
while(n--)
for(i=0;i<35;i++)
;
}
unsigned char SpiReadWrite(unsigned char b)
{
EXIF &= ~0x20; // Clear SPI interrupt
SPI_DATA = b; // Move byte to send to SPI data register
while((EXIF & 0x20) == 0x00) // Wait until SPI hs finished transmitting
;
return SPI_DATA;
}
void Init(void)
{ // Port ini
P0_ALT = 0x06; // Select alternate functions on pins P0.1 and P0.2, TXD RXD
// P0_DIR = 0x09; // P0.0, P0.3 is input(S1, S2), the rest output
// P0 = 0xF0; // P0.7-P0.4 = 1 for OFF LED1-LED4
//P1_DIR = 0x03; // P1.0, P1.3 is input(S3, S4),
PWR_UP = 1; // Turn on Radio
Delay100us(30); // Wait > 3ms
SPICLK = 0; // Max SPI clock (XTAL/8)
SPI_CTRL = 0x02; // Connect internal SPI controller to Radi
// serial communication ini
TH1 = 0xf3; // 9600@16MHz (when T1M=1 and SMOD=0)
CKCON |= 0x10; // T1M=1 (/4 timer clock)
PCON = 0x00; // SMOD=1 (double baud rate)
SCON = 0x52; // Serial mode1, enable receiver
TMOD = 0x20; // Timer1 8bit auto reload
TCON = 0x40; // Start timer1
}
void main(void)
{
unsigned int bn,an;
unsigned char b ,a,c ;
Init();
c=1;
lebal=0 ;
while(1)
{
CS = 1;
Delay100us(0);
for(bn=0;bn<3000;bn++)
{
an=bn;
rconf.buf[10]=bn>>8;
bn=an;
an=bn<<8;
rconf.buf[11]=bn>>8;
for(b=0;b<rconf.n;b++)
{
SpiReadWrite(rconf.buf[b]);
}
CS = 0;
CE = 1;
if(DR1 == 1)
{
if(lebal==0) //数据区无数据标志
{
c=1;
};
for(a=0;a<2;a++)
{
buf1[c]= SpiReadWrite(0);
c=c+1;
}
lebal=1;
}
CE = 0;
buf1[0]=c;
}
if(lebal==1)//与分站单片机通信
{
SBUF=0x88;
while(TI!=0);TI=0;
while(RI!=0);RI=0;
if(SBUF==0x66)
{
SBUF=buf1[0]; //fa song shu ju
while(TI!=0);TI=0;
for(c=1;c<buf1[0]+1;c++)
{
SBUF=buf1[c];
while(TI!=0);TI=0;
}
lebal=0;
}
}
else
{
SBUF=0x55;
while(TI!=0);TI=0;
};
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -