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

📄 main.s

📁 nRF24L01详细编程资料
💻 S
📖 第 1 页 / 共 2 页
字号:
	.dbline -2
L22:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay _delay fV
	.even
_delay::
	.dbline -1
	.dbline 208
; }
; void delay(void)//
; {
	.dbline 209
; 	NOP();
	nop
	.dbline 210
; 	NOP();
	nop
	.dbline 211
; 	NOP();
	nop
	.dbline 212
; 	NOP();
	nop
	.dbline 213
; 	NOP();
	nop
	.dbline 214
; 	NOP();
	nop
	.dbline -2
L23:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delayms _delayms fV
;            dly -> R16,R17
	.even
_delayms::
	.dbline -1
	.dbline 217
; }
; void delayms(unsigned short	dly)//
; {
	.dbline 218
; 	for(;dly>0;dly--) ;
	rjmp L28
L25:
	.dbline 218
L26:
	.dbline 218
	subi R16,1
	sbci R17,0
L28:
	.dbline 218
	cpi R16,0
	cpc R16,R17
	brne L25
X9:
	.dbline -2
L24:
	.dbline 0 ; func end
	ret
	.dbsym r dly 16 s
	.dbend
	.dbfunc e clear_buf _clear_buf fV
;         number -> R18
;            ptr -> R16,R17
	.even
_clear_buf::
	.dbline -1
	.dbline 222
; }
; 
; void clear_buf(unsigned char	*ptr,unsigned char number)//清零buffer,指定字节个数
; {
	.dbline 223
; 	for (;number>0;number--) *ptr++=0;
	rjmp L33
L30:
	.dbline 223
	clr R2
	movw R30,R16
	st Z+,R2
	movw R16,R30
L31:
	.dbline 223
	dec R18
L33:
	.dbline 223
	ldi R24,0
	cp R24,R18
	brlo L30
X10:
	.dbline -2
L29:
	.dbline 0 ; func end
	ret
	.dbsym r number 18 c
	.dbsym r ptr 16 pc
	.dbend
	.dbfunc e SPI_RW _SPI_RW fc
;        bit_ctr -> R22
;           byte -> R20
	.even
_SPI_RW::
	rcall push_xgsetF000
	mov R20,R16
	.dbline -1
	.dbline 234
; }
; //------------------------------------------------------
; /**************************************************
; Function: SPI_RW();
; 
; Description:
;   Writes one byte to nRF24L01, and return the byte read
;   from nRF24L01 during write, according to SPI protocol  */
; /**************************************************/
; unsigned char SPI_RW(unsigned char byte)
; {
	.dbline 236
; 	unsigned char  bit_ctr;	
;    	for(bit_ctr=0;bit_ctr<8;bit_ctr++)   	// output 8-bit
	clr R22
	rjmp L38
L35:
	.dbline 237
;    	{
	.dbline 238
;    		if(byte & 0x80) 
	sbrs R20,7
	rjmp L39
X11:
	.dbline 239
;    			nRF24L01_MOSIH;
	sbi 0x5,0
	rjmp L40
L39:
	.dbline 241
;    		else 
;    			nRF24L01_MOSIL;
	cbi 0x5,0
L40:
	.dbline 242
; 		delay();
	rcall _delay
	.dbline 243
;    		byte = (byte << 1);           		// shift next bit into MSB..
	lsl R20
	.dbline 244
;    		nRF24L01_SCKH;
	sbi 0x5,1
	.dbline 245
; 		delay();
	rcall _delay
	.dbline 246
;  		if(PINB&0x08) byte |= 1;
	sbis 0x3,3
	rjmp L41
X12:
	.dbline 246
	ori R20,1
L41:
	.dbline 247
;    		nRF24L01_SCKL;
	cbi 0x5,1
	.dbline 248
; 		delay();
	rcall _delay
	.dbline 249
;    	}
L36:
	.dbline 236
	inc R22
L38:
	.dbline 236
	cpi R22,8
	brlo L35
X13:
	.dbline 250
;     return(byte);           		  		// return read byte
	mov R16,R20
	.dbline -2
L34:
	.dbline 0 ; func end
	rjmp pop_xgsetF000
	.dbsym r bit_ctr 22 c
	.dbsym r byte 20 c
	.dbend
	.dbfunc e SPI_RW_Reg _SPI_RW_Reg fc
;         status -> R10
;          value -> R12
;            reg -> R10
	.even
_SPI_RW_Reg::
	rcall push_xgset003C
	mov R12,R18
	mov R10,R16
	.dbline -1
	.dbline 259
; }
; /**************************************************
; Function: SPI_RW_Reg();
; 
; Description:
;   Writes value 'value' to register 'reg' */
; /**************************************************/
; unsigned char SPI_RW_Reg(unsigned char reg, unsigned char value)
; {
	.dbline 261
; 	unsigned char status;
; 	nRF24L01_CSNL;
	cbi 0xb,6
	.dbline 262
; 	delay();
	rcall _delay
	.dbline 263
; 	status = SPI_RW(reg);      // select register
	mov R16,R10
	rcall _SPI_RW
	mov R10,R16
	.dbline 264
;   	SPI_RW(value);             // ..and write value to it..
	mov R16,R12
	rcall _SPI_RW
	.dbline 265
; 	nRF24L01_CSNH;
	sbi 0xb,6
	.dbline 266
; 	delay();
	rcall _delay
	.dbline 267
;   	return(status);            // return nRF24L01 status byte
	mov R16,R10
	.dbline -2
L43:
	.dbline 0 ; func end
	rjmp pop_xgset003C
	.dbsym r status 10 c
	.dbsym r value 12 c
	.dbsym r reg 10 c
	.dbend
	.dbfunc e SPI_Read _SPI_Read fc
;        reg_val -> R10
;            reg -> R10
	.even
_SPI_Read::
	st -y,R10
	st -y,R11
	mov R10,R16
	.dbline -1
	.dbline 276
; }
; /**************************************************
; Function: SPI_Read();
; 
; Description:
;   Read one byte from nRF24L01 register, 'reg'  */
; /**************************************************/
; unsigned char SPI_Read(unsigned char reg)
; {
	.dbline 278
; 	unsigned char reg_val;
; 	nRF24L01_CSNL;
	cbi 0xb,6
	.dbline 279
; 	delay();
	rcall _delay
	.dbline 280
;   	SPI_RW(reg);            // Select register to read from..
	mov R16,R10
	rcall _SPI_RW
	.dbline 281
;   	reg_val = SPI_RW(0);    // ..then read registervalue
	clr R16
	rcall _SPI_RW
	mov R10,R16
	.dbline 282
; 	nRF24L01_CSNH;
	sbi 0xb,6
	.dbline 283
; 	delay();
	rcall _delay
	.dbline 284
;   	return(reg_val);        // return register value
	mov R16,R10
	.dbline -2
L44:
	.dbline 0 ; func end
	ld R11,y+
	ld R10,y+
	ret
	.dbsym r reg_val 10 c
	.dbsym r reg 10 c
	.dbend
	.dbfunc e SPI_Read_Buf _SPI_Read_Buf fc
;         status -> R10
;       byte_ctr -> R12
;          bytes -> y+6
;           pBuf -> R14,R15
;            reg -> R10
	.even
_SPI_Read_Buf::
	rcall push_xgset00FC
	movw R14,R18
	mov R10,R16
	.dbline -1
	.dbline 294
; }
; /**************************************************
; Function: SPI_Read_Buf();
; 
; Description:
;   Reads 'bytes' #of bytes from register 'reg'
;   Typically used to read RX payload, Rx/Tx address */
; /**************************************************/
; unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)
; {
	.dbline 296
; 	unsigned char status,byte_ctr;
; 	nRF24L01_CSNL;
	cbi 0xb,6
	.dbline 297
; 	delay();
	rcall _delay
	.dbline 298
;   	status = SPI_RW(reg);       		// Select register to write to and read status byte
	mov R16,R10
	rcall _SPI_RW
	mov R10,R16
	.dbline 299
; 	for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
	clr R12
	rjmp L49
L46:
	.dbline 300
;     	pBuf[byte_ctr] = SPI_RW(0);    // Perform SPI_RW to read byte from nRF24L01
	clr R16
	rcall _SPI_RW
	mov R30,R12
	clr R31
	add R30,R14
	adc R31,R15
	std z+0,R16
L47:
	.dbline 299
	inc R12
L49:
	.dbline 299
	ldd R0,y+6
	cp R12,R0
	brlo L46
X14:
	.dbline 301
; 	nRF24L01_CSNH;
	sbi 0xb,6
	.dbline 302
; 	delay();
	rcall _delay
	.dbline 303
;   	return(status);                    // return nRF24L01 status byte
	mov R16,R10
	.dbline -2
L45:
	.dbline 0 ; func end
	rjmp pop_xgset00FC
	.dbsym r status 10 c
	.dbsym r byte_ctr 12 c
	.dbsym l bytes 6 c
	.dbsym r pBuf 14 pc
	.dbsym r reg 10 c
	.dbend
	.dbfunc e SPI_Write_Buf _SPI_Write_Buf fc
;         status -> R10
;       byte_ctr -> R12
;          bytes -> y+6
;           pBuf -> R14,R15
;            reg -> R10
	.even
_SPI_Write_Buf::
	rcall push_xgset00FC
	movw R14,R18
	mov R10,R16
	.dbline -1
	.dbline 313
; }
; /**************************************************
; Function: SPI_Write_Buf();
; 
; Description:
;   Writes contents of buffer '*pBuf' to nRF24L01
;   Typically used to write TX payload, Rx/Tx address */
; /**************************************************/
; unsigned char SPI_Write_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)
; {
	.dbline 315
; 	unsigned char status,byte_ctr;
; 	nRF24L01_CSNL;                   		// Set nRF24L01_CSN low, init SPI tranaction
	cbi 0xb,6
	.dbline 316
;   	delay();
	rcall _delay
	.dbline 317
; 	status = SPI_RW(reg);    					// Select register to write to and read status byte
	mov R16,R10
	rcall _SPI_RW
	mov R10,R16
	.dbline 318
;   	for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf)
	clr R12
	rjmp L54
L51:
	.dbline 319
;     	status = SPI_RW(*pBuf++);            
	movw R30,R14
	ld R16,Z+
	movw R14,R30
	rcall _SPI_RW
	mov R10,R16
L52:
	.dbline 318
	inc R12
L54:
	.dbline 318
	ldd R0,y+6
	cp R12,R0
	brlo L51
X15:
	.dbline 320
; 	nRF24L01_CSNH; 								// Set nRF24L01_CSN high again
	sbi 0xb,6
	.dbline 321
; 	delay();
	rcall _delay
	.dbline 322
;   	return(status);          					// return nRF24L01 status byte
	mov R16,R10
	.dbline -2
L50:
	.dbline 0 ; func end
	rjmp pop_xgset00FC
	.dbsym r status 10 c
	.dbsym r byte_ctr 12 c
	.dbsym l bytes 6 c
	.dbsym r pBuf 14 pc
	.dbsym r reg 10 c
	.dbend
	.dbfunc e RX_Mode _RX_Mode fV
	.even
_RX_Mode::
	sbiw R28,1
	.dbline -1
	.dbline 335
; }
; /**************************************************
; Function: RX_Mode();
; 
; Description:
;   This function initializes one nRF24L01 device to
;   RX Mode, set RX address, writes RX payload width,
;   select RF channel, datarate & LNA HCURR.
;   After init, CE is toggled high, which means that
;   this device is now ready to receive a datapacket. */
; /**************************************************/
; void RX_Mode(void)
; {
	.dbline 336
; 	nRF24L01_CEL;
	cbi 0xb,7
	.dbline 337
; 	delay();
	rcall _delay
	.dbline 338
;   	SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // Use the same address on the RX device as the TX device
	ldi R24,5
	std y+0,R24
	ldi R18,<_TX_ADDRESS
	ldi R19,>_TX_ADDRESS
	ldi R16,42
	rcall _SPI_Write_Buf
	.dbline 340
; 
;   	SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);      // Enable Auto.Ack:Pipe0
	ldi R18,1
	ldi R16,33
	rcall _SPI_RW_Reg
	.dbline 341
;   	SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);  // Enable Pipe0
	ldi R18,1
	ldi R16,34
	rcall _SPI_RW_Reg
	.dbline 342
;   	SPI_RW_Reg(WRITE_REG + RF_CH, 40);        // Select RF channel 40
	ldi R18,40
	ldi R16,37
	rcall _SPI_RW_Reg
	.dbline 343
;   	SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH); // Select same RX payload width as TX Payload width
	ldi R18,20
	ldi R16,49
	rcall _SPI_RW_Reg
	.dbline 344
;   	SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);   // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
	ldi R18,7
	ldi R16,38
	rcall _SPI_RW_Reg
	.dbline 345
;   	SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);     // Set PWR_UP bit, enable CRC(2 bytes) & Prim:RX. RX_DR enabled..
	ldi R18,15
	ldi R16,32
	rcall _SPI_RW_Reg
	.dbline 346
;   	nRF24L01_CEH;
	sbi 0xb,7
	.dbline 347
; 	delay();
	rcall _delay
	.dbline -2
L55:
	.dbline 0 ; func end
	adiw R28,1
	ret
	.dbend
	.dbfunc e TX_Mode _TX_Mode fV
	.even
_TX_Mode::
	sbiw R28,1
	.dbline -1
	.dbline 367
; 	//  This device is now ready to receive one packet of 16 bytes payload from a TX device sending to address
;   //  '3443101001', with auto acknowledgment, retransmit count of 10, RF channel 40 and datarate = 2Mbps.
; 
; }
; /**************************************************/
; 
; /**************************************************
; Function: TX_Mode();
; 
; Description:
;   This function initializes one nRF24L01 device to
;   TX mode, set TX address, set RX address for auto.ack,
;   fill TX payload, select RF channel, datarate & TX pwr.
;   PWR_UP is set, CRC(2 bytes) is enabled, & PRIM:TX.
; 
;   ToDo: One high pulse(>10us) on CE will now send this
;   packet and expext an acknowledgment from the RX device. */
; /**************************************************/
; void TX_Mode(void)
; {
	.dbline 368
; 	nRF24L01_CEL;
	cbi 0xb,7
	.dbline 369
; 	delay();
	rcall _delay
	.dbline 370
;   	SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);    // Writes TX_Address to nRF24L01
	ldi R24,5
	std y+0,R24
	ldi R18,<_TX_ADDRESS
	ldi R19,>_TX_ADDRESS
	ldi R16,48
	rcall _SPI_Write_Buf
	.dbline 371
;   	SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // RX_Addr0 same as TX_Adr for Auto.Ack
	ldi R24,5
	std y+0,R24
	ldi R18,<_TX_ADDRESS
	ldi R19,>_TX_ADDRESS
	ldi R16,42
	rcall _SPI_Write_Buf
	.dbline 372
;   	SPI_Write_Buf(WR_TX_PLOAD, Buffer, TX_PLOAD_WIDTH); // Writes data to TX payload
	ldi R24,20
	std y+0,R24
	ldi R18,<_Buffer
	ldi R19,>_Buffer
	ldi R16,160
	rcall _SPI_Write_Buf
	.dbline 374
; 
;   	SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);      // Enable Auto.Ack:Pipe0
	ldi R18,1
	ldi R16,33
	rcall _SPI_RW_Reg
	.dbline 375
;   	SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);  // Enable Pipe0
	ldi R18,1
	ldi R16,34
	rcall _SPI_RW_Reg
	.dbline 376
;   	SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a); // 500us + 86us, 10 retrans...
	ldi R18,26
	ldi R16,36
	rcall _SPI_RW_Reg
	.dbline 377
;   	SPI_RW_Reg(WRITE_REG + RF_CH, 40);        // Select RF channel 40
	ldi R18,40
	ldi R16,37
	rcall _SPI_RW_Reg
	.dbline 378
;   	SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);   // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
	ldi R18,7
	ldi R16,38
	rcall _SPI_RW_Reg
	.dbline 379
;   	SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);     // Set PWR_UP bit, enable CRC(2 bytes) & Prim:TX. MAX_RT & TX_DS enabled..
	ldi R18,14
	ldi R16,32
	rcall _SPI_RW_Reg
	.dbline 380
; 	nRF24L01_CEH;
	sbi 0xb,7
	.dbline 381
; 	delay();
	rcall _delay
	.dbline -2
L56:
	.dbline 0 ; func end
	adiw R28,1
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\sendavrnrf24l01\main.c
_key_debug::
	.blkb 1
	.dbsym e key_debug _key_debug c
; 	
; }
; //------------------------------------------------------

⌨️ 快捷键说明

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