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

📄 nrf905.s

📁 嵌入式单片机控制温度传感的无线收发方案!
💻 S
📖 第 1 页 / 共 2 页
字号:
	.dbline 215
;   SET(PORTD,PWR);
	sbi 0x12,5
	.dbline 216
;   CLR(PORTD,TX_EN);//maybe first
	cbi 0x12,7
	.dbline 217
;   SET(PORTD,TRXCE);
	sbi 0x12,6
	.dbline -2
	.dbline 218
; }
L20:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_TxSend _nrf905_TxSend fV
	.even
_nrf905_TxSend::
	.dbline -1
	.dbline 221
; //->ShockBurst Send
; void nrf905_TxSend(void)
; {
	.dbline 222
;   SET(PORTD,TRXCE);
	sbi 0x12,6
	.dbline 223
;   delay_us(20);//>10us
	ldi R16,20
	ldi R17,0
	rcall _delay_us
	.dbline 224
;   CLR(PORTD,TRXCE);//只发送一次
	cbi 0x12,6
	.dbline -2
	.dbline 226
; 
; }
L21:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_TxOn _nrf905_TxOn fV
	.even
_nrf905_TxOn::
	.dbline -1
	.dbline 232
; 
; /*-----------------------------------------------
;      设置为发送模式  
; ------------------------------------------------*/ 
; void nrf905_TxOn(void)
; {
	.dbline 233
;   SET(PORTD,PWR);
	sbi 0x12,5
	.dbline 234
;   SET(PORTD,TX_EN);
	sbi 0x12,7
	.dbline 235
;   CLR(PORTD,TRXCE);
	cbi 0x12,6
	.dbline -2
	.dbline 236
; }
L22:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_Init _nrf905_Init fV
	.even
_nrf905_Init::
	.dbline -1
	.dbline 240
; 
; //初始化nrf905
; void nrf905_Init(void)
; {
	.dbline 241
;    nrf905_StandBy();
	rcall _nrf905_StandBy
	.dbline 242
;    delay_10ms(2);//!!!must >3ms
	ldi R16,2
	ldi R17,0
	rcall _delay_10ms
	.dbline 243
;    nrf905_Config();
	.dbline -2
	.dbline 247
;    
;  // nrf905_SpiTest();//test... 测试:通过读配置,判断SPI操作是否正确
;   // nrf905_RxOn();//enable nrf905接收
; }
L23:
	.dbline 0 ; func end
	rjmp _nrf905_Config
	.dbend
	.dbfunc e nrf905_SpiTest _nrf905_SpiTest fV
;              i -> R20
	.even
_nrf905_SpiTest::
	rcall push_gset1
	.dbline -1
	.dbline 252
; 
; 
; //测试:通过读配置,判断SPI操作是否正确
; void nrf905_SpiTest(void)
; {
	.dbline 254
;   uchar i;
;   CLR(PORTB,CSN);                   
	cbi 0x18,2
	.dbline 255
;   nrf905_SpiRW(RC);  //读配置
	ldi R16,16
	rcall _nrf905_SpiRW
	.dbline 256
;   for (i=0;i<10;i++)
	clr R20
	rjmp L28
L25:
	.dbline 257
	.dbline 258
	clr R16
	rcall _nrf905_SpiRW
	ldi R24,<_Rx_Buf
	ldi R25,>_Rx_Buf
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 259
L26:
	.dbline 256
	inc R20
L28:
	.dbline 256
	cpi R20,10
	brlo L25
	.dbline 260
;   { 
;    Rx_Buf[i]=nrf905_SpiRW(0);//read from nrf905
;   }
;   SET(PORTB,CSN);  
	sbi 0x18,2
	.dbline -2
	.dbline 262
; 
; }
L24:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e nrf905_SetTxAddr _nrf905_SetTxAddr fV
	.even
_nrf905_SetTxAddr::
	rcall push_gset2
	.dbline -1
	.dbline 267
; 
; 
; //写Tx地址
; void nrf905_SetTxAddr(void)
; {
	.dbline 268
;   CLR(PORTB,CSN);                   
	cbi 0x18,2
	.dbline 269
;   nrf905_SpiRW(WTA);  //写Tx地址  
	ldi R16,34
	rcall _nrf905_SpiRW
	.dbline 270
;   nrf905_SpiRW(TX_ADDRESS_0);
	ldi R24,24
	ldi R25,0
	lds R4,_TX_ADDRESS+2
	lds R5,_TX_ADDRESS+2+1
	lds R2,_TX_ADDRESS
	lds R3,_TX_ADDRESS+1
	st -y,R24
	movw R16,R2
	movw R18,R4
	rcall lsr32
	rcall _nrf905_SpiRW
	.dbline 271
;   nrf905_SpiRW(TX_ADDRESS_1);
	ldi R20,255
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R4,_TX_ADDRESS+2
	lds R5,_TX_ADDRESS+2+1
	lds R2,_TX_ADDRESS
	lds R3,_TX_ADDRESS+1
	movw R2,R4
	clr R4
	clr R5
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	mov R16,R2
	rcall _nrf905_SpiRW
	.dbline 272
;   nrf905_SpiRW(TX_ADDRESS_2);
	ldi R24,8
	ldi R25,0
	lds R4,_TX_ADDRESS+2
	lds R5,_TX_ADDRESS+2+1
	lds R2,_TX_ADDRESS
	lds R3,_TX_ADDRESS+1
	st -y,R24
	movw R16,R2
	movw R18,R4
	rcall lsr32
	movw R2,R16
	movw R4,R18
	ldi R20,255
	ldi R21,0
	ldi R22,0
	ldi R23,0
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	mov R16,R2
	rcall _nrf905_SpiRW
	.dbline 273
;   nrf905_SpiRW(TX_ADDRESS_3);
	ldi R20,255
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R4,_TX_ADDRESS+2
	lds R5,_TX_ADDRESS+2+1
	lds R2,_TX_ADDRESS
	lds R3,_TX_ADDRESS+1
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	mov R16,R2
	rcall _nrf905_SpiRW
	.dbline 274
;   SET(PORTB,CSN);  
	sbi 0x18,2
	.dbline -2
	.dbline 275
; }
L29:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_SetData _nrf905_SetData fV
;              i -> R20
	.even
_nrf905_SetData::
	rcall push_gset1
	.dbline -1
	.dbline 279
; 
; //写Tx数据
; void nrf905_SetData(void)
; {uchar i;
	.dbline 281
;   
;   CLR(PORTB,CSN);                   
	cbi 0x18,2
	.dbline 282
;   nrf905_SpiRW(WTP);  //写TxPayload 
	ldi R16,32
	rcall _nrf905_SpiRW
	.dbline 283
;   for (i=0;i<SIZE;i++)
	clr R20
	rjmp L34
L31:
	.dbline 284
	.dbline 285
	ldi R24,<_Tx_Buf
	ldi R25,>_Tx_Buf
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	rcall _nrf905_SpiRW
	.dbline 286
L32:
	.dbline 283
	inc R20
L34:
	.dbline 283
	cpi R20,32
	brlo L31
	.dbline 288
;   { 
;     nrf905_SpiRW(Tx_Buf[i]);
;   }
;   
;   SET(PORTB,CSN);  
	sbi 0x18,2
	.dbline -2
	.dbline 290
;  
; }
L30:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e nrf905_WaitSended _nrf905_WaitSended fV
	.even
_nrf905_WaitSended::
	.dbline -1
	.dbline 294
; 
; //等待发送结束
; void nrf905_WaitSended(void)
; {
L36:
	.dbline 295
L37:
	.dbline 295
;    while ((PIND&(1<<DR))==0);
	sbis 0x10,2
	rjmp L36
	.dbline -2
	.dbline 296
; }
L35:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e nrf905_SendData _nrf905_SendData fV
	.even
_nrf905_SendData::
	.dbline -1
	.dbline 300
; 
; //发送TxBuf中的数据
; void nrf905_SendData(void)
; {
	.dbline 301
;    nrf905_TxOn();//切换到发送模式
	rcall _nrf905_TxOn
	.dbline 302
;    delay_10ms(2);
	ldi R16,2
	ldi R17,0
	rcall _delay_10ms
	.dbline 303
;    nrf905_SetTxAddr();//写发送地址WTA
	rcall _nrf905_SetTxAddr
	.dbline 304
;    nrf905_SetData();//写数据WTP
	rcall _nrf905_SetData
	.dbline 305
;    nrf905_TxSend();//启动发送
	rcall _nrf905_TxSend
	.dbline 306
;   nrf905_WaitSended();//等待发送结束
	.dbline -2
	.dbline 308
;    
; }
L39:
	.dbline 0 ; func end
	rjmp _nrf905_WaitSended
	.dbend
	.dbfunc e nrf905_SendAgain _nrf905_SendAgain fV
	.even
_nrf905_SendAgain::
	.dbline -1
	.dbline 312
; 
; //测试直接重新发送上次写入的数据
; void nrf905_SendAgain(void)
; {
	.dbline 313
;    nrf905_TxOn();
	rcall _nrf905_TxOn
	.dbline 314
;    nrf905_TxSend();
	rcall _nrf905_TxSend
	.dbline 315
;    nrf905_WaitSended();
	.dbline -2
	.dbline 317
;    
; }
L40:
	.dbline 0 ; func end
	rjmp _nrf905_WaitSended
	.dbend
	.dbfunc e RfSendProc _RfSendProc fV
	.even
_RfSendProc::
	.dbline -1
	.dbline 323
; 
; 
; 
; //发送测试
; void RfSendProc(void)
; {
	.dbline 325
;   // puts_hh("Into send process code");
;    nrf905_SendData();//发送测试数据
	rcall _nrf905_SendData
	.dbline 326
;    nrf905_Off();//断开电源
	rcall _nrf905_Off
	.dbline 327
;    nrf905_RxOn();
	.dbline -2
	.dbline 329
;    
; }
L41:
	.dbline 0 ; func end
	rjmp _nrf905_RxOn
	.dbend
	.dbfunc e nrf905_ReadData _nrf905_ReadData fV
;              i -> R20
	.even
_nrf905_ReadData::
	rcall push_gset1
	.dbline -1
	.dbline 335
; 
; //读出接收到的数据
; //读出的数据Rx_Buf[0]是子机地址,Rx_Buf[2]和Rx_Buf[3]是温度数据,
; //Rx_Buf[4]和Rx_Buf[5]是子机电源电压数据,Rx_Buf[1]是命令字
; void nrf905_ReadData(void)
; {
	.dbline 338
;   uchar i;
;   
;   clear_Rx_Buf();//先清空接收缓冲
	rcall _clear_Rx_Buf
	.dbline 339
;   CLR(PORTD,TRXCE);
	cbi 0x12,6
	.dbline 340
;   CLR(PORTB,CSN);                   
	cbi 0x18,2
	.dbline 341
;   nrf905_SpiRW(RRP);  //读RxPayload 
	ldi R16,36
	rcall _nrf905_SpiRW
	.dbline 342
;   for (i=0;i<SIZE;i++)
	clr R20
	rjmp L46
L43:
	.dbline 343
	.dbline 344
	clr R16
	rcall _nrf905_SpiRW
	ldi R24,<_Rx_Buf
	ldi R25,>_Rx_Buf
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 345
L44:
	.dbline 342
	inc R20
L46:
	.dbline 342
	cpi R20,32
	brlo L43
	.dbline 347
;   { 
;     Rx_Buf[i]=nrf905_SpiRW(0);//read...
;   }
;   
;   delay_10ms(2);
	ldi R16,2
	ldi R17,0
	rcall _delay_10ms
	.dbline 348
;     SET(PORTB,CSN);  
	sbi 0x18,2
	.dbline -2
	.dbline 350
;   
; }
L42:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e RfRecvProc _RfRecvProc fV
;              i -> <dead>
	.even
_RfRecvProc::
	.dbline -1
	.dbline 353
; //接收处理
; void RfRecvProc(void)
; {
	.dbline 357
;     uchar i;
; 	
; 
;    if ((PIND&(1<<AM))==0) return;//一般先AM=1指示地址匹配对  
	sbic 0x10,3
	rjmp L48
	.dbline 357
	rjmp L47
L48:
	.dbline 358
;    if ((PIND&(1<<DR))==0) return;//DR=1时表示数据接收对而且Crc正确
	sbic 0x10,2
	rjmp L50
	.dbline 358
	rjmp L47
L50:
	.dbline 361
;    
;    //已经接收到数据
;    nrf905_ReadData();//读出...
	rcall _nrf905_ReadData
	.dbline 370
;  //  for (i=0;i<32;i++)  //校检
;   // { if (Rx_Buf[i]!=(i+i)) 
;     //    return; }
;    
;    //从机回送数据包,这样双方都能指示是否收到有效数据包
;   // #ifndef MASTER
;     // RfSendProc();
;  //  #endif
;    delay_10ms(2);
	ldi R16,2
	ldi R17,0
	rcall _delay_10ms
	.dbline 371
;    nrf905_RxOn();//使nrf905重新进入接收状态
	rcall _nrf905_RxOn
	.dbline -2
	.dbline 372
; }
L47:
	.dbline 0 ; func end
	ret
	.dbsym l i 1 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\公司用\atmega8l\final\new\nrf905_receive\nrf905.c
_Rx_Buf::
	.blkb 32
	.dbsym e Rx_Buf _Rx_Buf A[32:32]c
_Tx_Buf::
	.blkb 32
	.dbsym e Tx_Buf _Tx_Buf A[32:32]c

⌨️ 快捷键说明

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