📄 ex2c-tx.c
字号:
/*= ex2c-tx.c ==================================================================
*
* Copyright (C) 2004 Nordic Semiconductor
*
* This file is distributed in the hope that it will be useful, but WITHOUT
* WARRANTY OF ANY KIND.
*
* Author(s): Ole Saether
*
* DESCRIPTION:
*
* This example should be used together with ex2c-rx.c. One nRF9E5 evaluation
* board (transmitter) should be programmed with the hex-file generated from
* compiling this file and the other evaluation board (receiver) programmed
* with the hex-file generated from compiling ex2c-rx.c.
*
* All switches on the DIP-swith S206 on the receiver must be set to the "on"
* position and all switches on the DIP-swith S205 on the transmitter must be
* set to the "on" position.
*
* When one of the switched SW1-SW4 on the transmitter is pressed the
* corresponding LED on the receiver is turned on.
*
* Please set HFREQ below to a setting that matches the frequency of your
* EVBOARD. You also have to set the channel if a frequency other than the
* default is needed.
*
* COMPILER:
*
* This program has been tested with Keil C51 V7.09.
*
* $Revision: 5 $
*
*==============================================================================
*/
#include <Nordic\reg9e5.h>
#define HFREQ 0 // 0=433MHz, 1=868/915MHz
#define POWER 3 // 0=min power...3 = max power
void Delay400us(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 TransmitPacket(unsigned char b)
{
RACSN = 0;
SpiReadWrite(WTP);
SpiReadWrite(b);
RACSN = 1;
TRX_CE = 1;
Delay400us(1);
TRX_CE = 0;
}
void Transmitter(void)
{
TXEN = 1;
for(;;)
{
TransmitPacket(P0);
}
}
void Init(void)
{
unsigned char tmp;
P0_ALT = 0x00;
P0_DIR = 0xFF;
SPICLK = 0; // Max SPI clock
SPI_CTRL = 0x02; // Connect internal SPI controller to Radio
// Configure Radio:
RACSN = 0;
SpiReadWrite(WRC | 0x03); // Write to RF config address 3 (RX payload)
SpiReadWrite(0x01); // One byte RX payload
SpiReadWrite(0x01); // One byte TX payload
RACSN = 1;
RACSN = 0;
SpiReadWrite(RRC | 0x01); // Read RF config address 1
tmp = SpiReadWrite(0) & 0xf1; // Clear the power and frequency setting bits
RACSN = 1;
RACSN = 0;
SpiReadWrite(WRC | 0x01); // Write RF config address 1
// Change power defined by POWER and to 433 or 868/915MHz defined by HFREQ above:
SpiReadWrite(tmp | (POWER <<2) | (HFREQ << 1));
RACSN = 1;
}
void main(void)
{
Init();
Transmitter();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -