Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
#define <strong>RF22</strong>_PWRSTATE_READY 01<br />
#define <strong>RF22</strong>_PWRSTATE_<strong>TX</strong> 0x09<br />
Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com<br />
http://www.hoperf.com<br />
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
/******************************************************************************<br />
Title: RFM22 transmitter demo program<br />
Current version: <strong>V1.2</strong><br />
Function: Package send Demo<br />
Processor PIC16F690 DIP-20<br />
Clock: internal 8M.<br />
Operate frequency: 434MHz<br />
Data rate: 2.4kbps<br />
modulation: FSK<br />
deviation: 45K<br />
bandwidth: 94.8K<br />
frame mode: PH + FIFO<br />
payload 0x30, 0x31...0x3f, 0x78(chksum)<br />
Author : Simon.Yang<br />
Company: HopeRF microelectroni<br />
Contact: +86-0755-82973806<br />
Date: 2010-07-14<br />
The example is only for your reference.<br />
******************************************************************************/<br />
#include<br />
typedef unsigned char uchar;<br />
typedef unsigned int uint;<br />
const uchar tx_buf[17] =<br />
{0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x78};<br />
// ch8 is 140<br />
1
#define <strong>RF22</strong>_PACKET_SENT_INTERRUPT 04<br />
#define <strong>RF22</strong>_PWRSTATE_POWERDOWN 00<br />
#define nIRQ RA2<br />
#define nSEL RC6<br />
#define SDO RC7<br />
#define SDI RB4<br />
#define LED_RED RB5<br />
#define SCK RB6<br />
#define <strong>TX</strong>EN RA4<br />
#define RXEN RA5<br />
uchar count_50hz;<br />
uchar ItStatus1, ItStatus2;<br />
typedef struct<br />
{<br />
uchar reach_1s : 1;<br />
} FlagType;<br />
FlagType Flag;<br />
uchar read_8bit_data(void);<br />
void to_tx_mode(void);<br />
void to_ready_mode(void);<br />
void send_8bit_data(uchar i);<br />
void send_read_address(uchar i);<br />
void spi_write(uchar address, uchar data);<br />
void <strong>RF22</strong>_init_parameter(void);<br />
void delay_50ms(void);<br />
void delay_5ms(void);<br />
void delay_1ms(void);<br />
void port_init(void);<br />
void power_on_delay(void);<br />
uchar spi_read(uchar address);<br />
void Write0( void );<br />
void Write1( void );<br />
void timer2_init(void);<br />
void Write8bitcommand(uchar command);<br />
void to_sleep_mode(void);<br />
__CONFIG(0x3F04);<br />
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
//*****************************************************************************<br />
Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com<br />
2<br />
http://www.hoperf.com
void main()<br />
{<br />
uchar i,j,chksum;<br />
OSCCON = 0X70; // 8M crystal<br />
WDTCON = 0X00;<br />
power_on_delay();<br />
port_init();<br />
timer2_init();<br />
count_50hz = 0;<br />
Flag.reach_1s = 0;<br />
INTCON = 0xc0; // enable interrupt<br />
Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com<br />
http://www.hoperf.com<br />
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
<strong>RF22</strong>_init_parameter();<br />
while(1)<br />
{<br />
//to_sleep_mode(); //enter sleep mode<br />
if(Flag.reach_1s)<br />
{<br />
Flag.reach_1s = 0;<br />
to_tx_mode(); // TRANSIMITTE DATA<br />
}<br />
}<br />
}<br />
//*****************************************************************************<br />
//-------------------------------------------------------------void<br />
Write0( void )<br />
{<br />
SCK=0;<br />
NOP();<br />
SDI=0;<br />
NOP();<br />
SCK=1;<br />
NOP();<br />
}<br />
//-------------------------------------------------------------void<br />
Write1( void )<br />
{<br />
SCK=0;<br />
NOP();<br />
3
SDI=1;<br />
NOP();<br />
SCK=1;<br />
NOP();<br />
}<br />
//-------------------------------------------------------------void<br />
Write8bitcommand(uchar command) // keep sel to low<br />
{<br />
uchar n=8;<br />
nSEL = 1;<br />
SCK=0;<br />
nSEL=0;<br />
while(n--)<br />
{<br />
if(command&0x80)<br />
Write1();<br />
else<br />
Write0();<br />
command = command
{<br />
uchar i;<br />
for(i = 0; i
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
}<br />
//-------------------------------------------------------------void<br />
power_on_delay(void)<br />
{<br />
uint i;<br />
for(i = 0; i
and 434<br />
spi_write(0x75, 0x53); // hbsel = 0, sbsel =1 ???, fb = 19<br />
spi_write(0x76, 0x64); // 25600= 0x6400 for 434Mhz<br />
spi_write(0x77, 0x00);<br />
}<br />
//-------------------------------------------------------------void<br />
spi_write(uchar address, uchar data)<br />
{<br />
address |= 0x80;<br />
Write8bitcommand(address);<br />
send_8bit_data(data);<br />
nSEL = 1;<br />
}<br />
//-------------------------------------------------------------void<br />
send_read_address(uchar i)<br />
{<br />
i &= 0x7f;<br />
Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com<br />
http://www.hoperf.com<br />
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
for byte 0, 1,2,3<br />
spi_write(0x33, 0x42); // header 3, 2, 1,0 used for head length, fixed packet length,<br />
synchronize word length 3, 2,<br />
spi_write(0x34, 64); // 64 nibble = 32byte preamble<br />
spi_write(0x36, 0x2d); // synchronize word<br />
spi_write(0x37, 0xd4);<br />
spi_write(0x38, 0x00);<br />
spi_write(0x39, 0x00);<br />
spi_write(0x3a, 's'); // tx header<br />
spi_write(0x3b, 'o');<br />
spi_write(0x3c, 'n');<br />
spi_write(0x3d, 'g');<br />
spi_write(0x3e, 17); // total tx 17 byte<br />
// 0x52, 53, 54, 55 set to default<br />
// 0x56 ---------0x6c ??????????????????????????<br />
spi_write(0x6d, 0x0f); // set power max power<br />
spi_write(0x79, 0x0); // no hopping<br />
spi_write(0x7a, 0x0); // no hopping<br />
spi_write(0x71, 0x22); // Gfsk, fd[8] =0, no invert for Tx/Rx data, fifo mode, txclk -->gpio<br />
spi_write(0x72, 0x38); // frequency deviation setting to 45k = 72*625<br />
spi_write(0x73, 0x0);<br />
spi_write(0x74, 0x0); // no offset<br />
7
Write8bitcommand(i);<br />
}<br />
//-------------------------------------------------------------void<br />
send_8bit_data(uchar i)<br />
{<br />
uchar n = 8;<br />
SCK=0;<br />
while(n--)<br />
{<br />
if(i&0x80)<br />
Write1();<br />
else<br />
Write0();<br />
i = i
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
//delay_50ms();<br />
RXEN = 0;<br />
<strong>TX</strong>EN = 1;<br />
spi_write(0x08, 0x03); // disABLE AUTO <strong>TX</strong> MODE, enble multi packet clear fifo<br />
spi_write(0x08, 0x00); // disABLE AUTO <strong>TX</strong> MODE, enble multi packet, clear fifo<br />
// ph +fifo mode<br />
spi_write(0x34, 64); // 64 nibble = 32byte preamble<br />
spi_write(0x3e, 17); // total tx 17 byte<br />
for (i = 0; i
{<br />
;<br />
}<br />
}<br />
//--------------------------------------------------------------<br />
Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com<br />
http://www.hoperf.com<br />
<strong>RF22</strong> <strong>TX</strong> <strong>Program</strong> <strong>V1.2</strong><br />
10