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

📄 hcs635.asm

📁 source for the microchip transponder for LF 125KHz.
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	retlw	0xAA


RecvLF_FAIL500us
	bsf	ValidLED	; turn off LED
	retlw	0x09
RecvLF_FAIL2msH
	bsf	ValidLED	; turn off LED
	retlw	0x0A
RecvLF_FAIL2msL
	bsf	ValidLED	; turn off LED
	retlw	0x0B
RecvLF_FAIL
	bsf	ValidLED	; turn off LED
	retlw	0x0C

		; ***********************************************************************
		; * Receive Routine 							*
		; ***********************************************************************
Receive8
		clrf	RXTX_REG	; clear receive register
		movlw	.8		; number of bits to receive
		movwf	COUNTER		; load number of bits into counter register
ReceiveNext
		btfss	LFDATA		; test for rising edge
		goto	ReceiveNext
		call	Delay350us	; wait until middle of bit		
		btfsc	LFDATA	; is LFDATA zero or a one?
		bcf	STATUS,C	; bit is a one => set carry bit
		btfss	LFDATA	; is LFDATA one or a zero?
		bsf	STATUS,C	; LFDATA is zero => clear carry bit
		rrf	RXTX_REG, f	; rotate value into receive register
		btfsc	LFDATA		; wait for bit to go low
		goto	$-1
		decfsz	COUNTER, f	; decrement receive count register by one
		goto	ReceiveNext	; receive next bit
		btfsc	LFDATA
		goto	$-1
		retlw	0x00		; return 

;****************************************************************************


Set_up_AFE_Registers
	bsf	STATUS,RP0
	movfw	TRISC
	andlw	b'11000000'		; chuck, Setup SDIO,SCLK, and CS as outputs 
	movwf	TRISC			; 
	bcf	STATUS,RP0

;		Register 0: 0000-0001 - 0 (parity)	
;----------------------------------------------------
	movlw	WriteCommand+GeneralOptions+((AFEConfig0>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig0&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 0
	movlw	ReadCommand+GeneralOptions
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig0&0xFF
	btfss	STATUS,Z
	retlw	0x01

;		Register 1: 0000-0000 - 1 (parity) 
;-------------------------------------------
	movlw	WriteCommand+LCXtune+((AFEConfig1>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig1&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 1
	movlw	ReadCommand+LCXtune
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig1&0xFF
	btfss	STATUS,Z
	retlw	0x02

;		Register 2: 0000-0000 - 1 (parity)
	movlw	WriteCommand+LCYtune+((AFEConfig2>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig2&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 2
	movlw	ReadCommand+LCYtune
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig2&0xFF
	btfss	STATUS,Z
	retlw	0x03

;		Register 3: 0000-0000 - 1 (parity)
	movlw	WriteCommand+LCZtune+((AFEConfig3>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig3&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 3
	movlw	ReadCommand+LCZtune
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig3&0xFF
	btfss	STATUS,Z
	retlw	0x04

;		Register 4: 0000-0000 - 1 (parity)
	movlw	WriteCommand+LCXLCYsens+((AFEConfig4>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig4&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 4
	movlw	ReadCommand+LCXLCYsens
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig4&0xFF
	btfss	STATUS,Z
	retlw	0x05


;		Register 5: 0000-1000 - 0 (parity)
	movlw	WriteCommand+LCZsensMOD+((AFEConfig5>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig5&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 5
	movlw	ReadCommand+LCZsensMOD
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig5&0xFF
	btfss	STATUS,Z
	retlw	0x06

;		Register 6: 1111-0110 - 1 (Parity) ;  column parity bits
	movlw	WriteCommand+ColParity+((AFEConfig6>>8)&0x01)
	movwf	SPIBufH
	movlw	AFEConfig6&0xFF
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
;		Verify Register 6
	movlw	ReadCommand+ColParity
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	xorlw	AFEConfig6&0xFF
	btfss	STATUS,Z
	retlw	0x07

	bsf	STATUS,RP0
	movfw	TRISC
	iorlw	b'00001100'		; Reset LFDATA,ALERT as input.  CS as output 
	movwf	TRISC			; 
	bcf	STATUS,RP0
	bsf	AFECS
	bcf	SCK		
	retlw	0x00

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Subroutine: ShiftOutSPIBuffer
;   
; Description: This routine is used to shift data out of the microcontroller
;					onto the SPI bus.
;
;Notes:
;1.	This routine assumes 16-bit data is in SSPBufH and SSPBufL already.
;3.	Control the ports as follows:
;		Clear SCK/ALERT
;		Clear chip select
;Loop
;		Set or clear LFDATA/SDIO pin.
;		Set SCK/ALERT
;		Clear SCK/ALERT
;		Goto Loop 16 times
;		Set chip select
;Count00
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ShiftOutSPIBuffer
	movlw		.16
	movwf		Count00
	bcf		SCK
	bcf		AFECS
ShiftOutLoop
	rlf		SPIBufL, f
	rlf		SPIBufH, f
	btfss		STATUS, C
	bcf		SDIO
	btfsc		STATUS, C
	bsf		SDIO
	bsf		SCK
	bcf		SCK
;	CLRWDT
	decfsz		Count00, f
	goto		ShiftOutLoop
	bsf		AFECS
	bcf		AFECS
	return

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Subroutine: ShiftInSPIBuffer
;   
; Description: This routine is used to shift data into the microcontroller
;					from the SPI bus.
;
;Notes:
;1.	This routine loads 16-bit data into the SSPBufH and SSPBufL registers.
;3.	Control the ports as follows:
;		Clear SCK/ALERT
;		Clear chip select
;Loop
;		Set SCK/ALERT
;		Shift in the LFDATA/SDIO pin value.
;		Clear SCK/ALERT
;		Goto Loop 16 times
;		Set chip select
;Count00
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ShiftInSPIBuffer
	movlw		.16
	movwf		Count00
	bsf		STATUS,RP0
	bsf		TRISC,3		;Set SDIO as an input
	bcf		STATUS,RP0
	bcf		SCK
	bcf		AFECS
ShiftInLoop
	bsf		SCK
	btfss		SDIO
	bcf		STATUS, C
	btfsc		SDIO
	bsf		STATUS, C
	rlf		SPIBufL, f
	rlf		SPIBufH, f
	bcf		SCK
;	CLRWDT
	decfsz		Count00, f
	goto		ShiftInLoop
	bsf		AFECS
	bcf		SCK
	bsf		STATUS,RP0
	bcf		TRISC,3		;Set SDIO as an output
	bcf		STATUS,RP0
	return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dump_AFE_Registers
	bsf	STATUS,RP0
	movlw	0x80
	movwf	EEADR
	bcf	STATUS,RP0

	bsf	STATUS,RP0
	movlw	b'11000000'		; Setup SDIO,SCLK, and CS as outputs 

	movwf	TRISC			; 
	bcf	STATUS,RP0

;		Register 0: 0000-0001 - 0 (parity)
	movlw	ReadCommand+GeneralOptions
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

;		Register 1: 0000-0000 - 1 (parity) 
	movlw	ReadCommand+LCXtune
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

;		Register 2: 0000-0000 - 1 (parity)
	movlw	ReadCommand+LCYtune
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

;		Register 3: 0000-0000 - 1 (parity)
	movlw	ReadCommand+LCZtune
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

;		Register 4: 0000-0000 - 1 (parity)
	movlw	ReadCommand+LCXLCYsens
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

;		Register 5: 0000-1000 - 0 (parity)
	movlw	ReadCommand+LCZsensMOD
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

;		Register 6: 1111-0110 - 1 (Parity) ;  column parity bits
	movlw	ReadCommand+ColParity
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	call	ShiftInSPIBuffer
	movfw	SPIBufL
	call	EEWRITE

	bsf		STATUS,RP0
	movlw	b'11001101'		; Reset LFDATA,ALERT, and CS as inputs 
	movwf	TRISC			; 
	bcf	STATUS,RP0
	bsf		AFECS
	retlw	0x00
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reset_AFE
	bsf	ValidLED	; LED
	bsf	STATUS,RP0
	movlw	b'11000000'		; lee, Setup SDIO,SCLK, and CS as outputs 
	movwf	TRISC			; 
	bcf	STATUS,RP0
	movlw	SoftRESET
	movwf	SPIBufH
	movlw	0x00
	movwf	SPIBufL
	call	ShiftOutSPIBuffer
	bsf	STATUS,RP0	
	movlw	b'11001100'		; Reset LFDATA,ALERT, and CS as inputs 
	movwf	TRISC			; 
	bcf	STATUS,RP0
	bsf	AFECS
	retlw	0x00

;------------------------------------------------
		; ***********************************************************************
		; * Delay routines  							*
		; ***********************************************************************
Delay250us
		movlw	.5
		movwf	TEMP2
BaseDelay	
		call	Delay50us
		decfsz	TEMP2,f
		goto	BaseDelay
		return
Delay500us
		movlw	.10
		movwf	TEMP2
		goto	BaseDelay
Delay2ms	
		movlw	.40
		movwf	TEMP2
		goto	BaseDelay
Delay4ms
		movlw	.80
		movwf	TEMP2
		goto	BaseDelay
Delay1ms	
		movlw	.20
		movwf	TEMP2
		goto	BaseDelay
Delay350us	
		movlw	.7
		movwf	TEMP2
		goto	BaseDelay
Delay400us			
		movlw	.8
		movwf	TEMP2
		goto	BaseDelay

; time=((X*3)+6)*(1/(Fosc/4))
Delay50us
		movlw	.14		; 1 cycle + 2 cycles for CALL
		movwf	TEMP1		; 1 cycle
		decfsz	TEMP1, f	; 1 cycle
		goto	$-1		; 2 cycles
		return			; 2 cycles + 1 cyclec for DECFSZ
;-----------------------------
ENDIF

	FILL	0xFFF, ROMend-$

;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
; INITIALIZE EEPROM WITH DEFAULT VALUES
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

#IF 1
	ORG	2100H
	DE	0FFH,03H 	; FIRST  COPY OF 16 BIT SYNC COU

⌨️ 快捷键说明

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