
CLS
bas = &H220
gc889 = 0
gn = .5

OUT bas + 9, 0
OUT bas + 10, 0
OUT bas + 11, 1
OUT bas + 12, 1




l = 0
WHILE l = 0
  
  v$ = INKEY$
  GOSUB gain889
  IF v$ = "Q" OR v$ = "q" THEN l = 1
  IF v$ = "C" OR v$ = "c" THEN GOSUB calibra
  LOCATE 2, 15: PRINT "      889 mux test press <Q> to quit    "
  LOCATE 3, 12: PRINT " Press <C> will goto Calibration program "
  LOCATE 4, 12: PRINT USING "Gain Select (0-7) Gain code = ####.# "; gn
  LOCATE 5, 12: PRINT " This Program can be A-821PG , A-822PG , A-823PG Used "

  LOCATE 8, 55: PRINT "=== Jumper Setting ==="
  LOCATE 10, 55: PRINT " JP16 Position : 0 "
  LOCATE 11, 55: PRINT " JP17 Position : 9 "
  LOCATE 12, 55: PRINT " JP18 Position : R "
  LOCATE 13, 55: PRINT " JP19 Position : PC "
  LOCATE 14, 55: PRINT " JP0 - JP15 : Close "

  FOR i = 0 TO 15

  OUT bas + 13, i + gc889

  OUT bas + 10, 0
  FOR delay = 1 TO 200: NEXT delay
  r = 0
  OUT bas + 12, 0
  WHILE r = 0
    msb = INP(bas + 5)
    IF msb < 16 THEN r = 1
  WEND
 
  lsb = INP(bas + 4)
  adda = msb * 255 + lsb
  advo = (adda - 2048) * 5 / 2048
  LOCATE i + 8, 5: PRINT USING "vol:##.####V "; advo;
  PRINT USING "  Data : #### "; adda;
  PRINT USING "  ch: ## "; i;
  d$ = "            "
  IF advo > 3.5 THEN d$ = " <----- O.K"
  PRINT d$
NEXT i
GOSUB cjc



WEND
END
           ' ======================= CALIBRATION ===================

calibra:
CLS
gc889 = &H70: gn = 1000
calop = 0
WHILE calop = 0
v$ = INKEY$
GOSUB gain889
IF v$ = "e" OR v$ = "E" OR v$ = "Q" OR v$ = "q" THEN calop = 1


LOCATE 2, 25: PRINT " Short A.GND , CH0LO , CH0HI "
LOCATE 3, 25: PRINT " Adjustment VR1 Untill reading 4094/4095 "

FOR delay = 1 TO 8000: NEXT delay
OUT bas + 13, gc889
OUT bas + 10, 0
OUT bas + 12, 0

cal = 0
WHILE cal = 0
      camsb = INP(bas + 5)
      IF camsb < 16 THEN cal = 1
WEND

calsb = INP(bas + 4)
caldata = camsb * 256 + calsb

LOCATE 4, 26: PRINT USING "Adjustment (2048/2049) VR1:####"; caldata
LOCATE 6, 26: PRINT " Press <E> will return to main program !"
LOCATE 7, 26: PRINT USING " DB-889D GAIN Control = ####.#"; gn
GOSUB cjc

WEND
CLS
gc889 = &H10: gn = 1

RETURN

gain889:

IF v$ = "0" THEN gc889 = &H0: gn = .5
IF v$ = "1" THEN gc889 = &H10: gn = 1
IF v$ = "2" THEN gc889 = &H20: gn = 5
IF v$ = "3" THEN gc889 = &H30: gn = 10
IF v$ = "4" THEN gc889 = &H40: gn = 50
IF v$ = "5" THEN gc889 = &H50: gn = 100
IF v$ = "6" THEN gc889 = &H60: gn = 500
IF v$ = "7" THEN gc889 = &H70: gn = 1000

RETURN

cjc:

OUT bas + 10, 9
FOR delay = 1 TO 1500: NEXT
LOCATE 19, 55: PRINT " CJC Channel : 9 "


OUT bas + 12, 0

chdrdy = 0

WHILE chdrdy = 0
         IF CONTER >= 1000 THEN CONTER = 0: BEEP: OUT bas + 12, 0
         x = INP(bas + 5)
         IF x < 15 THEN chdrdy = 1
       
         CONTER = CONTER + 1

WEND

y = INP(bas + 4)

rtda = x * 256 + y
rt = (rtda - 2048) * 5 / 2048 / .0244
LOCATE 21, 55: PRINT USING " roomtemp.: ####.# C   "; rt

RETURN

