V章で利用したプログラム
'------------------------------------------------- ' タイマ1,2を使った速度,加速度の測定 '------------------------------------------------- ' DECLARE SUB DisplayFkey (fkeycode!) DECLARE SUB InitScreen () DECLARE SUB GetCount (count1!,count2!) DECLARE SUB ClearCount () DECLARE SUB SetUnittime (unit,time!) DECLARE SUB StartDevice () DECLARE SUB EndDevice () DECLARE SUB LargePrintB (y!, x!, printdata!) DECLARE SUB LargePrintA (y!, x!, stringdata$) DECLARE SUB Large1char (y!, x!, 1cod!) dist = .00254 * 16 unit.time = 10 InitScreen status = 1 displaymode = 1 ON KEY(5) GOSUB Fkey5: ON KEY(6) GOSUB Fkey6 ON KEY(7) GOSUB Fkey7: ON KEY(8) GOSUB Fkey8 StartDevice SetUnittime unit, time WHILE status GOSUB RsetScreen WHILE INKEY$ <> " " KEY(5) ON: KEY(6) ON: KEY(7) ON: KEY(8) ON GOSUB Calculate KEY(5) STOP: KEY(6) STOP: KEY(7) STOP: KEY(8) STOP GOSUB DisplayData WEND WEND EndDevice END ResetScreen: ClearCount CLS IF displaymode = 1 THEN GOSUB Fkey6 IF displaymode = 2 THEN GOSUB Fkey7 IF displaymode = 3 THEN GOSUB Fkey8 RETURN Calculate: CALL GetCount(count1, count2) time1 = count1 * unit.time * .000001 time2 = count2 * unit.time * .000001 time = time1 - time2 / 2 IF time2 <> 0 THEN velerror = 0: vel = dist / time2 ELSE velerror = 1 END IF IF velerror = 0 AND time <> 0 THEN accerror = 0: acc = vel / time ELSE accerror = 1 END IF RETURN DisplayData: SELECT CASE displaymode CASE 1 COLOR 7 LargePrintB 3, 1, time1 LargePrintB 13, 1, time2 CASE 2 COLOR 6 LargePrintB 3, 1, time1 IF velerror = 0 THEN LargePrintB 13, 1, vel IF velerror = 1 THEN LargePrintA 13, 1, "………" CASE 3 COLOR 5 IF accerror = 0 THEN LargePrintB 8, 1, acc IF accerror = 1 THEN LargePrintA 8, 1, "………" END SELECT RETURN Fkey5: DisplayFkey 5 COLOR 6 LOCATE 20, 1: PRINT "時間測定の基準パルス幅を設定します(2〜65536μsec)" VIEW PRINT 21 TO 21 LINE INPUT tmpdata$ tmpdata = INT(VAL(tmpdata$)) IF tmpdata > 1 AND tmpdata < 65536 THEN unit.time = tmpdata SetUnittime unit.time ClearCount END IF InitScreen IF displaymode = 1 THEN GOSUB Fkey6 IF displaymode = 2 THEN GOSUB Fkey7 IF displaymode = 3 THEN GOSUB Fkey8 RETURN Fkey6: display = 1 CLS COLOR 7 LOCATE 1, 10: PRINT "センサ間の通過時間[s] (スペースキーでリセット)"; LargePrintB 3, 1, time1 LargePrintB 13, 1, time2 LOCATE 22, 50: PRINT "基準パルス"; unit.time; "マイクロ秒"; DisplayFkey 6 RETURN Fkey7: displaymode = 2 CLS COLOR 6 LOCATE 1, 10: PRINT "時間[s]と速度[m/s] (スペースキーでリセット)"; LargePrintB 3, 1, time IF velerror = 0 THEN LargePrintB 13, 1, vel IF velerror = 1 THEN LargePrintA 13, 1, "………" LOCATE 22, 50: PRINT "基準パルス"; unit.time; "マイクロ秒"; DisplayFkey 7 RETURN Fkey8: displaymode = 3 CLS COLOR 5 LOCATE 1, 10: PRINT "加速度[m/s^2] (スペースキーでリセット)"; LargePrintB 3, 1, time IF accerror = 0 THEN LargePrintB 8, 1, acc IF accerror = 1 THEN LargePrintA 8, 1, "………" LOCATE 22, 50: PRINT "基準パルス"; unit.time; "マイクロ秒"; DisplayFkey 8 RETURN SUB ClearCount PRINT #1, "f"; END SUB SUB DisplayFkey (fkeycode) IF fkeycode = 1 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 1: PRINT "f・1"; : LOCATE 25, 1: PRINT " "; IF fkeycode = 2 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 9: PRINT "f・2"; : LOCATE 25, 9: PRINT " "; IF fkeycode = 3 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 17: PRINT "f・3"; : LOCATE 25, 17: PRINT " "; IF fkeycode = 4 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 25: PRINT "f・4"; : LOCATE 25, 25: PRINT " "; IF fkeycode = 5 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 33: PRINT "f・5"; : LOCATE 25, 33: PRINT "時間幅"; IF fkeycode = 6 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 41: PRINT "f・6"; : LOCATE 25, 41: PRINT "測定値"; IF fkeycode = 7 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 49: PRINT "f・7"; : LOCATE 25, 49: PRINT "速 度"; IF fkeycode = 8 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 57: PRINT "f・8"; : LOCATE 25, 57: PRINT "加速度"; IF fkeycode = 9 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 65: PRINT "f・9"; : LOCATE 25, 65: PRINT " "; IF fkeycode = 10 THEN COLOR 14 ELSE COLOR 13 LOCATE 24, 73: PRINT "f・10"; : LOCATE 25, 73: PRINT " "; END SUB SUB EndDevice CLOSE #1 END SUB SUB GetCount (count1, count2) PRINT #1, "t"; : LINE INPUT #1, count1$ PRINT #1, "s"; : LINE INPUT #1, count2$ count1 = VAL(count1$) count2 = VAL(count2$) END SUB SUB InitScreen CLS VIEW PRINT 1 TO 25 END SUB SUB Large1char (y, x, lcod) STATIC lc$(), status IF status = 0 THEN DIM lc$(-5 TO 10, 0 TO 6) status = 1 lc$(-5, 0) = "■■■■": lc$(-4, 0) = " ": lc$(-3, 0) = " ": lc$(-5, 1) = "■■■■": lc$(-4, 1) = " ": lc$(-3, 1) = " ": lc$(-5, 2) = "■■■■": lc$(-4, 2) = " ": lc$(-3, 2) = " ": lc$(-5, 3) = "■■■■": lc$(-4, 3) = " ■ ■": lc$(-3, 3) = "■■■■": lc$(-5, 4) = "■■■■": lc$(-4, 4) = " ": lc$(-3, 4) = " ": lc$(-5, 5) = "■■■■": lc$(-4, 5) = " ": lc$(-3, 5) = " ": lc$(-5, 6) = "■■■■": lc$(-4, 6) = " ": lc$(-3, 6) = " ": lc$(-2, 0) = " ": lc$(-1, 0) = " ": lc$(-2, 1) = " ": lc$(-1, 1) = " ": lc$(-2, 2) = " ": lc$(-1, 2) = " ": lc$(-2, 3) = " ": lc$(-1, 3) = " ": lc$(-2, 4) = " ": lc$(-1, 4) = " ": lc$(-2, 5) = " ■■": lc$(-1, 5) = " ": lc$(-2, 6) = " ■■": lc$(-1, 6) = " ": lc$(0, 0) = " ■■ ": lc$(1, 0) = " ■ ": lc$(2, 0) = " ■■ ": lc$(0, 1) = "■ ■": lc$(1, 1) = " ■ ": lc$(2, 1) = "■ ■": lc$(0, 2) = "■ ■": lc$(1, 2) = " ■ ": lc$(2, 2) = " ■": lc$(0, 3) = "■ ■": lc$(1, 3) = " ■ ": lc$(2, 3) = "" ■: lc$(0, 4) = "■ ■": lc$(1, 4) = " ■ ": lc$(2, 4) = " ■■ ": lc$(0, 5) = "■ ■": lc$(1, 5) = " ■ ": lc$(2, 5) = "■ ": lc$(0, 6) = " ■■ ": lc$(1, 6) = " ■■■": lc$(2, 6) = "■■■■": lc$(3, 0) = "■■■ ": lc$(4, 0) = "■ ■ ": lc$(5, 0) = "■■■■": lc$(3, 1) = " ■": lc$(4, 1) = "■ ■ ": lc$(5, 1) = "■ ": lc$(3, 2) = " ■": lc$(4, 2) = "■ ■ ": lc$(5, 2) = "■■■ ": lc$(3, 3) = " ■■ ": lc$(4, 3) = "■ ■ ": lc$(5, 3) = " ■": lc$(3, 4) = " ■": lc$(4, 4) = "■■■■": lc$(5, 4) = " ■": lc$(3, 5) = " ■": lc$(4, 5) = " ■ ": lc$(5, 5) = " ■": lc$(3, 6) = "■■■ ": lc$(4, 6) = " ■ ": lc$(5, 6) = "■■■ ": lc$(6, 0) = " ■■ ": lc$(7, 0) = "■■■■": lc$(8, 0) = " ■■ ": lc$(6, 1) = "■ ": lc$(7, 1) = "■ ■": lc$(8, 1) = "■ ■": lc$(6, 2) = "■ ": lc$(7, 2) = "■ ■": lc$(8, 2) = "■ ■": lc$(6, 3) = "■■■ ": lc$(7, 3) = " ■ ": lc$(8, 3) = " ■■ ": lc$(6, 4) = "■ ■": lc$(7, 4) = " ■ ": lc$(8, 4) = "■ ■": lc$(6, 5) = "■ ■": lc$(7, 5) = " ■ ": lc$(8, 5) = "■ ■": lc$(6, 6) = " ■■ ": lc$(7, 6) = " ■ ": lc$(8, 6) = " ■■ ": lc$(9, 0) = " ■■ ": lc$(10, 0) = " ": lc$(9, 1) = "■ ■": lc$(10, 1) = " ": lc$(9, 2) = "■ ■": lc$(10, 2) = " ■■■": lc$(9, 3) = "■ ■": lc$(10, 3) = " ■ ": lc$(9, 4) = " ■■■": lc$(10, 4) = " ■■■": lc$(9, 5) = " ■": lc$(10, 5) = " ■ ": lc$(9, 6) = " ■■ ": lc$(10, 6) = " ■■■": END IF LOCATE y, x: PRINT lc$(lcod, 0); LOCATE y + 1, x: PRINT lc$(lcod, 1); LOCATE y + 2, x: PRINT lc$(lcod, 2); LOCATE y + 3, x: PRINT lc$(lcod, 3); LOCATE y + 4, x: PRINT lc$(lcod, 4); LOCATE y + 5, x: PRINT lc$(lcod, 5); LOCATE y + 6, x: PRINT lc$(lcod, 6); END SUB SUB LargePrintA (y, x, stringdata$) px = x: py = y: stringsize = LEN(stringdata$) dpx = 10 FOR cnt = 1 TO stringsize refchar$ = MID$(stringdata$, cnt, 1) SELECT CASE refchar$ CASE " " Large1char py, px, -1 CASE "." Large1char py, px, -2 CASE "-" Large1char py, px, -3 CASE "・" Large1char py, px, -4 CASE "D" TO "E" Large1char py, px, 10 CASE "0" TO "9" Large1char py, px, VAL(refchar$) CASE ELSE Large1char py, px, -5 END SELECT px = px + dpx NEXT END SUB SUB LargePrintB (y, x, printdata) SELECT CASE printdata CASE IS > 99999999 LargePrintA y, x, "########" CASE IS < -99999999 LargePrintA y, x, "########" CASE IS >= 0 tmpdata# = printdata tmpdata# = tmpdata# + .0000005# string1$ = LTRIM$(STR$(INT(tmpdata#))) IF LEN(string1$) <= 6 THEN string2$ = RIGHT$(STR$(INT(1000000# * tmpdata#) + 1000000#), 6) string0$ = string1$ + "." + LEFT$(string2$, 7 - LEN(string1$)) ELSE string0$ = LEFT$(" " + string1$, 8) END IF LargePrintA y, x, string0$ CASE IS < 0 tmpdata# = -printdata tmpdata# = tmpdata# + .0000005# string1$ = LTRIM$(STR$(INT(tmpdata#))) IF LEN(string1$) <= 5 THEN string2$ = RIGHT$(STR$(INT(100000# * tmpdata#) + 100000#), 5) string0$ = "-" + string1$ + "." + LEFT$(string2$, 6 - LEN(string1$)) ELSE string0$ = LEFT$(" -" + string1$, 8) END IF LargePrintA y, x, string0$ END SELECT END SUB SUB SetUnittime (unit. time) PRINT #1, "p"; STR$(unit. time) END SUB SUB StartDevice OPEN "COM1:9600,N,8,1,ASC" FOR RANDOM AS #1 END SUB |