www.pudn.com > 8051_pppsrc.zip > delay.c, change:2001-02-09,size:2005b


/****************************************************************************** 
File Name : Delay.c 
 
Author : Rene Trenado 
 
Location : Motorola Applications Lab, Baja California 
 
Date Created : July 2000 
 
Current Revision : 0.0 
 
Notes : This file contains the code for a variable Delay function  
*******************************************************************************/ 
 
#include "delay.h" 
 
BYTE delayCounter; 
 
 
/*********************************************************************** 
Function :	Delay 
 
Parameters : 	A Byte containing the number of times __Delay will be 
		called 
 
Date : 		July 2000 
 
Desc : 		This function blocks the CPU in multiples of _Delay times	 
 
***********************************************************************/ 
void Delay (register BYTE times) { 
	_Delay();	 
} 
 
 
/*********************************************************************** 
Assembly Function :	__1msDelay 
 
Parameters : 	None 
 
Date : 		July 2000 
 
Desc : 		This function blocks the CPU in multiples of 1.3mSecs 
		delayCount specifies the time base 
		__1msDelay = delayCounter x 1.3 mSec 
 
***********************************************************************/ 
#asm 
 
	xref.b	_delayCounter 
	xdef	__Delay 
 
BUSFREQ:	EQU		2 
 
_1msDelay: 
		PSHA					;2 cycles 
		LDA		#BUSFREQ		;2 
DLLoop:	        DBNZA	        DLSub			;3 
		BRA		DLDone			;3 
DLSub:	         
		MOV		#$FF,_delayCounter 	;4 
Here: 
		DBNZ	        _delayCounter,Here	;5 
		BRA		DLLoop			;3 
DLDone:	        PULA					;2 
		RTS					;4 
 
 
/*********************************************************************** 
Function :	_Delay 
 
Parameters : 	A Byte containing the number of times a base delay will be 
		called 
 
Date : 		July 2000 
 
Desc : 		This function blocks the CPU in multiples (Acc value) of  
		delay times 
 
***********************************************************************/ 
 
__Delay:         
		JSR   	        _1msDelay 
		DBNZA           __Delay 
		RTS 
 
#endasm