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

📄 rf_tx.asm

📁 RFID功能中阅读器源代码,实现汽车的无钥匙进入功能
💻 ASM
字号:
#include "Project.inc"
#include "Delay.inc"
#ifndef RF.PIN
	#define RF.PIN		5		; RF Modulation Output
	#define RF.PORT		PORTC
#endif
RF_ovr	udata_ovr
Parity			res 1
RF.COUNTER		res 1
RF.Byte_Counter	res 1
RF.Data_REG		res 1
    global RF.Init,RF.Send_Header, RF.Send_Byte, RF.SendBuffer
    code
---------------------------------------
;初始化发射口
--------------------------------------
RF.Init
    banksel RF.PORT
	bcf		RF.PORT,RF.PIN
    return
---------------------------------------
;发送帧头,4ms+0.5ms+2ms+2ms
---------------------------------------
RF_Send_Header	
    banksel	RF.PORT
	bsf		RF.PORT,RF.PIN	; modulation data for rf
	movlw	(.4100/.50)
	call	Delay.start
	call	Delay.Wait
	banksel	RF.PORT
	bcf		RF.PORT,RF.PIN	; turn off modulation data for rf
	movlw	(.550/.50)
	call	Delay.start
	call	Delay.Wait
	banksel	RF.PORT
	bsf		RF.PORT,RF.PIN	; modulation data for rf
	MOVLW	(.2100/.50)
	call	Delay.start
	call	Delay.Wait
	banksel	RF.PORT
	bcf		RF.PORT,RF.PIN	; turn off modulation data for rf
	movlw	(.2100/.50)
	call	Delay.start
	return
------------------------------------------
;发送一个字节的数据,位于w中
------------------------------------------
RF_Send_Byte
    banksel RF.Data_REG
    movwf RF.Data_REG
    clrf Parity
Transmit8
    banksel RF.COUNTER
    movlw .8
    movwf RF.COUNTER
TransmitNext
    banksel RF.Data_REG
	rrf		RF.Data_REG, f		; rotate receive register
	btfsc	STATUS, C		; test bit to be transmited
	goto	SendOne			; send high value
SendZero
    call 	Delay.Wait
	banksel RF.PORT
	bsf		RF.PORT,RF.PIN	; rf modulation on
	movlw	((.2*.250)/.50)
	call 	Delay.start
	call 	Delay.Wait
	banksel RF.PORT
	bcf		RF.PORT,RF.PIN	; rf modulation off
	movlw	(.250/.50)
	call 	Delay.start
	goto	SendNextBit		; send next bit
SendOne
	call 	Delay.Wait
	banksel RF.PORT
	bsf		RF.PORT,RF.PIN	; rf modulation on
	movlw	(.250/.50)
	call 	Delay.start
	call 	Delay.Wait
	banksel RF.PORT
	bcf		RF.PORT,RF.PIN	; rf modulation off
	movlw	((.2*.250)/.50)
	call 	Delay.start
	banksel	Parity
	incf	Parity,f
;	goto	SendNextBit		; send next bit
SendNextBit	
	banksel RF.COUNTER
	movf	RF.COUNTER,f
	btfsc	STATUS,Z
	goto	EndTX
	decfsz	RF.COUNTER, f	; decrement counter register
	goto	TransmitNext 	; transmit next bit
SendParity
;	btfsc	Parity,7
;	goto	EndTX
;	bsf		Parity,7
    banksel Parity
	btfss	Parity,0
	goto	SendOne
	banksel Parity
	btfsc	Parity,0
	goto	SendZero
EndTX
	call 	Delay.Wait
	retlw	0x00
-----------------------------------------------
;将缓冲区中的数据通过RF口发射出去
;w代表要传送的字节数
;FSR代表要传送的字节在RAM中存放的首地址	
--------------------------------------------------
RF_SendBuffer
    banksel RF.Byte_Counter
    movwf RF.Byte_Counter
    call RF_Send_Header
RF_SendBuffer_LOOP
    bankisel PORTA
    movf INDF,w
    call RF_Send_Byte
    incf FSR,f
    banksel RF.Byte_Counter
    decfsz RF.Byte_Counter,f
    goto RF_SendBuffer_LOOP
    return
    END

⌨️ 快捷键说明

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