DIM PortBits(8) AS INTEGER
elapsed = 0
CLS
SCREEN 7
COLOR 15: LOCATE 1, 10: PRINT "MS16 & MS26 Rate Test"
readings = 1
cumulative = 0
threshold = 30
average = 0
total = 0
pulse.count = -1




' INTERFACE:
'      Parallel Port  Data direction  AtoD Interface    Address
'      -------------  --------------  --------------    -------
'           b0             >>>          SCLK            888 (378h)
'           b7             >>>          CS (NEG going)  888 (378h)
'           BUSY           <<<          Dout            889 (379h)


BitYouWant% = 8
elapsed = TIMER
x = 1
WHILE INKEY$ = ""

        ' Set CS low
        OUT 888, 128   'CS High  SCLK Low -
        OUT 888, 0     'CS Low   SCLK Low - Start a conversion

        ' Get bit of data

        total = 0
        FOR n = 0 TO 11

                OUT 888, 1     'CS Low  SCLK High
                OUT 888, 0     'CS Low  SCLK Low

                PortNum% = INP(889)

                FOR i = 1 TO 8
                        PortBits%(i) = PortNum% MOD 2
                        PortNum% = FIX(PortNum% / 2)
                NEXT i
               
                BitStatus% = PortBits%(BitYouWant%)
                IF BitStatus% = 0 THEN BitStatus% = 1 ELSE BitStatus% = 0
                IF BitStatus% = 1 THEN total = total + 2 ^ (11 - n)
        NEXT n
        LOCATE 5, 5: PRINT "Syringe Driver Current="; total; "mA"; "     "

        IF total > threshold THEN
            pulse.count = pulse.count + 1
            IF pulse.count = 0 THEN elapsed = TIMER
           
            LOCATE 8, 5: PRINT "Pulse Count="; pulse.count
            IF pulse.count = 1 THEN LOCATE 12, 5: PRINT "Timer for 1 Pulse="; INT((TIMER - elapsed) * 100) / 100; "Seconds"
            IF pulse.count = 5 THEN LOCATE 14, 5: PRINT "Time for 5 Pulses="; INT((TIMER - elapsed) * 100) / 100; "Seconds"
            IF pulse.count = 10 THEN LOCATE 16, 5: PRINT "Time for 10 Pulses="; INT((TIMER - elapsed) * 100) / 100; "Seconds"
            IF pulse.count = 10 THEN
                pulse.count = -1
                elapsed = TIMER
            END IF

        SLEEP 2
        END IF
        


WEND







