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

📄 delay.inc

📁 PKE(被动无钥门禁系统
💻 INC
字号:
;	extern Delay50us, Delay250us, Delay500us, Delay2ms, Delay4ms, Delay1ms, Delay350us, Delay400us, Delay_15ms, Delay_15ms, Delay_50ms, Delay_100ms, Delay_500ms


#define Delay.Returned	Delay.flag,3


	extern Delay.flag, Delay.Start8, Delay.Start16, Delay.Wait, Delay.CounterL, Delay.CounterH



;/*
;
;	This macro must be called within the Interrupt routine, to enable the counter.
;	The Counter function is optimized for the following Interrupt routine.
;	If you do changes to that routine you will have to modify counter.start function,
;	to compensate these instructions (or you will loose precision).
;
;
;	@example
;	
;	
;	HIGH_INT_VEC	code 0x0008		;3Cycles	n
;		goto	ISR					;2Cycles	n
;	
;	LOW_INT_VEC		code 0x0018
;		bra 0x0018
;	
;	REST	code
;		
;	
;	ISR	
;		banksel	0x000				;2(1)Cycles	n
;		movff	FSR2L,FSR2_bak		;2Cycles	n
;		movff	FSR2H,FSR2_bak+1	;2Cycles	n
;		lfsr	0x02,tmpvar			;2Cycles	n
;		movff	FSR0L,POSTINC2		;2Cycles	n
;		movff	FSR0H,POSTINC2		;2Cycles	n
;		movff	FSR1L,POSTINC2		;2Cycles	n
;		movff	FSR1H,POSTINC2		;2Cycles	n
;		movff	ECANCON,POSTINC2	;2Cycles	n
;		movff	PCLATH,POSTINC2		;2Cycles	n
;		
;		btfss	INTCON,TMR0IE		;2Cycles	n
;		bra		PORTB_INT
;		btfss	INTCON,TMR0IF		;2Cycles	n
;		bra		PORTB_INT
;		
;		Delay.Isr					
;		
;						
;	;*** When using TMR0 for other interrupts, you may place code here ***
;	; You will have to compensate all instructions in the Delay.Isr or Delay.Start function
;		bcf		INTCON,TMR0IF		;1Cycle		1
;		bra		endisr				;2Cycles	1
;	;*** You may add other interrupts here ***	
;	endisr	
;		lfsr	0x02,tmpvar				;2Cycles	1
;		movsf	[0],FSR0L				;2Cycles	1
;		movsf	[1],FSR0H				;2Cycles	1
;		movsf	[2],FSR1L				;2Cycles	1
;		movsf	[3],FSR1H				;2Cycles	1
;		movsf	[4],ECANCON				;2Cycles	1
;		movsf	[5],PCLATH				;2Cycles	1
;		movff	FSR2_bak,FSR2L			;2Cycles	1
;		movff	FSR2_bak+1,FSR2H		;2Cycles	1
;		RETFIE	0x01					;2Cycles	1
;	@end-ex
;	@ex-desc 
;
;	@status Tested
;
;	@stacklevel 0
;
;	@registers TMR0
;
;*/
Delay.Isr macro
;	nop
	movlw	(0x100-0xFA+.31)		;1Cycle		n	; 0x100 - (50u) +  (Delay.Isr) +  (Interrupt)
	movwf	TMR0L					;1Cycle		n
	decfsz	Delay.CounterL			;2Cycle		1
	bra		Delay.Isr.End			;2Cycle		0
	decfsz	Delay.CounterH			;2Cycle		1
	bra		Delay.Isr.End			;2Cycle		0
	bsf		Delay.Returned			;1Cycle		1
Delay.Isr.End
	endm

;/*
;
;	This function starts a delay routine with the given time in us.
;	Appropriate values are multiples of 50 us up to a maximum of ~3.27 seconds.
;	To wait for the counter to finish call Delay.Wait
;	
;	@param Delay.CounterH The high byte of the multiplicator
;	@param w The low byte of the multiplicator
;
;	@return Delay.Returned 1 if counter is zero, 0 otherwise
;
;	@example
;	banksel PORTB
;	bsf		PORTB,0
;	Delay.Mikros .50000
;	call	Delay.Wait		;waits untill the 50ms are over
;	banksel PORTB
;	bcf		PORTB,0
;	@end-ex
;	@ex-desc This sets Pin RB0 high for approx. 50 ms
;
;	@status Tested
;
;	@stacklevel /*/Delay.Start8 /*/Delay.Start16
;	@calls Delay.Start8 /*/Delay.Start8 Delay.Start16 /*/Delay.Start16
;	@registers INTCON T0CON
;
;*/
Delay.Mikros	macro time
	if (time/.50) > 0xFFFF
		error "The requested delay time exceeds the capability of this module (0xFFFF * 50us)"
	else
		if (time/.50) < .256
			movlw	(time/.50)
			call	Delay.Start8
		else
			if	((low (time/.50)) == .0)
				movlw	(high (time/.50))
			else
				movlw	((high (time/.50))+1)
			endif
			movwf	Delay.CounterH
			movlw	low (time/.50)
			call	Delay.Start16
		endif
	endif
	endm

⌨️ 快捷键说明

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