' A-626 test prog
' write by chen yue lin
' date 1996,01,13
' version 1


DEF SEG = &HB800

bas = &H2C0              ' d/a card

bas2 = &H2A0             ' d/i/o card  1

bas1 = &H2E0 + 12           ' 6126 led board card  2

OUT bas1 + 0, &HFF
OUT bas1 + 1, &HFF
OUT bas1 - 12, &HFF
OUT bas1 - 11, &HFF

l = 0
vrp = 219
lin = 196
str = 179
lco = 218
rco = 191
ch = 0
4 va = 0
UB = 0




CLS

MAIN:

GOSUB phm
l = 0
LOCATE 2, 15: PRINT " --------------------   A-626 CALABRATION PROGRAM -------------------"
LOCATE 4, 10: PRINT " 1. PRESS < + > , < - > TO CHANGE CHANNEL."
LOCATE 5, 10: PRINT " 2. PRESS < U > , < B > TO CHANGE UNIBOLAR OR BIPOLAR."
LOCATE 6, 10: PRINT " 3. PRESS < A > , < V > TO CHANGE VOLTAGE OUT OR CURRENT LOOP."
LOCATE 7, 10: PRINT " 4. PRESS < T > TO TESTING D/I/O . < L > TO TEST ALL.  "
LOCATE 8, 10: PRINT " 5. PRESS < F > TO TEST VOLATEGE ."


WHILE l = 0
 S$ = INKEY$
 IF S$ <> " " THEN GOSUB SELCH
 IF S$ = "Q" OR S$ = "q" THEN l = 1
 IF S$ = "L" OR S$ = "l" THEN GOSUB TESTLOO
 IF S$ = "F" OR S$ = "f" THEN GOSUB DAOVF

WEND





END   '  -----------------------end-------------------------'


SELCH:

IF S$ = "=" OR S$ = "+" THEN ch = ch + 1
IF S$ = "-" THEN ch = ch - 1
IF ch > 5 THEN ch = 0
IF ch < 0 THEN ch = 5
IF S$ = "V" OR S$ = "v" THEN va = 0
IF S$ = "A" OR S$ = "a" THEN va = 1
IF S$ = "U" OR S$ = "u" THEN UB = 0
IF S$ = "B" OR S$ = "b" THEN UB = 1
IF S$ = "t" OR S$ = "T" THEN GOSUB DIOT

IF va = 1 THEN UB = 0


IF UB = 0 THEN
     UBC$ = " NOW TESTING UNIPOLAR "
     vlu$ = " UNTILL DVM = 4.9988 V "
     ubn = 2
   ELSE
     UBC$ = " NOW TESTING BIPOLAR  "
     vlu$ = " UNTILL DVM = 0.0000 V "
     ubn = 1
END IF
IF va = 0 THEN
      VAC$ = " NOW TESTING VOLTAGE OUTPUT "
      vlu$ = " UNTILL DVM = 4.9988 V "
      IF UB = 1 THEN vlu$ = " UNTILL DVM = 0.0000 V "
   ELSE
      VAC$ = " NOW TESTING CURRENT LOOP   "
      vlu$ = " UNTILL DAM = 4.0000 mA"
      ubn = 3
END IF


IF UB = 0 THEN
     JUMC$ = " JP9 - JP24 SHOULD BE SET TO 2-3 "
   ELSE
     JUMC$ = " JP9 - JP24 SHOULD BE SET TO 1-2 "
END IF




LOCATE 17, 10: PRINT VAC$
LOCATE 18, 10: PRINT UBC$; "   "; JUMC$
LOCATE 9, 10: PRINT " D/A CH = "; ch; "  "; "Trim  VR"; ch + 1; "-"; ubn; " "; vlu$
LOCATE 13, 8: PRINT "읕컴컴컴컴VOLTAGE OUT컴컴컴컴켸   읕CURRENT OUT켸"
LOCATE 14, 8: PRINT "      USE VOLTAGE METER (DVM)         USE DAM "







GOSUB phm


RETURN





phm:
LOCATE 10, 5: PRINT STRING$(60, CHR$(lin))
IF va = 0 THEN
   FOR i = 0 TO 40 STEP 2
       IF UB = 0 THEN mp = 2 ELSE mp = 0
    
       LOCATE 10, 8 + mp + ch * 4
       PRINT CHR$(2)
       xyp = 2 * (9 * 80 + 7 + mp - ch * 4)
       POKE xyp + 1, &H7
       xyp = 2 * (9 * 80 + 7 + mp + ch * 4)
       POKE xyp + 1, &HF8
   NEXT i
ELSE
    FOR i = 0 TO 40 STEP 2
    
       LOCATE 10, 42 + ch * 2
       PRINT CHR$(2)
       xyp = 2 * (9 * 80 + 41 - ch * 2)
       POKE xyp + 1, &H7
       xyp = 2 * (9 * 80 + 41 + ch * 2)
       POKE xyp + 1, &HF8
    NEXT i
END IF

FOR i = 1 TO 24 STEP 4
    LOCATE 12, 9 + i: PRINT CHR$(177)
    LOCATE 12, 7 + i: PRINT CHR$(219)
    LOCATE 12, 42 + i / 2: PRINT CHR$(176)



NEXT i





GOSUB daov


RETURN

daov:

IF UB = 0 THEN
OUT bas + ch * 2, &HF
OUT bas + ch * 2 + 1, &HFF
END IF
IF UB = 1 THEN
OUT bas + ch * 2, 8
OUT bas + ch * 2 + 1, 0
END IF

GOSUB OLED
RETURN

DAOVF:
IF UB = 0 THEN VS = 0: VE = 5
IF UB = 1 THEN VS = -5: VE = 5
FOR ch = 0 TO 5
BEEP: BEEP
    FOR DELA = 1 TO 5000: NEXT DELA


FOR VO = VS TO VE STEP .5
    BEEP
    FOR DELA = 1 TO 5000: NEXT DELA
   
IF UB = 0 THEN
   avdata = FIX(VO * 4096 / 5) - 1
   MSB = FIX(avdata / 256)
   LSB = avdata - MSB * 256
   OUT bas + ch * 2, MSB
   OUT bas + ch * 2 + 1, LSB
   
END IF


IF UB = 1 THEN
   
   avdata = FIX((VO * 2048 / 5) + 2048) - 1
   MSB = FIX(avdata / 256)
   LSB = avdata - MSB * 256
   OUT bas + ch * 2, MSB
   OUT bas + ch * 2 + 1, LSB
   
END IF
LOCATE 20, 10: PRINT " D/A CHANNEL "; ch;
PRINT USING " OUT Voltage : ##.####"; VO

GOSUB OLED

NEXT VO
NEXT ch

RETURN







OLED:          ' use 720 let the led light

IF UB = 0 OR va = 1 THEN
   IF ch = 0 THEN od = 1: b = 1: dvmch = 1: vach = 16: vaba = 0
   IF ch = 1 THEN od = 2: b = 1: dvmch = 2: vach = 32: vaba = 0
   IF ch = 2 THEN od = 4: b = 1: dvmch = 4: vach = 64: vaba = 0
   IF ch = 3 THEN od = 8: b = 1: dvmch = 8: vach = 128: vaba = 0
   IF ch = 4 THEN od = 16: b = 1: dvmch = 16: vaba = -11: vach = &HFF - 4
   IF ch = 5 THEN od = 32: b = 1: dvmch = 32: vaba = -11: vach = &HFF - 8
END IF

IF UB = 1 THEN
   IF ch = 0 THEN od = 64: b = 1: dvmch = 1
   IF ch = 1 THEN od = 128: b = 1: dvmch = 2
   IF ch = 2 THEN od = 1: b = 0: dvmch = 4
   IF ch = 3 THEN od = 2: b = 0: dvmch = 8
   IF ch = 4 THEN od = 4: b = 0: dvmch = 16
   IF ch = 5 THEN od = 8: b = 0: dvmch = 32
END IF

REM IF ub = 1 THEN od = od * 2
 
IF va = 1 THEN od = 0
IF va = 0 THEN mutich = &HFF - od ELSE od = 0: mutich = &HFF - dvmch: b = 2




IF b = 0 THEN OUT bas1 + 1, &HFF: OUT bas1 - 12, &HFF: OUT bas1 - 11, &HFF
IF b = 1 THEN OUT bas1, &HFF: OUT bas1 - 12, &HFF: OUT bas1 - 11, &HFF
IF b = 2 THEN OUT bas1 + 0, &HFF: OUT bas1 + 1, &HFF

REM IF VA = 0 THEN OUT bas1 - 13, &HFF


OUT bas1 + b, &HFF - od
IF va = 1 THEN OUT bas1 + vaba, &HFF - vach: OUT bas1 - 12, &HFF: OUT bas1 - 11, &HFF
IF vaba = -11 AND va = 1 THEN
         OUT bas1 + vaba - 1, &HFF - vach
         OUT bas1 + vaba, &HFF - vach
END IF

IF va = 0 THEN
   OUT bas2 + 0, dvmch
   OUT bas2 + 1, 0
ELSE
   OUT bas2 + 1, dvmch
   OUT bas2, 0
END IF


RETURN

DIOT:
errdio = 0
FOR bitt = 0 TO 255
   
    
    OUT bas + 12, bitt
    OUT bas + 13, bitt
   
    bitin1 = INP(bas + 14)
    bitin2 = INP(bas + 15)
   
    bit = bitin1
    ret = 3
    GOSUB show
    bit = bitin2
    ret = 4
    GOSUB show
    OUT bas1, &HFF - bitin1
    OUT bas1 + 1, &HFF - bitin2
   
IF bitt <> bitin1 OR bitt <> bitin2 THEN errdio = errdio + 1
NEXT bitt
IF errdio = 0 THEN
   BEEP
   LOCATE 22, 20: PRINT " ********   THE D/I/O IS GOOD   ************  "
   ELSE
   LOCATE 22, 20: PRINT " *******THE D/I/O HAVE SOME POUBLEM*********  "
   GOSUB TEST2
END IF

RETURN

TEST2:
     LOCATE 22, 15: PRINT "  !!!!!!!!!!  FOUND ERROR   !!!!!!!!!!!"
     ggg = 1
     P = 1
     FOR i = 0 TO 28 STEP 4
         OUT bas + 12, ggg
         OUT bas + 13, ggg
         FOR WIT = 1 TO 5000: NEXT WIT
             ox = INP(bas + 14): oy = INP(bas + 15)
             
             
             OUT bas1, &HFF - ox
             OUT bas1 + 1, &HFF - oy

         LOCATE 20, 11 + i: PRINT "O"
         LOCATE 20, 71 - i: PRINT "O"
         
         IF ggg <> ox THEN
            LOCATE 20, 11 + i
            PRINT "X"
            TESTE2 = TESTE2 + 1
            erroda1 = ggg + erroda1
            BEEP
        OUT bas1, &HFF - erroda1
        OUT bas1 + 1, &HFF - erroda2
        
        
         END IF

         IF ggg <> oy THEN
            LOCATE 20, 71 - i
            PRINT "X"
            teste3 = teste3 + 1
            erroda2 = ggg + erroda2
            BEEP
        OUT bas1, &HFF - erroda1
        OUT bas1 + 1, &HFF - erroda2
       
       
        END IF
        

         ggg = ggg * 2
     NEXT i
     LOCATE 22, 15: PRINT "******  FOUND ERRROR ........ERROR COUNT:"; TESTE2
     BEEP: BEEP
     
     
RETURN

show:
    bit1 = bit / 2
    BIT1I = INT(bit / 2)
    BIT2 = bit / 4
    BIT2I = INT(bit / 4)
    BIT3 = CINT(bit / 8)
    BIT3I = INT(bit / 8)
    BIT4 = CINT(bit / 16)
    BIT4I = INT(bit / 16)
    BIT5 = CINT(bit / 32)
    BIT5I = INT(bit / 32)
    BIT6 = CINT(bit / 64)
    BIT6I = INT(bit / 64)
    BIT7 = CINT(bit / 128)
    BIT7I = INT(bit / 128)
  
    IF bit1 > BIT1I THEN B1$ = "O" ELSE B1$ = "-"
    IF BIT2 > BIT2I THEN B2$ = "O" ELSE B2$ = "-"
    IF BIT3 > BIT3I THEN B3$ = "O" ELSE B3$ = "-"
    IF BIT4 > BIT4I THEN B4$ = "O" ELSE B4$ = "-"
    IF BIT5 > BIT5I THEN B5$ = "O" ELSE B5$ = "-"
    IF BIT6 > BIT6I THEN B6$ = "O" ELSE B6$ = "-"
    IF BIT7 > BIT7I THEN B7$ = "O" ELSE B7$ = "-"
    IF bit > 128 THEN B8$ = "O" ELSE B8$ = "-"

   
     WHILE ret = 0
        LOCATE 16, 11: PRINT B1$
        LOCATE 16, 15: PRINT B2$
        LOCATE 16, 19: PRINT B3$
        LOCATE 16, 23: PRINT B4$
        LOCATE 16, 27: PRINT B5$
        LOCATE 16, 31: PRINT B6$
        LOCATE 16, 35: PRINT B7$
        LOCATE 16, 39: PRINT B8$
        ret = 2
     WEND
     WHILE ret = 1
        LOCATE 16, 71: PRINT B1$
        LOCATE 16, 67: PRINT B2$
        LOCATE 16, 63: PRINT B3$
        LOCATE 16, 59: PRINT B4$
        LOCATE 16, 55: PRINT B5$
        LOCATE 16, 51: PRINT B6$
        LOCATE 16, 47: PRINT B7$
        LOCATE 16, 43: PRINT B8$
        ret = 2
     WEND

     WHILE ret = 3
        LOCATE 20, 11: PRINT B1$
        LOCATE 20, 15: PRINT B2$
        LOCATE 20, 19: PRINT B3$
        LOCATE 20, 23: PRINT B4$
        LOCATE 20, 27: PRINT B5$
        LOCATE 20, 31: PRINT B6$
        LOCATE 20, 35: PRINT B7$
        LOCATE 20, 39: PRINT B8$
        ret = 2
     WEND
     WHILE ret = 4
        LOCATE 20, 71: PRINT B1$
        LOCATE 20, 67: PRINT B2$
        LOCATE 20, 63: PRINT B3$
        LOCATE 20, 59: PRINT B4$
        LOCATE 20, 55: PRINT B5$
        LOCATE 20, 51: PRINT B6$
        LOCATE 20, 47: PRINT B7$
        LOCATE 20, 43: PRINT B8$
        ret = 2
     WEND


RETURN

TESTLOO:
TL = 0: ch = 0: va = 0: UB = 0
WHILE TL <= 2
      FOR ch = 0 TO 7
          GOSUB SELCH
          GOSUB DELOOP
      NEXT ch
      TL = TL + 1
      IF TL = 1 THEN
        UB = 1
        LOCATE 9, 9: PRINT "* PLEASE CHANGE JUMPER JP9-JP24 THEN PRESS <ENTER> *";
        WHILE PL < 50
               PSL = 2 * (8 * 80 + 9 + PL)
               POKE PSL + 1, &HF8
               PL = PL + 1
        WEND
        PL = 0
        INPUT K

        WHILE PL < 50
               PSL = 2 * (8 * 80 + 9 + PL)
               POKE PSL + 1, &H7
               PL = PL + 1
        WEND
      END IF
      PL = 0
      IF TL = 2 THEN
        va = 1: UB = 0
        LOCATE 9, 9: PRINT "**    PLEASE CHANGE DVM TO DAM THEN PRESS < ENTER >    **";
        WHILE PL < 50
               PSL = 2 * (8 * 80 + 9 + PL)
               POKE PSL + 1, &HF8
               PL = PL + 1
        WEND
        PL = 0
        INPUT K

        WHILE PL < 50
               PSL = 2 * (8 * 80 + 9 + PL)
               POKE PSL + 1, &H7
               PL = PL + 1
        WEND

     END IF


WEND
GOSUB DIOT


RETURN

DELOOP:
    FOR DELAY = 1 TO 5000
      S$ = INKEY$
      IF S$ = "E" OR S$ = "e" THEN GOTO MAIN
   NEXT DELAY
RETURN

   

