⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nrf905.s

📁 这是用C编的nrf905的通讯程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module nrf905.C
	.area data(ram, con, rel)
_X:
	.blkb 1
	.area idata
	.byte 10
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
	.dbsym s X _X c
_Y:
	.blkb 1
	.area idata
	.byte 2
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
	.dbsym s Y _Y c
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
	.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905\nrf905.C
	.dbfunc e nrf905_Config _nrf905_Config fV
	.even
_nrf905_Config::
	.dbline -1
	.dbline 136
; #include "config.h"
; #include "nrf905.h"
; #define A //对应地址
; 
; 
; uchar TxBuf[bufSIZE],RxBuf[bufSIZE];
; 
; uchar nrf905_SpiRW(uchar val);
; void nrf905_StandBy(void);
; void nrf905_Off(void);
; void nrf905_TxOn(void);
; void nrf905_TxSend(void);
; void nrf905_RxOn(void);
; void nrf905_Init(void);
; void nrf905_SpiTest(void);
; void nrf905_SetTxAddr(void);
; 
; /*-------------------------------------------------------------------------------------------
; nrf905配置寄存器宏定义 author:HotPower
;         nrf905配置寄存器(10Byte)
; 工作频率f=(422.4+CH_NO/10)*(1+HFREQ_PLL)MHz
; -------------------------------------------------------------------------------------------*/
; #ifdef A
;        #define TX_ADDRESS           0x87654321               //接收有效地址(本方)
;        #define RX_ADDRESS           0x12345678               //发送有效地址(对方)
; #endif
; #ifdef B
;  #define TX_ADDRESS           0x12345678               //接收有效地址(本方)
;  #define RX_ADDRESS           0x87654321               //发送有效地址(对方)
; #endif
; 
; #define CH_NO_FREQ_422_4MHz  0x000                     //工作频率422.4MHz(433MHz频段最低频率)
; #define CH_NO_FREQ_422_5MHz  0x001                     //工作频率422.5MHz
; #define CH_NO_FREQ_425_0MHz  0x01a                     //工作频率425.0MHz
; #define CH_NO_FREQ_427_5MHz  0x033                     //工作频率427.5MHz
; 
; #define CH_NO_FREQ_430_0MHz  0x04c                     //工作频率430.0MHz
; #define CH_NO_FREQ_433_0MHz  0x06a                     //工作频率433.0MHz(433MHz频段基准频率)
; #define CH_NO_FREQ_433_1MHz  0x06b                     //工作频率433.1MHz
; #define CH_NO_FREQ_433_2MHz  0x06c                     //工作频率433.2MHz
; #define CH_NO_FREQ_434_7MHz  0x07b                     //工作频率434.7MHz
; #define CH_NO_FREQ_473_5MHz  0x1ff                     //工作频率473.5MHz(433MHz频段最高频率)
; 
; #define CH_NO_FREQ_844_8MHz  0x000                     //工作频率844.8MHz(868MHz频段最低频率)
; 
; #define CH_NO_FREQ_862_0MHz  0x056                     //工作频率862.0MHz
; #define CH_NO_FREQ_868_0MHz  0x074                     //工作频率868.0MHz(868MHz频段基准频率)
; #define CH_NO_FREQ_868_2MHz  0x075                     //工作频率868.2MHz
; #define CH_NO_FREQ_868_4MHz  0x076                     //工作频率868.4MHz
; #define CH_NO_FREQ_869_8MHz  0x07d                     //工作频率869.8MHz
; #define CH_NO_FREQ_895_8MHz  0x0ff                     //工作频率895.8MHz
; #define CH_NO_FREQ_896_0MHz  0x100                     //工作频率896.0MHz
; #define CH_NO_FREQ_900_0MHz  0x114                     //工作频率900.0MHz
; #define CH_NO_FREQ_902_2MHz  0x11f                     //工作频率902.2MHz
; #define CH_NO_FREQ_902_4MHz  0x120                     //工作频率902.4MHz
; #define CH_NO_FREQ_915_0MHz  0x15f                     //工作频率915.0MHz(915MHz频段基准频率)
; #define CH_NO_FREQ_927_8MHz  0x19f                     //工作频率927.8MHz
; 
; #define CH_NO_FREQ_947_0MHz  0x1ff                     //工作频率947.0MHz(915MHz频段最高频率)
; 
; #define CH_NO_FREQ           CH_NO_FREQ_430_0MHz       //工作频率433.0MHz
; 
; 
; #define CH_NO_BYTE           (CH_NO_FREQ & 0xff)         //工作频率低8位       Byte0       01101100
; 
; #define AUTO_RETRAN          0x20                      //重发数据包          Byte1.5     0
; #define RX_RED_PWR           0x10                      //接收低功耗模式      Byte1.4     0
; #define PA_PWR__10dBm        0x00                      //输出功率-10dBm      Byte1.3~2   00
; #define PA_PWR_2dBm          0x04                      //输出功率+2dBm       Byte1.3~2
; #define PA_PWR_6dBm          0x08                      //输出功率+6dBm       Byte1.3~2
; #define PA_PWR_10dBm         0x0c                      //输出功率+10dBm      Byte1.3~2   
; #define HFREQ_PLL_433MHz     0x00                      //工作在433MHz频段    Byte1.1     0
; #define HFREQ_PLL_868MHz     0x02                      //工作在868MHz频段    Byte1.1
; #define HFREQ_PLL_915MHz     0x02                      //工作在915MHz频段    Byte1.1
; #define CH_NO_BIT8           (CH_NO_FREQ >> 8)           //工作频率第9位       Byte1.0     0
; 
; #define TX_AFW_1BYTE         (1 * 16)                    //发送地址宽度1字节   Byte2.7~4
; #define TX_AFW_2BYTE         (2 * 16)                    //发送地址宽度2字节   Byte2.7~4
; #define TX_AFW_3BYTE         (3 * 16)                    //发送地址宽度3字节   Byte2.7~4
; #define TX_AFW_4BYTE         (4 * 16)                    //发送地址宽度4字节   Byte2.7~4   100
; #define RX_AFW_1BYTE         1                         //接收地址宽度1字节   Byte2.3~0
; #define RX_AFW_2BYTE         2                         //接收地址宽度2字节   Byte2.3~0
; #define RX_AFW_3BYTE         3                         //接收地址宽度3字节   Byte2.3~0
; #define RX_AFW_4BYTE         4                         //接收地址宽度4字节   Byte2.3~0   100
; 
; #define RX_PW_1BYTE          1                         //接收数据宽度1字节   Byte3.5~0
; #define RX_PW_32BYTE         32                        //接收数据宽度32字节  Byte3.5~0   00100000
; #define TX_PW_1BYTE          1                         //发送数据宽度1字节   Byte4.5~0 
; #define TX_PW_32BYTE         32                        //发送数据宽度32字节  Byte4.5~0   00100000
; 
; #define RX_ADDRESS_0         (RX_ADDRESS >> 24)          //接收有效地址第1字节 Byte5       11100111
; #define RX_ADDRESS_1         ((RX_ADDRESS >> 16) & 0xff) //接收有效地址第2字节 Byte6       11100111 
; #define RX_ADDRESS_2         ((RX_ADDRESS >> 8) & 0xff)  //接收有效地址第3字节 Byte7       11100111
; #define RX_ADDRESS_3         (RX_ADDRESS & 0xff)         //接收有效地址第4字节 Byte8       11100111
;        
; #define CRC_MODE_16BIT       0x80                      //CRC16模式           Byte9.7     1
; #define CRC_MODE_8BIT        0x00                      //CRC8模式            Byte9.7     
; #define CRC_EN               0x40                      //CRC使能             Byte9.6     1
; #define CRC16_EN             0xc0                      //CRC16模式使能       Byte9.7~6   11
; #define CRC8_EN              0x40                      //CRC8模式使能        Byte9.7~6
; #define XOF_20MHz            0x20                      //晶体振荡器频率20MHz Byte9.5~3
; #define XOF_16MHz            0x18                      //晶体振荡器频率16MHz Byte9.5~3   100
; #define XOF_12MHz            0x10                      //晶体振荡器频率12MHz Byte9.5~3
; #define XOF_8MHz             0x08                      //晶体振荡器频率8MHz  Byte9.5~3
; #define XOF_4MHz             0x00                      //晶体振荡器频率4MHz  Byte9.5~3
; #define UP_CLK_EN            0x40                      //输出时钟使能        Byte9.2     1
; #define UP_CLK_FREQ_500kHz   0x03                      //输出时钟频率500kHz  Byte9.1~0   11
; #define UP_CLK_FREQ_1MHz     0x02                      //输出时钟频率1MHz    Byte9.1~0
; #define UP_CLK_FREQ_2MHz     0x01                      //输出时钟频率2MHz    Byte9.1~0
; #define UP_CLK_FREQ_4MHz     0x00                      //输出时钟频率4MHz    Byte9.1~0
; 
; #define UP_CLK_EN_500kHz     0x43                      //输出时钟频率500kHz  Byte9.2~0   111
; #define UP_CLK_EN_1MHz       0x42                      //输出时钟频率1MHz    Byte9.2~0
; #define UP_CLK_EN_2MHz       0x41                      //输出时钟频率2MHz    Byte9.2~0
; #define UP_CLK_EN_4MHz       0x40                      //输出时钟频率4MHz    Byte9.2~0
; 
; #define TX_ADDRESS_0         (TX_ADDRESS >> 24)          //发送有效地址第1字节
; #define TX_ADDRESS_1         ((TX_ADDRESS >> 16) & 0xff) //发送有效地址第2字节
; #define TX_ADDRESS_2         ((TX_ADDRESS >> 8) & 0xff)  //发送有效地址第3字节
; #define TX_ADDRESS_3         ((TX_ADDRESS >> 0) & 0xff)         //发送有效地址第4字节
; 
; /*-----------------------------------------------
;         nrf905命令控制字 author:HotPower
; ------------------------------------------------*/
; #define WC        0x00            // Write configuration register command
; #define RC        0x10            // Read  configuration register command
; #define WTP       0x20            // Write TX Payload  command
; #define RTP       0x21            // Read  TX Payload  command
; #define WTA       0x22            // Write TX Address  command
; #define RTA       0x23            // Read  TX Address  command
; #define RRP       0x24            // Read  RX Payload  command
;  
; 
; //配置nRF905
; void nrf905_Config(void)
; {
	.dbline 137
;   CLR(PORTB,CSN);                   // Spi 片选开
	cbi 0x18,4
	.dbline 138
;   nrf905_SpiRW(WC);                // Write config command
	clr R16
	xcall _nrf905_SpiRW
	.dbline 139
;   nrf905_SpiRW(CH_NO_BYTE);                      //中心频率低8位
	ldi R16,76
	xcall _nrf905_SpiRW
	.dbline 140
;   nrf905_SpiRW(PA_PWR_10dBm | HFREQ_PLL_433MHz); //发射+10dBm,发射频率433MHz,中心频率第9位=0
	ldi R16,12
	xcall _nrf905_SpiRW
	.dbline 141
;   nrf905_SpiRW(TX_AFW_4BYTE | RX_AFW_4BYTE);     //接收地址宽度4字节,发送地址宽度4字节
	ldi R16,68
	xcall _nrf905_SpiRW
	.dbline 142
;   nrf905_SpiRW(RX_PW_32BYTE);                    //接收数据宽度32字节
	ldi R16,32
	xcall _nrf905_SpiRW
	.dbline 143
;   nrf905_SpiRW(TX_PW_32BYTE);                    //发送数据宽度32字节
	ldi R16,32
	xcall _nrf905_SpiRW
	.dbline 144
;   nrf905_SpiRW(RX_ADDRESS_0);                    //接收有效地址第1字节
	ldi R16,18
	xcall _nrf905_SpiRW
	.dbline 145
;   nrf905_SpiRW(RX_ADDRESS_1);                    //接收有效地址第2字节
	ldi R16,52
	xcall _nrf905_SpiRW
	.dbline 146
;   nrf905_SpiRW(RX_ADDRESS_2);                    //接收有效地址第3字节
	ldi R16,86
	xcall _nrf905_SpiRW
	.dbline 147
;   nrf905_SpiRW(RX_ADDRESS_3);                    //接收有效地址第4字节
	ldi R16,120
	xcall _nrf905_SpiRW
	.dbline 148
;   nrf905_SpiRW(CRC16_EN | XOF_16MHz);            //CRC16模式使能,晶体振荡器频率16MHz
	ldi R16,216
	xcall _nrf905_SpiRW
	.dbline 149
;   SET(PORTB,CSN);                 // Disable Spi
	sbi 0x18,4
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_SpiRW _nrf905_SpiRW fc
;           temp -> R20
;            val -> R16
	.even
_nrf905_SpiRW::
	xcall push_gset1
	.dbline -1
	.dbline 153
; }
; 
; uchar nrf905_SpiRW(uchar val) 
; {uchar temp;
	.dbline 155
; 
;     SPDR=val;
	out 0xf,R16
L3:
	.dbline 156
L4:
	.dbline 156
; 	while ((SPSR&(1<<SPIF))==0);
	sbis 0xe,7
	rjmp L3
	.dbline 157
; 	temp=SPDR;
	in R20,0xf
	.dbline 158
; 	return temp;
	mov R16,R20
	.dbline -2
L2:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r val 16 c
	.dbend
	.dbfunc e nrf905_StandBy _nrf905_StandBy fV
	.even
_nrf905_StandBy::
	.dbline -1
	.dbline 163
; }
; 
; //PwrDown->StandBy
; void nrf905_StandBy()
; {
	.dbline 164
;    SET(PORTD,PWR);
	sbi 0x12,6
	.dbline 165
;    CLR(PORTD,TRXCE);
	cbi 0x12,3
	.dbline 166
;    CLR(PORTD,TX_EN);
	cbi 0x12,4
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_Off _nrf905_Off fV
	.even
_nrf905_Off::
	.dbline -1
	.dbline 171
; }
; 
; //->PwrDown
; void nrf905_Off()
; {
	.dbline 172
;   CLR(PORTD,PWR);
	cbi 0x12,6
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_TxOn _nrf905_TxOn fV
	.even
_nrf905_TxOn::
	.dbline -1
	.dbline 177
; }
; 
; //->ShockBurst Send
; void nrf905_TxOn()
; {
	.dbline 178
;   SET(PORTD,PWR);
	sbi 0x12,6
	.dbline 179
;   SET(PORTD,TX_EN);
	sbi 0x12,4
	.dbline 180
;   CLR(PORTD,TRXCE);
	cbi 0x12,3
	.dbline -2
L8:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_TxSend _nrf905_TxSend fV
	.even
_nrf905_TxSend::
	.dbline -1
	.dbline 185
; }
; 
; //->ShockBurst Send
; void nrf905_TxSend()
; {
	.dbline 186
;   SET(PORTD,TRXCE);
	sbi 0x12,3
	.dbline 187
;   DelayUs(20);//>10us
	ldi R16,20
	ldi R17,0
	xcall _DelayUs
	.dbline 188
;   CLR(PORTD,TRXCE);//只发送一次
	cbi 0x12,3
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_RxOn _nrf905_RxOn fV
	.even
_nrf905_RxOn::
	.dbline -1
	.dbline 193
; }
; 
; //->ShockBurst Recv
; void nrf905_RxOn()
; {
	.dbline 194
;   SET(PORTD,PWR);
	sbi 0x12,6
	.dbline 195
;   CLR(PORTD,TX_EN);//maybe first
	cbi 0x12,4
	.dbline 196
;   SET(PORTD,TRXCE);
	sbi 0x12,3
	.dbline -2
L10:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_Init _nrf905_Init fV
	.even
_nrf905_Init::
	.dbline -1
	.dbline 201
; }
; 
; //初始化nrf905
; void nrf905_Init()
; {
	.dbline 202
;    nrf905_StandBy();
	xcall _nrf905_StandBy
	.dbline 203
;    DelayMs(10);//!!!must >3ms
	ldi R16,10
	xcall _DelayMs
	.dbline 204
;    nrf905_Config();
	xcall _nrf905_Config
	.dbline 206
;    
;    nrf905_SpiTest();//test...
	xcall _nrf905_SpiTest
	.dbline 207
;    nrf905_RxOn();
	xcall _nrf905_RxOn
	.dbline -2
L11:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_SpiTest _nrf905_SpiTest fV
;              i -> R10
	.even
_nrf905_SpiTest::
	xcall push_gset3
	.dbline -1
	.dbline 212
; }
; 
; //测试:通过读配置,判断SPI操作是否正确
; void nrf905_SpiTest()
; {uchar i;
	.dbline 213
;   CLR(PORTB,CSN);                   
	cbi 0x18,4
	.dbline 214
;   nrf905_SpiRW(RC);  //读配置
	ldi R16,16

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -