Rev Author Line No. Line
1088 mija 1 /* mija 2008
2 demo for RFM01 - TX 868MHz
3  
4 PIC 16F84
5 xtal = 4MHz
6 */
7  
8 #include "TX_RFM02.h"
9  
10 //************************************************************************
11  
12 #define SDI PIN_B0
13 #define SCK PIN_B1
14 #define FSK PIN_B2
15 #define nIRQ PIN_B3 // input for PIC
16 #define nSEL PIN_B4
17  
18 //************************************************************************
19  
20 //unsigned int8 test[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x03b,0x3c,0x3d,0x3e,0x3f};
21 unsigned int8 test[16]="\n\r\r\rtest\n\r\r\r ";
22  
23 //************************************************************************
24  
25 void RF_INIT(void)
26 {
27 output_high(nSEL);
28 output_high(SDI);
29 output_low(SCK);
30 input(nIRQ);
31 }
32  
33 void RF_WRITE_CMD(unsigned int16 cmd)
34 {
35 unsigned int8 i;
36  
37 output_low(SCK);
38 output_low(nSEL);
39 for (i=0;i<16;i++)
40 {
41 output_low(SCK);
42 if (cmd & 0x8000) output_high(SDI);
43 else output_low(SDI);
44 output_high(SCK);
45 cmd <<= 1;
46 }
47 output_low(SCK);
48 output_high(nSEL);
49 }
50  
51 void RF_WRITE_DATA(unsigned int8 data)
52 {
53 unsigned int8 i;
54  
55 for (i=0;i<8;i++)
56 {
57 while (input(nIRQ));
58 while (!input(nIRQ));
59 if (data & 0x80) output_high(FSK);
60 else output_low(FSK);
61 data <<= 1;
62 }
63 }
64  
65 void main()
66 {
67 unsigned int8 i,j,ChkSum;
68  
69 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
70  
71 output_high(LED);
72 delay_ms(1000);
73 output_low(LED);
74 RF_INIT();
75  
76 RF_WRITE_CMD(0xCC00);
77 RF_WRITE_CMD(0x9361); // 868BAND,+/-90kHz
78 RF_WRITE_CMD(0xA640); // 868Mhz
79 RF_WRITE_CMD(0xD040); // rate/2
80 RF_WRITE_CMD(0xC823); // 4.8kbps
81 RF_WRITE_CMD(0xC220); // enable bit sync
82 RF_WRITE_CMD(0xC001); // close all
83  
84 j= ' ';
85 while (1)
86 {
87 RF_WRITE_CMD(0xC039); // start tx
88 ChkSum = 0;
89 RF_WRITE_DATA(0xAA);
90 RF_WRITE_DATA(0xAA);
91 RF_WRITE_DATA(0xAA);
92 RF_WRITE_DATA(0x2D);
93 RF_WRITE_DATA(0xD4);
94 if (j++ > '~') j = '!';
95 test[15]=j;
96 for (i=0;i<16;i++)
97 {
98 RF_WRITE_DATA(test[i]);
99 ChkSum += test[i];
100 }
101 RF_WRITE_DATA(ChkSum);
102 RF_WRITE_DATA(0xAA);
103 RF_WRITE_CMD(0xC001);
104 delay_ms(1000);
105 }
106 }
107  
108  
109