Biomedical Engineering Reference
In-Depth Information
'
' Define variables for printer port location
' ------------------------------------------
Global prinop ' Printer Port Output Port location variable
Global prinstat ' Printer Port Status Port location variable
Global princont ' Printer Port Control Port location variable
The following VisualBasic code module (ACQUIRE.BAS) shows how the serial
protocol for the A/D is implemented.
Function Acquire(mux) As Single
'
' Function Acquire(mux) executes the A/D protocol on the
' channel specified by mux. The A/D's result in A/D counts is
' returned via the Acquire variable.
'
'
'
' Define variables
' ---------------
Dim clocknum As Integer
' clock counter variable
Dim dat As Integer
' accumulated data variable
Dim bit As Integer
' filtered data bit variable
Dim bit7 As Integer
' current value of Out D7
' Acquisition loop
' ----------------
bit7 Inp(prinop) And 2 ^ 7
' evaluate current value of Out
D7
Out prinop, power notcs sclk mux bit7 ' power up but keep CS'
deasserted and
' do not upset bit 7 of Output
port
Out prinop, power mux bit7
' convert by asserting CS', pull
SCLK low
' without upsetting bit 7 of
' Output port
For clocknum 1 To 2
' two clock pulses are required
to start
Out prinop, power sclk mux bit7
' conversion process
Out prinop, power mux bit7
Next clocknum
dat 0
' clear A/D accumulator variable
For clocknum 11 To 0 Step 1
' clock 12 bits serially
Out prinop, power sclk mux bit7
' clock pulse rising edge without
' upsetting
' bit 7 of Output port
Out prinop, power mux bit7
' clock pulse falling edge without
' upsetting
' bit 7 of Output port
bit (Inp(prinstat) And 8) / 8
' read Status port and filter bit
' corresponding
' to A/D's serial data output
Search WWH ::




Custom Search