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