📄 fasong.lst
字号:
C51 COMPILER V8.02 FASONG 04/09/2009 17:13:26 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE FASONG
OBJECT MODULE PLACED IN fasong.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE fasong.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <reg51.h>
2 #include <ABSACC.h>
3 #include <intrins.h>
4 #include <stdio.h>
5
6 //--------------------------------------------------------------------------------------------------------
---------
7 #define uint unsigned int
8 #define uchar unsigned char
9
10 //--------------------------------------------------------------------------------------------------------
---------
11 #define BYTE_BIT0 0x01
12 #define BYTE_BIT1 0x02
13 #define BYTE_BIT2 0x04
14 #define BYTE_BIT3 0x08
15 #define BYTE_BIT4 0x10
16 #define BYTE_BIT5 0x20
17 #define BYTE_BIT6 0x40
18 #define BYTE_BIT7 0x80
19 bdata unsigned char DATA_BUF;
20 extern uchar bai,shi,ge;
21 #define DATA7 ((DATA_BUF&BYTE_BIT7) != 0)
22 #define DATA0 ((DATA_BUF&BYTE_BIT0) != 0)
23 sbit flag =DATA_BUF^7;
24 sbit flag1 =DATA_BUF^0;
25 //--------------------------------------------------------------------------------------------------------
---------
26 #define TxRxBuf_Len 4
27 unsigned char TxRxBuf[TxRxBuf_Len];
28
29
30 //--------------------------------------------------NRF905端口配置----------------------------------------
---------
31 sbit TXEN=P1^0;
32 sbit TRX_CE=P3^4;
33 sbit PWR=P1^1;
34 sbit MISO=P1^6;
35 sbit MOSI=P1^5;
36 sbit SCK=P1^7;
37 sbit CSN=P1^3;
38 sbit AM=P1^4;
39 sbit DR=P3^2;
40 sbit CD=P1^2;
41 //---------------------------------------------------NRF905寄存器配置-------------------------------------
---------------
42 unsigned char idata RFConf[11]=
43 {
44 0x00, //配置命令//
45 0x4c, //CH_NO,配置频段在423MHZ
46 0x0C, //输出功率为10db,不重发,节电为正常模式
47 0x44, //地址宽度设置,为4字节
48 0x04,0x04, //接收发送有效数据长度为32字节
49 0xCC,0xCC,0xCC,0xCC, //接收地址
50 0x58, //CRC充许,8位CRC校验,外部时钟信号不使能,16M晶振
C51 COMPILER V8.02 FASONG 04/09/2009 17:13:26 PAGE 2
51 };
52 code TxAddress[4]={0xcc,0xcc,0xcc,0xcc};
53 //----------------------------------------------------NRF905控制指令--------------------------------------
---------
54 #define WC 0x00
55 #define RC 0x10
56 #define WTP 0x20
57 #define RTP 0x21
58 #define WTA 0x22
59 #define RTA 0x23
60 #define RRP 0x24
61 //----------------------------------------------------延时------------------------------------------------
-------
62 static void Delay(uchar n)
63 {
64 1 uint i;
65 1 while(n--)
66 1 for(i=0;i<80;i++);
67 1 }
68 //---------------------------------------------------SPI写函数--------------------------------------------
---------
69 void SpiWrite(unsigned char send)
70 {
71 1 unsigned char i;
72 1 DATA_BUF=send;
73 1 for (i=0;i<8;i++)
74 1 {
75 2 if (DATA7) //总是发送最高位
76 2 {
77 3 MOSI=1;
78 3 }
79 2 else
80 2 {
81 3 MOSI=0;
82 3 }
83 2 SCK=1;
84 2 DATA_BUF=DATA_BUF<<1;
85 2 SCK=0;
86 2 }
87 1 }
88 //---------------------------------------------------初始化nRF905状态-------------------------------------
-------------
89 extern void nRF905Init(void)
90 {
91 1 CSN=1; // Spi disable
92 1 SCK=0; // Spi clock line init low
93 1 DR=0; // Init DR for input
94 1 AM=0; // Init AM for input
95 1 CD=0; // Init CD for input
96 1 PWR=1; // nRF905 power on
97 1 TRX_CE=0; // Set nRF905 in standby mode
98 1 TXEN=0; // set radio in Rx mode
99 1 }
100 //---------------------------------------------------初始化NRF905寄存器-----------------------------------
----------
101 extern void Config905(void)
102 {
103 1 uchar i;
104 1 CSN=0; // Spi enable for write a spi command
105 1 //SpiWrite(WC); // Write config command写放配置命令
106 1 for (i=0;i<11;i++) // Write configration words 写放配置字
107 1 {
C51 COMPILER V8.02 FASONG 04/09/2009 17:13:26 PAGE 3
108 2 SpiWrite(RFConf[i]);
109 2 }
110 1 CSN=1; // Disable Spi
111 1 }
112 //----------------------------------------------------数据打包--------------------------------------------
---------------------
113 void TxPacket(void)
114 {
115 1 uchar i;
116 1 //Config905();
117 1 CSN=0;
118 1 SpiWrite(WTP); // Write payload command
119 1 for (i=0;i<4;i++)
120 1 {
121 2 SpiWrite(TxRxBuf[i]); // Write 32 bytes Tx data
122 2 }// Spi enable for write a spi command
123 1 CSN=1;
124 1 Delay(1); // Spi disable
125 1 CSN=0; // Spi enable for write a spi command
126 1 SpiWrite(WTA); // Write address command
127 1 for (i=0;i<4;i++) // Write 4 bytes address
128 1 {
129 2 SpiWrite(TxAddress[i]);
130 2 }
131 1 CSN=1; // Spi disable
132 1 TRX_CE=1; // Set TRX_CE high,start Tx data transmission
133 1 Delay(1); // while (DR!=1);
134 1 TRX_CE=0; // Set TRX_CE low
135 1 }
136 //----------------------------------------------------设置发送状态----------------------------------------
----------
137 void SetTxMode(void)
138 {
139 1 TRX_CE=0;
140 1 TXEN=1;
141 1 Delay(1); // delay for mode change(>=650us)
142 1 }
143 //-----------------------------------------------------数据发送-------------------------------------------
---------
144 extern void TX(void)
145 {
146 1 SetTxMode();// Set nRF905 in Tx mode
147 1 TxPacket();// Send data by nRF905
148 1 // SetRF_PA_PWR(unsigned char i); //设置发射功率
149 1 }
150
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 181 ----
CONSTANT SIZE = 8 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 5 ----
IDATA SIZE = 11 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -