;File: dac42out.a51
;Author: Eckart Hartmann Date:17/10/2003
;Development progress: Dac842.df
;
;DacOut==========Output a value on DAC.
;C Function prototype: char DacOut(char cChan, int iDac);
;Description of Function: Causes iDac to be output on channel cChan.
;User interface: Set DAC options by executing DacCfg(). 
;		Put channel number in first parameter. 
;		Put iDac in second parameter. 
;		Call DacOut. Parameter2 is output on appropriate DAC pin.
; 		Returns 1 if parameter in range, else 0.
;Robustness:	If parameter2 >4095 output full scale.
;		If parameter<0 output 0.
;Side effects:	Overwrites a, P.
;
NAME DACOUT
$NOMOD51
 $IC(..kei842.inc) ; Parameter passing registers for Keil .
 $IC(..kei842.dat) ; SFR definition for Keil .
;
public _DacOut

?PR?_DacOut?DACOUT	SEGMENT CODE
	RSEG	?PR?_DacOut?DACOUT

_DacOut:
	orl	DACCON,#3	;Activate DAC.
	mov	a,iP2hc		;if(iDac<0)
	jnb	ACC.7,DaOPos
	mov	iP2hc,#0h	; output zero.
	mov	iP2lc,#0h
	mov	a,#080h		;Mark range error.
	sjmp	DaOG
DaOPos:	anl	a,#0f0h		;else if(iDac>0xfff)
	jz	DaOG
	mov	iP2hc,#00fh	; output full scale.
	mov	iP2lc,#0ffh
	mov	a,#080h		;Mark range error.
DaOG:	xch	a,cP1l
	jz	DaO0		;if(cChan)
	mov	DAC1H,iP2hc	; DAC1H/L = iDac;
	mov	DAC1L,iP2lc
	sjmp	DaOOut
DaO0:	mov	DAC0H,iP2hc	; DAC0H/L = iDac;
	mov	DAC0L,iP2lc
DaOOut:	mov	cP1l,#1		;Good return
	xch	a,cP1l		;if(error)
	cjne	a,#080h,DaOR
	mov	cP1l,#0		; bad return.
DaOR:	ret
;
;Function End==========================================================Function End
END



