'**************************************************************************** '* '* Copyright: 1992-1995 Pico Technology Limited '* '* Module: ADC-10.BAS '* '* Author: Alan Tong '* Pico Technology Limited '* Broadway House '* 149-151 St Neots Road '* Hardwick '* Cambridge CB3 7QJ. U.K. '* Tel. 01954 211716 '* Fax. 01954 211880 '* Email: 100073,2365@compuserve.com '* '* Connections to ADC-10: '* Control: Output Address '* '* Bit 7 6 5 4 3 2 1 0 '* Pin 9 8 7 6 5 4 3 2 '* PWR PWR PWR PWR PWR PWR *CS CLK '* '* Input: Input Address '* '* Bit 7 6 5 4 3 2 1 0 '* Pin 11 '* DATA '* '* Description: This module contains a Quick Basic routine to drive '* the PICO ADC-10. It was written using the 'QBASIC' '* program supplied with DOS 5. '* History: '* ?????92 ADT Created '* 09Sep93 MKG Add notes on use of DEBUG '* 16Sep93 MKG Use constants for bits '* 20Sep93 ADT Autodetection of printer port addresses '* 27Sep93 ADT Changes following review '* 29Sep93 MKG Add revision info '* 11Feb95 MKG Ask for port '* '* Revision Info: "file %n date %f revision %v" '* "file ADC-10.BAS date 11-Feb-95,17:32:30 revision 4" '* '**************************************************************************** 'define subroutines DECLARE SUB Adc10DriverOpen (port) DECLARE SUB ADC10GetValue () 'define constants CONST POWER% = &HFC CONST POWEROFF% = &H0 CONST CS% = &H2 CONST CLOCK% = &H1 CONST clocklow% = &HFC CONST DATABIT% = &H80 'global variables DIM SHARED outputaddress% DIM SHARED portin% DIM SHARED adc% '*************************************************************************** '* '* Start of program '* '*************************************************************************** 'say hello PRINT "ADC-10 BASIC driver: Version 1.3" PRINT "Copyright 1992-1995 Pico Technology Limited" 'ask which port to use... ' port is 1 for LPT1, 2 for lpt2 etcetera INPUT "Printer port (1..4):", port CALL Adc10DriverOpen(port) PRINT "Press any key to start displaying readings" PRINT "Press a key again to stop" WHILE INKEY$ = "" WEND debut = TIMER WHILE INKEY$ = "" CALL ADC10GetValue PRINT "ADC-10 reading = "; adc%, PRINT USING "ADC-10 voltage = #.## V"; ((5 * adc%) / 255) compteur = compteur + 1 WEND PRINT compteur / (TIMER - debut); "mesures par seconde." END '*************************************************************************** '* '* Adc10DriverOpen '* This routine sets port addresses and powers up the ADC-10 '* '* accepts: '* 1 - use LPT1 '* 2 - use LPT2 '* 3 - use LPT3 '* 4 - use LPT4 '* '* sets: '* outputaddress '* portin '* '*************************************************************************** ' SUB Adc10DriverOpen (port) 'read the port addresses from the BIOS DEF SEG = 0 addr% = &H408 + 2 * (port - 1) outputaddress% = PEEK(addr%) + (PEEK(addr% + 1) * 256) portin% = outputaddress% + 1 'power up the ADC-10 OUT outputaddress%, POWER% + CS% END SUB '*************************************************************************** '* '* Adc10GetValue '* This routine starts a new conversion and gets the result of '* the PREVIOUS conversion. (The first result is invalid as no '* conversion has been performed). '* '* Sets: '* adc% - result of previous conversion '* '*************************************************************************** ' SUB ADC10GetValue OUT outputaddress%, POWER% ' chip select low bits% = 0 'data is read into this string one bit at a time ' FOR j% = 1 TO 8 'read in 8 bits from ADC-10 (or TLC548) serially FOR j% = 1 TO 9 'read in 9 bits from ADC0831 serially OUT outputaddress%, POWER% + CLOCK% 'switch clock high 'the next line reads the input port, then performs an 'AND' 'to leave only the data bit from the ADC-10 that we want. 'Next it does a binary shift to the left by multiplying by two bits% = (INP(portin%) AND DATABIT%) + bits% * 2 OUT outputaddress%, POWER% 'switch clock low NEXT OUT outputaddress%, POWER% + CS% ' chip select high ' divide the accumulator by DATABIT% and invert the bits adc% = (bits% / DATABIT%) XOR &HFF END SUB