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

📄 nrf.s

📁 atmega128单片机上实现的nrf905无线收发程序
💻 S
字号:
	.module nrf.c
	.area data(ram, con, rel)
_broad_addr::
	.blkb 2
	.area idata
	.byte 255,255
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 255,255
	.area data(ram, con, rel)
	.dbfile E:\心电监护系统\测试程序\第一阶段\无线测试\发送端\nrf.c
	.dbsym e broad_addr _broad_addr A[4:4]c
	.area text(rom, con, rel)
	.dbfile E:\心电监护系统\测试程序\第一阶段\无线测试\发送端\nrf.c
	.dbfunc e init_905 _init_905 fV
	.even
_init_905::
	.dbline -1
	.dbline 14
; 
; #include "spi.h"
; #include "common.h"
; #include "nrf.h"
; 
; unsigned char  broad_addr[4]={0xff,0xff,0xff,0xff};                   //4字节的广播地址
; unsigned char  data_conf[10];
; /**************************************************
; 函数功能:初始化nRF905,
; 输入参数:无
; 输出参数:无
; **************************************************/
; void init_905(void)
; {
	.dbline 15
; 	DDRE|=(1<<CSN)|(1<<PWR_UP)|(1<<TX_EN);//设置端口E的1,2,3引脚为输出引脚
	in R24,0x2
	ori R24,14
	out 0x2,R24
	.dbline 16
; 	DDRB|=(1<<MOSI)|(1<<SCK)|(1<<TRX_CE);//设置MOSI、SCK和SS 为输出,其他为输入 
	in R24,0x17
	ori R24,7
	out 0x17,R24
	.dbline 18
; 	
; 	PORTE |=(1<<PWR_UP);              //905上电
	sbi 0x3,2
	.dbline 19
; 	PORTE |=(1<<CSN);                //CSN引脚置位,停止SPI操作,
	sbi 0x3,1
	.dbline 21
; 	
; 	PORTB |=1<<SCK;                    // Spi clock line init high	
	sbi 0x18,1
	.dbline 23
; 	   
; 	PORTE &=~(1<<TX_EN);                 
	cbi 0x3,3
	.dbline 24
; 	PORTB &=~(1<<TRX_CE);               // Set nRF905 in standby mode
	cbi 0x18,0
	.dbline 26
; 
; 	Delay3ms();
	xcall _Delay3ms
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_confword _set_confword fV
;         r_addr -> R16,R17
	.even
_set_confword::
	.dbline -1
	.dbline 35
; }
; 
; /**************************************************
; 函数功能:设置配置字
; 输入参数:905的接收地址
; 输出参数:无
; **************************************************/
; void set_confword(unsigned char*r_addr)
; { 
	.dbline 37
;  
;   data_conf[0]=0x01;                  //
	ldi R24,1
	sts _data_conf,R24
	.dbline 38
;   data_conf[1]=0x0c;                  //不重发数据,接收模式为正常模式,输出功率为10dB("11"),工作在433MHz
	ldi R24,12
	sts _data_conf+1,R24
	.dbline 39
;   data_conf[2]=0x44;                  //4字节的接收地址和发送地址
	ldi R24,68
	sts _data_conf+2,R24
	.dbline 41
;                
;   data_conf[3]=PACKAGE_LENGTH;         //RX有效数据长度
	ldi R24,21
	sts _data_conf+3,R24
	.dbline 42
;   data_conf[4]=PACKAGE_LENGTH;         //TX有效数据长度
	sts _data_conf+4,R24
	.dbline 44
; 
;   data_conf[5]=r_addr[0];                //5~8为RX地址
	movw R30,R16
	ldd R2,z+0
	sts _data_conf+5,R2
	.dbline 45
;   data_conf[6]=r_addr[1];                                   
	ldd R2,z+1
	sts _data_conf+6,R2
	.dbline 46
;   data_conf[7]=r_addr[2];
	movw R30,R16
	ldd R2,z+2
	sts _data_conf+7,R2
	.dbline 47
;   data_conf[8]=r_addr[3];
	movw R30,R16
	ldd R2,z+3
	sts _data_conf+8,R2
	.dbline 49
;   
;   data_conf[9]=0xd8;
	ldi R24,216
	sts _data_conf+9,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbsym r r_addr 16 pc
	.dbend
	.dbfunc e send_conf _send_conf fV
;              i -> R20
	.even
_send_conf::
	xcall push_gset1
	.dbline -1
	.dbline 59
;  
; }
; 
; /************************************************************
; 函数功能:发送配置字 ,通过SPI口把设定的配置寄存器的值写入到905
; 输入参数:无
; 输出参数:无
; *************************************************************/
; void send_conf(void)
; {
	.dbline 62
;   unsigned char  i;		
;   			
;   PORTE &=~(1<<CSN);			// Spi enable for write a spi command
	cbi 0x3,1
	.dbline 63
;   SpiWrite(WC);				// Write config command写放配置命令
	clr R16
	xcall _SpiWrite
	.dbline 65
;   
;   for (i=0;i<10;i++)	// Write configration words  写放配置字
	clr R20
	xjmp L16
L13:
	.dbline 66
	.dbline 67
	ldi R24,<_data_conf
	ldi R25,>_data_conf
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	xcall _SpiWrite
	.dbline 68
L14:
	.dbline 65
	inc R20
L16:
	.dbline 65
	cpi R20,10
	brlo L13
	.dbline 70
;   {
; 	SpiWrite(data_conf[i]);
;   }
;   
;   PORTE |=(1<<CSN);						// Disable Spi
	sbi 0x3,1
	.dbline -2
L12:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e set_Tmode _set_Tmode fV
	.even
_set_Tmode::
	.dbline -1
	.dbline 79
; }
; 
; /***************************************************************
; 函数功能:把905配置成发送模式
; 输入参数:无
; 输出参数:无
; ***************************************************************/
; void set_Tmode(void)
; {	
	.dbline 80
; 	PORTE |=(1<<PWR_UP);              //905上电
	sbi 0x3,2
	.dbline 81
; 	PORTE |=(1<<TX_EN); 
	sbi 0x3,3
	.dbline 82
; 	PORTB &=~(1<<TRX_CE);
	cbi 0x18,0
	.dbline 83
; 	Delay650us(); 					// delay for mode change(>=650us)
	xcall _Delay650us
	.dbline -2
L17:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_Rmode _set_Rmode fV
	.even
_set_Rmode::
	.dbline -1
	.dbline 92
; }
; 
; /***************************************************************
; 函数功能:把905配置成接收模式
; 输入参数:无
; 输出参数:无
; ***************************************************************/
; void set_Rmode(void)
; {
	.dbline 93
; 	PORTE |=(1<<PWR_UP);              //905上电
	sbi 0x3,2
	.dbline 94
; 	PORTE &=~(1<<TX_EN); 
	cbi 0x3,3
	.dbline 95
; 	PORTB |=(1<<TRX_CE);
	sbi 0x18,0
	.dbline 96
; 	Delay650us(); 					// delay for mode change(>=650us)				
	xcall _Delay650us
	.dbline -2
L18:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_Powerdownmode _set_Powerdownmode fV
	.even
_set_Powerdownmode::
	.dbline -1
	.dbline 105
; }
; 
; /***************************************************************
; 函数功能:把905配置成掉电和SPI模式(节省能量)
; 输入参数:无
; 输出参数:无
; ***************************************************************/
; void set_Powerdownmode(void)
; {
	.dbline 106
;     PORTE &=~(1<<PWR_UP);                   //掉电
	cbi 0x3,2
	.dbline 107
; 	Delay650us(); 					// delay for mode change(>=650us)	
	xcall _Delay650us
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_STmode _set_STmode fV
	.even
_set_STmode::
	.dbline -1
	.dbline 116
; }
; 
; /***************************************************************
; 函数功能:把905配置成STANDBY和SPI模式(节省能量)
; 输入参数:无
; 输出参数:无
; ***************************************************************/
; void set_STmode(void)
; {
	.dbline 117
;     PORTE |=(1<<PWR_UP);              //905上电
	sbi 0x3,2
	.dbline 118
; 	PORTB &=~(1<<TRX_CE); 
	cbi 0x18,0
	.dbline 119
; 	Delay3ms(); 					// delay for mode change(>=650us)	
	xcall _Delay3ms
	.dbline -2
L20:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_Taddr _set_Taddr fV
;              i -> R20,R21
;           addr -> R22,R23
	.even
_set_Taddr::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 130
; }
; 
; 
; 
; /**************************************************************************
; 函数功能:通过SPI设定905的发送地址
; 输入参数:发送地址数据的首地址
; 输出参数:无
; **************************************************************************/
; void set_Taddr(unsigned char*addr)
; {
	.dbline 132
;     unsigned i;
; 	PORTE &=~(1<<CSN);						// Spi 使能
	cbi 0x3,1
	.dbline 133
; 	SpiWrite(WTA);
	ldi R16,34
	xcall _SpiWrite
	.dbline 135
; 					                        // Write address command
; 	for (i=0;i<4;i++)			                // Write 4 bytes address
	clr R20
	clr R21
	xjmp L25
L22:
	.dbline 136
	.dbline 137
	movw R30,R20
	add R30,R22
	adc R31,R23
	ldd R16,z+0
	xcall _SpiWrite
	.dbline 138
L23:
	.dbline 135
	subi R20,255  ; offset = 1
	sbci R21,255
L25:
	.dbline 135
	cpi R20,4
	ldi R30,0
	cpc R21,R30
	brlo L22
	.dbline 140
; 	{
; 		SpiWrite(addr[i]);
; 	}	
; 	
; 	PORTE |=(1<<CSN);						   // 禁止Spi 
	sbi 0x3,1
	.dbline -2
L21:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r addr 22 pc
	.dbend
	.dbfunc e TxPacket _TxPacket fV
;           temp -> <dead>
;              i -> R20
;         send_d -> R22,R23
	.even
_TxPacket::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 150
; 	//Delay300us();
; } 
; 
; /**************************************************************************
; 函数功能:905发送一个数据包
; 输入参数:要发送的数据包的首地址
; 输出参数:无
; **************************************************************************/
; void TxPacket(unsigned char*send_d)
; {
	.dbline 153
; 	unsigned char temp,i;
; 			
; 	PORTE &=~(1<<CSN);			// CSN置零,Spi 使能
	cbi 0x3,1
	.dbline 154
; 	SpiWrite(WTP);				  // 写SPI命令
	ldi R16,32
	xcall _SpiWrite
	.dbline 156
; 
; 	for (i=0;i<PACKAGE_LENGTH;i++)
	clr R20
	xjmp L30
L27:
	.dbline 157
	.dbline 158
	mov R30,R20
	clr R31
	add R30,R22
	adc R31,R23
	ldd R16,z+0
	xcall _SpiWrite
	.dbline 159
L28:
	.dbline 156
	inc R20
L30:
	.dbline 156
	cpi R20,21
	brlo L27
	.dbline 161
; 	{	  
; 	  SpiWrite(*(send_d+i));		// 写21字节的TX数据
; 	}
; 	
; 	PORTE |=(1<<CSN);						// 禁止Spi						
	sbi 0x3,1
	.dbline 163
; 		
; 	PORTB |=(1<<TRX_CE); 					// Set TRX_CE high,开始TX数据发送
	sbi 0x18,0
	.dbline 164
; 	Delay650us();		           
	xcall _Delay650us
	.dbline 166
; 	
; 	PORTB &=~(1<<TRX_CE); 				// Set TRX_CE low,进入standby模式
	cbi 0x18,0
	.dbline -2
L26:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l temp 1 c
	.dbsym r i 20 c
	.dbsym r send_d 22 pc
	.dbend
	.dbfunc e RxPacket _RxPacket fV
;              i -> R20
;     received_d -> R22,R23
	.even
_RxPacket::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 175
; }
; 
; /***************************************************************************
; 函数功能:把905接收到的一个数据包放到CPU的接收缓冲区
; 输入参数:接收缓冲区的首地址
; 输出参数:无
; ***************************************************************************/
; void RxPacket(unsigned char*received_d)
; {
	.dbline 177
; 	unsigned char  i;
; 	PORTB &=~(1<<TRX_CE); 					// 把nRF905 设置成standby,不再接收无线数据	
	cbi 0x18,0
	.dbline 178
; 	PORTE &=~(1<<CSN);			// Spi enable for write a spi command,Spi 使能
	cbi 0x3,1
	.dbline 179
; 	SpiWrite(RRP);				  // Read payload command	
	ldi R16,36
	xcall _SpiWrite
	.dbline 180
; 	for (i=0;i<PACKAGE_LENGTH;i++)
	clr R20
	xjmp L35
L32:
	.dbline 181
	.dbline 182
	clr R16
	xcall _SpiWrite
	mov R30,R20
	clr R31
	add R30,R22
	adc R31,R23
	std z+0,R16
	.dbline 183
L33:
	.dbline 180
	inc R20
L35:
	.dbline 180
	cpi R20,21
	brlo L32
	.dbline 184
; 	{
; 		*(received_d+i)=SpiWrite(0x00);			// Read data and save to buffer		
; 	}
; 	PORTE |=(1<<CSN);						// 禁止Spi
	sbi 0x3,1
	.dbline 185
;         Delay650us();	
	xcall _Delay650us
	.dbline 186
;         PORTB |=(1<<TRX_CE);             //把nRF905 设置成RX mode
	sbi 0x18,0
	.dbline -2
L31:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r received_d 22 pc
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\心电监护系统\测试程序\第一阶段\无线测试\发送端\nrf.c
_data_conf::
	.blkb 10
	.dbsym e data_conf _data_conf A[10:10]c

⌨️ 快捷键说明

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