6-3
Programming Examples
The following example shows how to output data in BASIC. The example
is in BASIC but translates readily into other programming languages.
Since the DACs have 12-bit resolution, data D should be in the range 0 to
4095 decimal. First, split the data into the two bytes DL% (low) and DH%
(high), as follows:
05 DH% = INT(D/16)
’Generate high byte
10 DL% = D - 16*DH%
’Derive remainder in low byte
20 DL% = 16* DL%
’Shift low nibble four places
30
’ left
Next write the data to the DAC. The example uses DAC 0 with a base
address of 300h.
40 OUT &H300, DL%
’Low byte
50 OUT &H301, DH%
’High byte and load
An assembly language routine is even simpler. Assume AX contains the
data and DX has the base address. Use the following statements to write
to DAC 0:
MOV CL,4
;Set up for four left shifts
SAL AX,CL
;Left justify data
OUT DX,AX
’Write to DAC 0
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com