📄 main.s
字号:
X19:
.dbline 273
; return(byte); // return read byte
mov R16,R20
.dbline -2
L44:
.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 282
; }
; /**************************************************
; Function: SPI_RW_Reg();
;
; Description:
; Writes value 'value' to register 'reg' */
; /**************************************************/
; unsigned char SPI_RW_Reg(unsigned char reg, unsigned char value)
; {
.dbline 284
; unsigned char status;
; nRF24L01_CSNL;
cbi 0xb,6
.dbline 285
; delay();
rcall _delay
.dbline 286
; status = SPI_RW(reg); // select register
mov R16,R10
rcall _SPI_RW
mov R10,R16
.dbline 287
; SPI_RW(value); // ..and write value to it..
mov R16,R12
rcall _SPI_RW
.dbline 288
; nRF24L01_CSNH;
sbi 0xb,6
.dbline 289
; delay();
rcall _delay
.dbline 290
; return(status); // return nRF24L01 status byte
mov R16,R10
.dbline -2
L53:
.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 299
; }
; /**************************************************
; Function: SPI_Read();
;
; Description:
; Read one byte from nRF24L01 register, 'reg' */
; /**************************************************/
; unsigned char SPI_Read(unsigned char reg)
; {
.dbline 301
; unsigned char reg_val;
; nRF24L01_CSNL;
cbi 0xb,6
.dbline 302
; delay();
rcall _delay
.dbline 303
; SPI_RW(reg); // Select register to read from..
mov R16,R10
rcall _SPI_RW
.dbline 304
; reg_val = SPI_RW(0); // ..then read registervalue
clr R16
rcall _SPI_RW
mov R10,R16
.dbline 305
; nRF24L01_CSNH;
sbi 0xb,6
.dbline 306
; delay();
rcall _delay
.dbline 307
; return(reg_val); // return register value
mov R16,R10
.dbline -2
L54:
.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 317
; }
; /**************************************************
; 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 319
; unsigned char status,byte_ctr;
; nRF24L01_CSNL;
cbi 0xb,6
.dbline 320
; delay();
rcall _delay
.dbline 321
; status = SPI_RW(reg); // Select register to write to and read status byte
mov R16,R10
rcall _SPI_RW
mov R10,R16
.dbline 322
; for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
clr R12
rjmp L59
L56:
.dbline 323
; 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
L57:
.dbline 322
inc R12
L59:
.dbline 322
ldd R0,y+6
cp R12,R0
brlo L56
X20:
.dbline 324
; nRF24L01_CSNH;
sbi 0xb,6
.dbline 325
; delay();
rcall _delay
.dbline 326
; return(status); // return nRF24L01 status byte
mov R16,R10
.dbline -2
L55:
.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 336
; }
; /**************************************************
; 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 338
; unsigned char status,byte_ctr;
; nRF24L01_CSNL; // Set nRF24L01_CSN low, init SPI tranaction
cbi 0xb,6
.dbline 339
; delay();
rcall _delay
.dbline 340
; status = SPI_RW(reg); // Select register to write to and read status byte
mov R16,R10
rcall _SPI_RW
mov R10,R16
.dbline 341
; for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf)
clr R12
rjmp L64
L61:
.dbline 342
; status = SPI_RW(*pBuf++);
movw R30,R14
ld R16,Z+
movw R14,R30
rcall _SPI_RW
mov R10,R16
L62:
.dbline 341
inc R12
L64:
.dbline 341
ldd R0,y+6
cp R12,R0
brlo L61
X21:
.dbline 343
; nRF24L01_CSNH; // Set nRF24L01_CSN high again
sbi 0xb,6
.dbline 344
; delay();
rcall _delay
.dbline 345
; return(status); // return nRF24L01 status byte
mov R16,R10
.dbline -2
L60:
.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 358
; }
; /**************************************************
; 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 359
; nRF24L01_CEL;
cbi 0xb,7
.dbline 360
; delay();
rcall _delay
.dbline 361
; 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 363
;
; SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); // Enable Auto.Ack:Pipe0
ldi R18,1
ldi R16,33
rcall _SPI_RW_Reg
.dbline 364
; SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // Enable Pipe0
ldi R18,1
ldi R16,34
rcall _SPI_RW_Reg
.dbline 365
; SPI_RW_Reg(WRITE_REG + RF_CH, 40); // Select RF channel 40
ldi R18,40
ldi R16,37
rcall _SPI_RW_Reg
.dbline 366
; 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 367
; 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 368
; 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 369
; nRF24L01_CEH;
sbi 0xb,7
.dbline 370
; delay();
rcall _delay
.dbline -2
L65:
.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 390
; // 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 391
; nRF24L01_CEL;
cbi 0xb,7
.dbline 392
; delay();
rcall _delay
.dbline 393
; 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 394
; 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 395
; 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 397
;
; SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); // Enable Auto.Ack:Pipe0
ldi R18,1
ldi R16,33
rcall _SPI_RW_Reg
.dbline 398
; SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // Enable Pipe0
ldi R18,1
ldi R16,34
rcall _SPI_RW_Reg
.dbline 399
; SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a); // 500us + 86us, 10 retrans...
ldi R18,26
ldi R16,36
rcall _SPI_RW_Reg
.dbline 400
; SPI_RW_Reg(WRITE_REG + RF_CH, 40); // Select RF channel 40
ldi R18,40
ldi R16,37
rcall _SPI_RW_Reg
.dbline 401
; 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 402
; 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 403
; nRF24L01_CEH;
sbi 0xb,7
.dbline 404
; delay();
rcall _delay
.dbline -2
L66:
.dbline 0 ; func end
adiw R28,1
ret
.dbend
.area bss(ram, con, rel)
.dbfile E:\acceptavrnrf24l01\main.c
_key_debug::
.blkb 1
.dbsym e key_debug _key_debug c
;
; }
; //------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -