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

📄 rfdriver.asm

📁 FM1702SL射频模块底层驱动源程序
💻 ASM
📖 第 1 页 / 共 3 页
字号:
		btfsc   status,c
                return

		bsf	status,rp0
		movlw	Poll_1702SL_Timeout
		movwf	Temp_2
Read_FIFOLength:
		movlw	FIFOLength_Reg			;读取FIFOLength寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		call	SPIRead
		btfsc	status,c
		return

		bsf	status,rp0
		movf	TxRx_Buf,w			;判断FIFOLength寄存器是否已为0
		btfss	status,z
		goto	Clear_FIFO_Err

		bcf	status,rp0
		bcf	status,c
		return
Clear_FIFO_Err:
		decfsz	Temp_2,f
		goto	Read_FIFOLength

		bcf	status,rp0
		bsf	status,c
		return
;***********************************************************************
;读FM1702SL的FIFO寄存器
;Read_FIFO	读FIFO寄存器
;	入口:
;		N/A
;	出口:
;		ReadLength	读得数据长度
;		Send_Buf	读出的数据置于发送,接收缓冲区中
;		c = 1:		读FIFO寄存器失败
;		c = 0:		读FIFO寄存器成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Loop_Count,SpiAddress
;***********************************************************************
Read_FIFO:
		bsf	status,rp0
		movlw	FIFOLength_Reg			;读取FIFOLength寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		call	SPIRead
		btfsc	status,c
		return

		bsf	status,rp0
		movf	TxRx_Buf,w
		btfsc	status,z
		goto	Read_FIFO_Err

		movwf	ReadLength
		movwf	Loop_Count
		movlw	FIFO_Reg
		movwf	SpiAddress
		movlw	Send_Buf
		movwf	fsr
		bsf	status,irp
		call	SPIRead
		bcf	status,irp
		return
Read_FIFO_Err:
		bcf	status,rp0
		bsf	status,c
		return
;***********************************************************************
;写FM1702SL的FIFO寄存器
;Write_FIFO	写FIFO寄存器
;	入口:
;		Send_Length:	要写入的字节数
;		Send_Buf:	待发送数据应放在Send_Buf缓冲区中
;		irp:		Ram首地址的Bank标识
;	出口:
;		c = 1:		写FIFO寄存器失败
;		c = 0:		写FIFO寄存器成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Loop_Count,SpiAddress
;***********************************************************************
Write_FIFO:
		bsf	status,rp0
		movlw	FIFO_Reg
		movwf	SpiAddress
		movf	Send_Length,w
		btfsc	status,z
		goto	Write_FIFO_Empty

		movwf	Loop_Count
		movlw	Send_Buf
		movwf	fsr
		bsf	status,irp
		call	SPIWrite
		bcf	status,irp
		return
Write_FIFO_Empty:
		bcf	status,rp0
		bcf	status,c
		return
;***********************************************************************
;发送接收FM1702SL数据
;Command_Send	发送接收数据
;	入口:
;		Send_Length:	要写入的字节数
;		Send_Buf:	待发送数据应放在Send_Buf缓冲区中
;		comm_set:	命令操作码
;	出口:
;		c = 1:		命令发送失败
;		c = 0:		命令发送成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Temp2,Loop_Count,SpiAddress
;***********************************************************************
Command_Send:
		call 	Clear_FIFO			;清空FIFO寄存器
		btfsc	status,c
		return

		call	Write_FIFO			;写FIFO寄存器
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	Command_Reg			;向command寄存器写控制命令码
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		movf	comm_set,w
		movwf	indf
		call	SPIWrite
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	Poll_1702SL_Timeout		;检测命令是否被执行
		movwf	Temp_2
Read_Command_Loop:
		movlw	Command_Reg
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		call	SPIRead
		btfsc	status,c
		return

		bsf	status,rp0
		movf	TxRx_Buf,w
		bcf	status,rp0
		btfsc	status,z
		return

		bsf	status,rp0
		decfsz	Temp_2,f
		goto	Read_Command_Loop

		bcf	status,rp0
		bsf	status,c
		return
;===============================================================================
;FM1702SL对射频卡片的相关操作
;===============================================================================

;***********************************************************************
;FM1702SL向空间发送request信号
;Request	发送request信号
;	入口:
;		N/A
;	出口:
;		c = 1:		request命令执行失败
;		c = 0:		request命令执行成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Temp2,Loop_Count,SpiAddress
;               Send_Length,comm_set,Read_length
;***********************************************************************
Request:
		bsf	status,rp0
		movlw	BitFraming_Reg			;写bitframing寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		movlw	0x07
		movwf	indf
		call	SPIWrite
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	Control_Reg			;改写control寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		call	SPIRead
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	TxRx_Buf
		movwf	fsr
		movf	indf,w
		andlw	0xf7
		movwf	indf
		movlw	Control_Reg
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		call	SPIWrite
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	ChannelRedundancy_Reg		;写ChannelRedundancy寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		movlw	0x03
		movwf	indf
		call	SPIWrite
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	Send_Buf			;将待发送数据写入FIFO中,并执行发送接收命令
		movwf	fsr
		bsf	status,irp
		movlw	0x52
		movwf	indf
		bcf	status,irp
		movlw	0x01
		movwf	Send_Length
		movlw	Transceive
		movwf	comm_set
		call	command_send
		btfsc	status,c
		return

		call 	Read_FIFO			;读出FIFO寄存器的内容
		btfsc	status,c
		return

		bsf	status,rp0
		movf	ReadLength,w			;判断回读的应答数据长度为2否
		sublw	0x02
		btfss	status,z
		goto	Request_Err

		bsf	status,rp1			;判断回应的数据是否为04,00
		movf	Send_Buf,w
		bcf	status,rp1
		sublw	0x04
		btfss	status,z
		goto	Request_Err

		bsf	status,rp1
		movf	Send_Buf+1,w
		bcf	status,rp1
		btfss	status,z
		goto	Request_Err

		bcf	status,rp0
		bcf	status,c
		return
Request_Err:
		bcf	status,rp0
		bsf	status,c
		return
;***********************************************************************
;FM1702SL向存在于其发射范围内的卡片发射GET_UID信号
;Get_UID	发送GET_UID信号
;	入口:
;		N/A
;	出口:
;		c = 1:		GET_UID命令执行失败
;		c = 0:		GET_UID命令执行成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Temp2,Loop_Count,SpiAddress
;		Send_length,comm_set,Read_length,Card_UID
;***********************************************************************
Get_UID:
		bsf	status,rp0
		movlw	ChannelRedundancy_Reg		;写ChannelRedundancy寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		movlw	0x03
		movwf	indf
		call	SPIWrite
		btfsc	status,c
		return

		bsf	status,rp0
		movlw	Send_Buf			;将待发送数据写入FIFO中,并执行发送接收命令
		movwf	fsr
		bsf	status,irp
		movlw	0x93
		movwf	indf
		incf	fsr,f
		movlw	0x20
		movwf	indf
		bcf	status,irp
		movlw	0x02
		movwf	Send_Length
		movlw	Transceive
		movwf	comm_set
		call	command_send
		btfsc	status,c
		return

		call 	Read_FIFO			;读出FIFO寄存器的内容
		btfsc	status,c
		return

		bsf	status,rp0
		movf	ReadLength,w			;判断回读的应答数据长度为5否
		sublw	0x05
		btfss	status,z
		goto	Get_UID_Err

		bcf	status,rp0
		movlw	Send_Buf			;保存得到的5位UID号
		movwf	temp0
		movlw	Card_UID
		movwf	temp1
		movlw	.5
		movwf	temp2
		bsf	source_irp
		bcf	destination_irp
		movlw	high copydata
		movwf	pclath
		call	copydata
		movlw	high Get_UID
		movwf	pclath

		call	Check_UID			;校验得到的5位UID是否正确
		return
Get_UID_Err:
		bcf	status,rp0
		bsf	status,c
		return
;***********************************************************************
;对收到的UID号进行校验
;Check_UID	校验UID
;	入口:
;		N/A
;	出口:
;		c = 1:		UID校验错误
;		c = 0:		UID校验成功
;影响的寄存器:
;		w,status,fsr,Temp2,Temp3
;***********************************************************************
Check_UID:
		movlw	Card_UID
		movwf	fsr
		clrf	Temp2
		movlw	.5
		movwf	Temp3
Check_UID_Loop:						;对5位UID号进行异或操作
		movf	indf,w
		xorwf	Temp2,f
		incf	fsr,f
		decfsz	Temp3,f
		goto	Check_UID_Loop

		movf	Temp2,w
		btfss	status,z
		goto	Check_UID_Err

		bcf	status,c
		return
Check_UID_Err:
		bsf	status,c
		return
;***********************************************************************
;FM1702SL向存在于其发射范围内的卡片发射选择卡片信号
;Select_Tag	发送Select_TAG信号
;	入口:
;		N/A
;	出口:
;		c = 1:		选择卡片执行失败
;		c = 0:		选择卡片执行成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Temp2,Loop_Count,SpiAddress
;		Send_length,comm_set,Read_length,Src,Dst,count
;***********************************************************************
Select_Tag:
		bsf	status,rp0
		movlw	ChannelRedundancy_Reg		;写ChannelRedundancy寄存器
		movwf	SpiAddress
		movlw	0x01
		movwf	Loop_Count
		movlw	TxRx_Buf
		movwf	fsr
		movlw	0x0f
		movwf	indf
		call	SPIWrite
		btfsc	status,c
		return

		movlw	Send_Buf			;将待发送数据写入FIFO中,并执行发送接收命令
		movwf	fsr
		bsf	status,irp
		movlw	0x93
		movwf	indf
		incf	fsr,f
		movlw	0x70
		movwf	indf
		bcf	status,irp
		incf	fsr,f
		movf	fsr,w
		movwf	temp1
		movlw	Card_UID
		movwf	temp0
		movlw	.5
		movwf	temp2
		bcf	source_irp
		bsf	destination_irp
		movlw	high copydata
		movwf	pclath
		call	copydata
		movlw	high Select_Tag
		movwf	pclath

		bsf	status,rp0
		movlw	0x07
		movwf	Send_Length
		movlw	Transceive
		movwf	comm_set
		call	command_send
		btfsc	status,c
		return

		call 	Read_FIFO			;读出FIFO寄存器的内容
		btfsc	status,c
		return

		bsf	status,rp0
		movf	ReadLength,w			;判断回读的应答数据长度为1否
		sublw	0x01
		btfss	status,z
		goto	Select_Tag_Err

		bsf	status,rp1
		movf	Send_Buf,w			;判断回应的数据是否为08
		bcf	status,rp1
		sublw	0x08
		btfss	status,z
		goto	Select_Tag_Err

		bcf	status,rp0
		bcf	status,c
		return
Select_Tag_Err:
		bcf	status,rp0
		bsf	status,c
		return
;***********************************************************************
;FM1702SL将密码装入EE中
;Load_Key	发送Load_Key信号
;	入口:
;		Send_Buf	写入FM1702SL EE中的EE地址(2bytes)及密码(6bytes),
;   				EE地址低字节在前
;	出口:
;		c = 1:		Load_Key失败操作
;		c = 0:		Load_Key操作成功
;影响的寄存器:
;		w,status,fsr,Temp5,Temp4,Temp3,Temp2,Loop_Count,SpiAddress
;		Src,Dst,count,Send_Length,comm_set
;***********************************************************************
Load_Key:
		movlw	Send_Buf+02h			;密码搬运
		movwf	temp0
		movlw	Send_Buf+0ah
		movwf	temp1
		movlw	.6
		movwf	temp2
		bsf	source_irp
		bsf	destination_irp
		movlw	high copydata
		movwf	pclath
		call 	copydata
		movlw	high Load_Key
		movwf	pclath

		bsf	status,rp0
		bsf	status,irp
		movlw	Send_Buf+0ah			;计算出存放于EE中的密码
		movwf	Src
		movlw	Send_Buf+02h
		movwf	Dst
		movlw	.6
		movwf	loop_count
Key_Transfer:
		movf	Src,w
		movwf	fsr
		movf	indf,w
		movwf	Temp_5
		incf	Src,f
		comf	Temp_5,w
		andlw	0xf0
		movwf	Temp_4
		swapf 	Temp_5,w
		andlw	0x0f
		iorwf	Temp_4,f

		comf	Temp_5,w
		andlw 	0x0f
		movwf	Temp_3
		swapf 	Temp_3,f
		movf	Temp_5,w
		andlw	0x0f
		iorwf	Temp_3,f

		movf	Dst,w
		movwf	fsr
		movf	Temp_4,w
		movwf	indf
		incf	fsr,f
		incf	Dst,f
		movf	Temp_3,w
		movwf	indf
		incf	Dst,f

		decfsz	loop_count,f
		goto	Key_Transfer

		bcf	status,irp

		movlw	0x0e				;将密码写入FM1702SL的EE中
		movwf	Send_Length
		movlw	WriteEE

⌨️ 快捷键说明

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