REM ADC control program. REM This program shows how to access the MC145050 Via the Printer Port. REM Replace the main body of this program to do what you want. REM MFL'94 REM Define constants for use latter CONST power = &H70 CONST clock = &H4 CONST cs = &H2 CONST eoc = &H40 CONST addressbit = &H8 CONST datamask = &H80 CONST BIT0 = 1 CONST BIT1 = 2 CONST BIT2 = 4 CONST BIT3 = 8 CONST outputaddress = &H378: REM lpt1 CONST inputaddress = &H379 REM initialise port give power and cs hi. OUT outputaddress, power OR cs REM Your code goes here. E.G. nexttosample = 0: REM Use this variable to specify which channel is next to be converted. REM Note 0-10 are the input channels and 11,12,13 are internal references, Vref,Vref/2,0V GOSUB SAMPLE: REM Dummy Read to set address. FOR j = 1 TO 14 nexttosample = j GOSUB SAMPLE PRINT Value NEXT REM Power Down. OUT outputaddress, 0 STOP REM now read in a sample... This is the Subroutine that does it all REM Order of events... REM Wait for EOC. Make sure its ok to read the ADC. REM Chip Select low. REM Output the address MSB first onto the ADDR pin of the ADC REM Read in the result of the last conversion. REM and put it in the LSB of the Value read in. REM Clock the ADC. REM Move on to next bit of address. when past the end of the real 4bit address all zero's are output. REM Repeat address, data and clock loop for all data bits (10) REM Chip select HIGH. This with the clocked data transfer has started the next conversion on the channel specified in the address sent. REM Convert Value into Volts. Note that BUSY is inverted so data bits have to be inverted before thay are used. SAMPLE: Value = 0 nextaddress = nexttosample AND &HF REM wait for EOC WHILE (INP(inputaddress) AND eoc) = 0 WEND REM before clock data put the cs lo. OUT outputaddress, power FOR i = 1 TO 10 REM output the address OUT outputaddress, power OR (nextaddress AND addressbit) REM read in data bits MSB first. Value = ((INP(inputaddress) AND datamask) / 128) OR (Value * 2) REM rising edge of clock... OUT outputaddress, clock OR power OR (nextaddress AND addressbit) REM Move to next bit of address, if past the end zeros outputed. nextaddress = nextaddress * 2 NEXT i REM finished therefore cs to hi. Therefore start next conversion. OUT outputaddress, power OR cs REM convert to volts Value = (Value XOR &H3FF) AND &H3FF Value = Value * 2.5 / 1024 RETURN