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

📄 rx.asm

📁 一款用24L01给美的电器做的2.4G无线遥控器
💻 ASM
字号:
		.include	"SPI.inc"
		.include        "inc.inc"
;--------------Constants--------------------
c_max_channel          ==             15
c_fecth_pipe_no        ==            0x0e
c_fetch_command        ==            0xe0
c_com_normal_key       ==            0x00
c_com_ask              ==            0x20
c_com_answer           ==            0x40
c_com_factory_set      ==            0x60
c_com_return	       ==	     0xc0	
;--------------Variables--------------------
           .area     RX_Data(data)
   
IRQ_source::                   .ds          1



  
;tx_payload::       .ds               4           ;tx_payload parket
;rx_payload::                    .ds          4 
;tx_fail_point::                 .ds          1  
flag::			.ds	1
;--------------Code-------------------------
            .area    RX_Code(code) 		

;****************************************
; Function: Rx_Bytes
; Description: Recieve bytes sent from another nRF24L01
;         Mainly be used to recieve access code
;
; In/Out parameters:
;     In: non
;     Out: 'access_code','access_code+1'
;****************************************
Rx_Bytes::
	
	setbit(plata,CE)
	call    Wait_Rx_Delay
	call	Wait_Rx_Delay
	;call    Wait_IRQ_Delay
	clearbit(plata,CE)
	lda     IRQ_source
	anda    #c_fecth_IRQ_source
	cmpe    #RX_DR
	brnz    Rx_End
	lda     IRQ_source
	anda    #c_fecth_pipe_no
	cmpe    #0
	brnz    Rx_End
	lda     #RX_PW_P0
	sta     reg_name
	call    SPI_Read_Reg
	lda     reg_value
	cmpe    #c_tx_payload_width
	brnz    Rx_End

	clearbit(plata,CSN)
	lda     #RD_RX_PLOAD
	sta     byte
	call    SPI_RW
	lda     #0
	sta	byte
	call    SPI_RW
	lda     byte
	sta	command
	lda     #0
	sta     byte
	call    SPI_RW
	lda     byte
	sta     access_code
	lda     #0
	sta     byte
	call    SPI_RW
	lda     byte
	sta     access_code+1
	lda     #0
	sta     byte
	call    SPI_RW
	lda     byte
	sta     access_code+2
	
	setbit(plata,CSN)

        lda     command
        anda    #c_fetch_command
        cmpe    #c_com_answer
        brnz    Rx_End
        setbit(flag,f_rx_ok)
Rx_End: 
        lda     #0
        sta     IRQ_source
        ret

;---------------------------------------
Wait_Rx_Delay:
      lda      #0x12                     
      sta      delay_times
      lda      #0xff
      sta      delay_times+1
Wait_Rx_Delay_Loop:  
      lda      IRQ_source
      anda     #c_fecth_IRQ_source
      cmpe     #RX_DR
      brz      Wait_Rx_End
      lda      delay_times+1
      suba     #1
      sta      delay_times+1
      brc      Wait_Rx_Delay_Loop		;9*256*0.25Us=576us
      lda      delay_times
      suba     #1
      sta      delay_times
      brc      Wait_Rx_Delay_Loop 		;17*576us=9.7ms
Wait_Rx_End:      
      ret         	
;---------------------------------
Wait_Tx_Delay::
      lda      #0x12                     
      sta      delay_times
      lda      #0xff
      sta      delay_times+1
Wait_Tx_Delay_Loop:  
      lda      IRQ_source
      anda     #c_fecth_IRQ_source
      cmpe     #TX_DS
      brz      Wait_Tx_End
      cmpe     #MAX_RT
      brz      Wait_Tx_End
      lda      delay_times+1
      suba     #1
      sta      delay_times+1
      brc      Wait_Tx_Delay_Loop		;9*256*0.25Us=576us
      lda      delay_times
      suba     #1
      sta      delay_times
      brc      Wait_Tx_Delay_Loop 		;17*576us=9.7ms
Wait_Tx_End:      
      ret	


Test_Frequency:
	lda	#11111001b
	sta	pdirc
	
test:
	lda	PLATC
	XORA	#0XFF
	STA	PLATC
	BR	TEST
	ret

⌨️ 快捷键说明

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