MR2/ICE #10183
-----------------------------------------------------------
/*=== ADCInit: Initialize ADC ===*/
void ADCInit(BYTE idbRange)
{
outportb(ADC_BASE + 3, idbRange); // Init range
} // ADCInit
/*=== ADCRead: Read ADC channel ===*/
BOOL ADCRead(BYTE ibChan, short *psADCData)
{
USHORT c;
BYTE low;
BYTE high;
short sADData;
BOOL fOK;
outportb(ADC_BASE + 2, ibChan); // select A/D channel
for (c = 1; c < 25; c++)
; // wait 100 uSec for mux to settle - fixme to time
outportb(ADC_BASE + 1, 0); // start 12 bit conversion
while (inportb(ADC_BASE + 2) & ADC_BUSY && ++c < 500)
; // Wait for conversion to complete
fOK = c < 500; // False if conversion timeout
/* Read 12 bit ADC value
Data comes in normalized with MSB in bit 15 of data word
*/
low = inportb(ADC_BASE);
high = inportb(ADC_BASE + 1);
sADData = ((USHORT)high << 8) | low;
sADData -= 0x8000; // Remove offset
sADData = sADData >> 4; // Scale to 12 bits
*psADCData = sADData; // Stow
return fOK;
} // ADCRead
/*=== ADCReadStatus: Read ADC status word ===*/
BYTE ADCReadStatus(void)
{
return inportb(ADC_BASE + 2);
} // ADCReadStatus
=====================================================
To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".
For problems, contact the list owner at
"rollin@scoug.com".
=====================================================
<< Previous Message <<
>> Next Message >>
Return to [ 20 |
May |
1999 ]
The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS
RESERVED.
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International
Business Machines Corporation.
All other trademarks remain the property of their respective owners.