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

📄 rf.asm

📁 采用6502内核单片机,结合无线通讯模块的无线通讯方案,含Asm代码.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;==================================================================================
; The information contained herein is the exclusive property of
; Sunplus Technology Co. And shall not be distributed, reproduced,
; or disclosed in whole in part without prior written permission.
;       (C) COPYRIGHT 2004   SUNPLUS TECHNOLOGY CO.                                  
;                   ALL RIGHTS RESERVED
; The entire notice above must be reproduced on all authorized copies.
;==================================================================================
																					
;==================================================================================
;  Program Name		:	RF.asm
;  Description		:	RF communication operation 		 
;  Reference		:	SPMC65P2404A/2408A Data Sheet
;  Revision history	:
;---------------------------------------------------------------------------------- 
;  Version		Date 		Description
;  1.0.0    	2005-1-21	First Edition
;==================================================================================

.SYNTAX  6502							;Process standard 6502 addressing syntax
.LINKLIST								;Generate linklist information
.SYMBOLS								;Generate symbolic debug information
;**********************************************************************************
;constant
CB_CmpTimers			EQU		6			;The maximum times of compare
;**********************************************************************************
.PAGE0 
;key scan
GB_KeyDownFlag			DS		1			;Keys-down flag
IB_KeyupFlag			DS		1			;Keys-up flag
IB_CmpTimers			DS		1			;The equal times of Keys value
IB_ShowBuf				DS		1			;When key pressed,IB_ShowBuf add 1 for showing
	
;send datas
GB_Lock_Num				DS		1			;Delay before sending indexical data 
GB_Send_Flag			DS		1				
	C_Head_Allow:		EQU		$1			;Allow to send indexical data flag
	C_Start_Allow:		EQU		$2			;Allow to send starting data flag
	C_ID_Allow:			EQU		$4			;Allow to send ID word flag
	C_Data1_Allow:		EQU		$8			;Allow to send data1 flag			
	C_Data2_Allow:		EQU		$10			;Allow to send data2 flag	
	C_Data3_Allow:		EQU		$20			;Allow to send data3 flag		
	C_Data4_Allow:		EQU		$40			;Allow to send data4 flag			
	C_Send_Allow:		EQU		$80			;Allow to send flag

GB_Sending_Flag			DS		1
	C_Sending:			EQU		$1			;Sending one bit flag
	C_Sending_Bit:		EQU		$2			;0:sending 0; 1:sending 1
	C_Send_8BitEnd:		EQU		$4			;One byte sending end flag
	C_Send_40BitEnd:	EQU		$8			;Five byte sending end flag
IB_Bit_number			DS		1			;The numbers of bit that have been send

GB_DataBuf				DS		1			;Data to be sended
	C_ID_Buf:			EQU		$AA			;ID word
IB_470us_Count			DS		1			;Time base for sending 

;receive datas
GB_Receive_Flag			DS		1	
	C_Rece_Allow:		EQU		$1			;Allow to receive flag
	C_ReceInit_Allow:	EQU		$2			;Initialize receive flag
	C_ReceStart_Allow:	EQU		$4			;Allow to receive starting data flag
	C_ReceID_Allow:		EQU		$8			;Allow to receive ID data flag
	C_ReceEnd_Allow:	EQU		$10			;Receiving end flag

G_RF_Time				DS		1			;The latest capture data
G_RF_data				DS		5			;The datas received
G_RF_Number				DS		1			;The numbers of bit that has been received
	C_RF_Number:		EQU		40			;40 bits to receive flag
.DATA
;**********************************************************************************
.CODE
;==================================================================================
;	Function:		F_Receive_Init
;	Description:	Initialize receiving
;	Input:			GB_Send_Flag
;					GB_Receive_Flag
;	Output:			GB_Receive_Flag
;	Destroy:		A
;	Stacks:			1
;==================================================================================
F_Receive_Init:
		lda		GB_Send_Flag					;In sending mode
		bne		?L_Send_Mode					;yes

		lda		GB_Receive_Flag					
		and		#C_Rece_Allow					;In receiving mode	
		bne		?L_Receive_Init					;yes

		lda		GB_Receive_Flag
		ora		#(C_Rece_Allow+C_ReceInit_Allow);set receiving mode
		sta		GB_Receive_Flag
		
		lda		P_IOB_Data
		and		#%01011111						;enter receiving mode
		sta		P_IOB_Data
		
?L_Receive_Init:
		lda		GB_Receive_Flag
		and		#C_ReceInit_Allow				;Initialize receiving?
		beq		?L_Receive_Init_Exit			;no
		;------------------------------
		;initialize	cap3
		;falling clear, falling INT
        lda		#$00							;Set Timer3 preload counter= 0
        sta		P_TMR3_Preload			
		lda		#C_T3FCS_Div_512				;Set Timer3 clock source is Fcs/512
		sta		P_TMR2_3_Ctrl1
		lda		#C_T38B_CAP						;Set Timer3 is 8-bit capture
		sta		P_TMR2_3_Ctrl0

        lda     #0              				;Falling edge clear counter
        sta     P_IRQ_Opt1              
        sta     P_IRQ_Opt1              

	    lda     #$20              				;Be same with CAP3ES edge setting
        sta		P_CAP_Ctrl

        lda		#$FF							;clear INT request flag
        sta		P_INT_Flag0				
        lda		#C_INT_CAP3IE					;Capture3 INT enable
        sta		P_INT_Ctrl0		

		lda		GB_Receive_Flag
		and		#~C_ReceInit_Allow
		ora		#C_ReceStart_Allow				;Allow to receive starting data 
		sta		GB_Receive_Flag
		jmp		?L_Receive_Init_Exit
		
?L_Send_Mode:
		lda		GB_Receive_Flag
		and		#~(C_Rece_Allow+C_ReceInit_Allow+C_ReceStart_Allow+C_ReceID_Allow)
		sta		GB_Receive_Flag	
		lda		P_INT_Ctrl0
        and		#~C_INT_CAP3IE					;Capture3 INT enable
        sta		P_INT_Ctrl0		
?L_Receive_Init_Exit:		
		rts
		
;==================================================================================
;	Function:		F_Receive
;	Description:	decode datas and save the decoded datas in a 5-byte RAM
;	Input:			GB_Send_Flag
;					GB_Receive_Flag
;	Output:			G_RF_data
;					GB_Receive_Flag
;	Destroy:		A,X
;	Stacks:			2
;==================================================================================		
F_Receive:		
		lda		GB_Send_Flag
		and		#C_Send_Allow					;In sending mode
		bne		?L_Send_Mode1					;yes

		lda		GB_Receive_Flag					
		and		#C_Rece_Allow					;In receiving mode	
		bne		?L_Start_Bit					;yes
		
?L_Send_Mode1:
		lda		GB_Receive_Flag
		and		#~(C_ReceInit_Allow+C_ReceStart_Allow+C_ReceID_Allow)
		sta		GB_Receive_Flag	
		lda		P_INT_Ctrl0
        and		#~C_INT_CAP3IE					;Capture3 INT enable
        sta		P_INT_Ctrl0		
		jmp		?L_ReceEnd			
		
?L_Start_Bit:
		lda		P_TMR3_CapHi
		sta		G_RF_Time						;rising edage data
?_incept:		
		lda		GB_Receive_Flag
		and		#C_ReceStart_Allow				;Allow to receive starting data 
		beq		?L_ID_Word						;no
		
		lda		G_RF_Time						;\69
		cmp		#54								;+ 
		bcc		?L_Error						;+=the front code = 156 (9ms)
		cmp		#84								;+
		bcs		?L_Error						;/	

 		lda		GB_Receive_Flag
		and		#~C_ReceStart_Allow
		ora		#C_ReceID_Allow
		sta		GB_Receive_Flag
		lda		#0
		sta		G_RF_Number
		jmp		?L_Receive_Exit	
 			
?L_ID_Word:
		lda		GB_Receive_Flag
		and		#C_ReceID_Allow
		beq		?L_Error

		lda		G_RF_Time						;\	13
		cmp		#6								;+
		bcc		?L_Error						;+= receive "0" =39 (0.94ms)?
		cmp		#18								;+
		bcs		?_incept_1						;/								
		jmp		?_icept_number					;no
		
?_incept_1:		
		lda		G_RF_Time						;\25
		cmp		#18								;+
		bcc		?L_Error						;+= receive "1" =78 (1.88ms)?
		cmp		#35								;+
		bcs		?L_Error						;/		
		sec										;yes
		
?_icept_number:	
		rol		G_RF_data						;\
		rol		G_RF_data+1						;+					
		rol		G_RF_data+2						;+= receive bits one by one							
		rol		G_RF_data+3						;+		
		rol		G_RF_data+4						;/
		
		inc		G_RF_Number
		lda		G_RF_Number
		cmp		#8								;get ID word? 
		beq		?L_Int							;yes
		cmp		#C_RF_Number					;receive end?
		bcc		?L_Receive_Exit					;no
		
		jsr		F_DataCorrect
		beq		?L_Error
		
		lda		#C_ReceEnd_Allow
		sta		GB_Receive_Flag		
?L_ReceEnd:	
		jmp		?L_Receive_Exit
		
?L_Int:
		lda		G_RF_data
		cmp		#$AA							;ID word past?
		beq		?L_Receive_Exit					;yes
?L_Error:										;Error cope
		lda		GB_Receive_Flag
		and		#C_ReceEnd_Allow
		ora		#(C_Rece_Allow+C_ReceStart_Allow)
		sta		GB_Receive_Flag	
?L_Receive_Exit:		
		rts
;==================================================================================
;	Function:		F_DataCorrect
;	Description:	Check up 4byte datas
;	Input:			G_RF_data
;	Output:			G_RF_data
;	Destroy:		A
;	Stacks:			1
;==================================================================================
F_DataCorrect:
		lda		G_RF_data+1
		cmp		G_RF_data+3
		beq		?L_Right
		
		lda		G_RF_data
		cmp		G_RF_data+2
		beq		?L_ReceiveData

		clc
		lda		G_RF_data
		adc		G_RF_data+1
		cmp		#$FF
		beq		?L_Right
		
		clc
		lda		G_RF_data
		adc		G_RF_data+3
		cmp		#$FF
		beq		?L_ReceiveData1
		
		clc
		lda		G_RF_data+2
		adc		G_RF_data+1
		cmp		#$FF
		beq		?L_Right
		
		clc
		lda		G_RF_data+3
		adc		G_RF_data+2
		cmp		#$FF
		beq		?L_ReceiveData1
		jmp		?L_Wrong
		
?L_ReceiveData1:
		lda		G_RF_data+3
		sta		G_RF_data+1
		jmp		?L_Right
?L_ReceiveData:
		lda		G_RF_data
		eor		#$FF
		sta		G_RF_data+1
?L_Right:
		lda		#99
		jmp		?L_DataCorrectExit	
?L_Wrong:
		lda		#0
?L_DataCorrectExit:			
		rts
;==================================================================================
;	Function:		F_Send_Init
;	Description:	Initialize sending
;	Input:			GB_Send_Flag
;	Output:			GB_Send_Flag
;	Destroy:		A
;	Stacks:			1
;==================================================================================
F_Send_Init:
		lda		#0
		sta		GB_Receive_Flag
		lda		#C_Send_Allow				;Start to send datas 
		sta		GB_Send_Flag
		lda		#0
		sta		P_INT_Ctrl0
		sta		P_INT_Ctrl1
   
        lda		#138						;Set Timer3 preload counter= 0
        sta		P_TMR3_Preload			
		lda		#C_T3FCS_Div_32				;Set Timer3 clock source is Fcs
		sta		P_TMR2_3_Ctrl1
		lda		#C_T38B_Timer				;Set Timer3 is 8-bit timer
		sta		P_TMR2_3_Ctrl0				;8000000/32/(256-138)=472us
		
		;-------------------------------------------------------
		;change from capture to timer,need a long delay
		ldy		#0
?L_Delay00:		
		ldx		#0
?L_Delay11:
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		inx
		bne		?L_Delay11
		iny
		bne		?L_Delay00	
		rts	
;==================================================================================
;	Function:		F_Lock
;	Description:	Initialize sending
;	Input:			GB_Send_Flag
;	Output:			GB_Send_Flag
;	Destroy:		A
;	Stacks:			1
;==================================================================================
F_Lock:
		lda		GB_Send_Flag
		and		#C_Send_Allow
		beq		?L_Lock_Exit

		lda		GB_Send_Flag
		and		#~C_Send_Allow					;Allow to initialize sending
		bne		?L_Lock_Exit

		lda		P_IOB_Data
		ora		#%00001100
		and		#%11101111
		sta		P_IOB_Data						;prepare to send
		
		inc		GB_Lock_Num						;\
		cmp		#10                   			;+ delay 40ms	          
		bcc		?L_Lock_Exit					;/
		
		lda		#0
		sta		GB_Lock_Num
		
		lda		GB_Send_Flag
		ora		#C_Head_Allow
		sta		GB_Send_Flag

?L_Lock_Exit:		
		rts

;==================================================================================
;	Function:		F_Send_Data_Head
;	Description:	send indexical data 
;	Input:			GB_Send_Flag
;	Output:			GB_Send_Flag
;	Destroy:		A,X
;	Stacks:			1
;==================================================================================
F_Send_Data_Head:
		lda		GB_Send_Flag
		and		#C_Send_Allow
		beq		?L_Send_Data_Head_Exit
		
		lda		GB_Send_Flag
		and		#C_Head_Allow
		beq		?L_Send_Data_Head_Exit
		
		ldy		#0											
?L_Long_Head:									;\				
		ldx		#0								;+
		lda		P_IOB_Data						;+			
		eor		#%00010000						;+				
		sta		P_IOB_Data						;+
?L_20us:										;+
		inx										;+		
		cpx		#200							;+=	send indexical data			

⌨️ 快捷键说明

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