COMMANDS
Key in program and type RUN.
Select conversion required.
100 REM Program P76 - Number Base Conversion 110 MODE 6 120 PRINT TAB(12,12)"N U M B E R B A S E" 130 PRINT TAB(13,14)"C O N V E R S I O N" 140 Z=INKEY(300) 150 REPEAT 160 CLS 170 PRINT '''"1. Hex to Decimal" 180 PRINT "2. Decimal to Hex" 190 PRINT "3. Octal to Decimal" 200 PRINT "4. Decimal to Octal" 210 PRINT "5. Binary to Decimal" 220 PRINT "6. Decimal to Binary" 230 INPUT ''"Enter appropriate choice "choice 240 ON choice GOSUB 290,450,510,640,750,890 ELSE PRINT ''" Wrong choice - Try again" 250 PRINT '''''"Press key for another run" 260 Z=GET 270 UNTIL 0 280 290 CLS 300 PRINT '''"1. Hex to Decimal" 310 INPUT ''"Enter Hexadecimal Number - "hex$ 320 dec%=0 330 index=0 340 REPEAT 350 digit$=RIGHT$(hex$,1) 360 d=ASC(digit$) 370 IF d>47 OR d<58 THEN d=d-48 ELSE IF d>64 AND d<71 THEN d=d-55 ELSE PRINT "Not Hex":RETURN 380 dec%=dec%+d*16^index 390 index=index+1 400 hex$=LEFT$(hex$,LEN(hex$)-1) 410 UNTIL LEN(hex$)=0 420 PRINT "Decimal is "dec% 430 RETURN 440 450 CLS 460 PRINT '''"2. Decimal to Hex" 470 INPUT ''"Enter Decimal Number - "dec% 480 PRINT "Hexadecimal is "~dec% 490 RETURN 500 510 CLS 520 PRINT '''"3. Octal to Decimal" 530 INPUT ''"Enter Octal Number - "oct% 540 dec%=0 550 index=0 560 REPEAT 570 dec%=dec%+(oct% MOD 10)*8^index 580 oct%=oct% DIV 10 590 index=index+1 600 UNTIL oct%=0 610 PRINT "Decimal is "dec% 620 RETURN 630 640 CLS 650 PRINT '''"4. Decimal to Octal" 660 INPUT ''"Enter Decimal Number - "dec% 670 oct$="" 680 REPEAT 690 oct$=STR$(dec% MOD 8) + oct$ 700 dec%=dec% DIV 8 710 UNTIL dec%=0 720 PRINT "Octal is "oct$ 730 RETURN 740 750 CLS 760 PRINT '''"5. Binary to Decimal" 770 INPUT ''"Enter Binary Number - "bin$ 780 dec%=0 790 index=0 800 REPEAT 810 d=VAL(RIGHT$(bin$,1)) 820 dec%=dec%+d*2^index 830 bin$=LEFT$(bin$,LEN(bin$)-1) 840 index=index+1 850 UNTIL LEN(bin$)=0 860 PRINT "Decimal is "dec% 870 RETURN 880 890 CLS 900 PRINT '''"6. Decimal to Binary" 910 INPUT ''"Enter Decimal Number - "dec% 920 bin$="" 930 REPEAT 940 bin$=STR$(dec% MOD 2)+bin$ 950 dec%=dec% DIV 2 960 UNTIL dec%=0 970 PRINT "Binary is "bin$ 980 RETURN
P77 Colour Codes For Resistors
This program could prove to be of great use in an electronics laboratory. It allows the user to calculate the value of a resistor from its colour code or to determine the colour code from its value.
COMMANDS
Key in program and type RUN.
Follow instructions.
100 REM Program P77 - Colour Codes For Resistors 110 MODE6 120 PRINT TAB(0,7)"This program can be used to calculate" 130 PRINT "the value of a resistor from its colour" 140 PRINT "code or to calculate the code from its" 150 PRINT "value." 160 Z=INKEY(600) 170 DIM code$(9),colour$(3),val(3) 180 FOR I=0 TO 9 190 READ code$(I) 200 NEXT I 210 REPEAT 220 CLS 230 PRINT ''"Do you wish to find value or code?" 240 PRINT "Enter 1 for value, 2 for code" 250 INPUT choice 260 IF choice=1 THEN PROCvalue ELSE IF choice=2 THEN PROCc ode 270 INPUT "Another run (Y/N) "a$ 280 UNTIL a$<>"y" AND a$<>"Y" 290 END 300 DATA BLACK,BROWN,RED,ORANGE,YELLOW,GREEN,BLUE,PURPLE,G REY,WHITE,EOD 310 320 DEF PROCvalue 330 CLS 340 @%=1 350 PRINT "COLOURS ARE :"'"BLACK"'"BROWN"'"RED"'"ORANGE"'" YELLOW"'"GREEN"'"BLUE"'"PURPLE"'"GREY"'"WHITE" 360 INPUT '"Colour 1", colour$(1) 370 INPUT "Colour 2", colour$(2) 380 INPUT "Colour 3", colour$(3) 390 FOR I=1 TO 3 400 FOR C=0 TO 9 410 IF code$(C)=colour$(I) THEN val(I)=C:C=9 420 NEXT C 430 NEXT I 440 PRINT "FOURTH BAND COLOURS ARE GOLD, SILVER OR" 450 PRINT "NONE" 460 INPUT "Tolerance band colour "tol$ 470 IF tol$="GOLD" THEN tol$="5%" ELSE IF tol$="SILVER" TH EN tol$="10%" ELSE tol$="20%" 480 PRINT ''"Value of resistor is "val(1);val(2)"*10^"val( 3)" OHMS" 490 PRINT "Tolerance = "tol$ 500 ENDPROC 510 520 DEF PROCcode 530 CLS 540 INPUT "What is resistor value",value$ 550 value=EVAL(value$) 560 l=LEN(STR$(INT(value))) 570 value=INT(value/(10^(l-2))+.5) 580 c1=value DIV 10 590 c2=value MOD 10 600 INPUT '"What tolerance do you require? (5,10 or 20%) " tol$ 610 IF RIGHT$(tol$,1)<>"%" THEN tol$=tol$+"%" 620 IF tol$="5%" THEN tol$="GOLD" ELSE IF tol$="10%" THEN tol$="SILVER" ELSE tol$=" " 630 PRINT''"Colour code is" 640 PRINT code$(c1);" ";code$(c2);" ";code$(l-2);" ";tol$ 650 ENDPROC
P78 Volumes of Solids
This program can be used to calculate the volumes of the following solids.
1. Sphere. | ||
2. Cylinder. | ||
3. Pyramid and Cone. | ||
Key in program and type RUN.
Follow menus.
100 REM Program P78 - Volumes of Solids 110 REM This part of the program presents the main menu 120 REPEAT 130 CLS 140 PRINT'''"THIS PROGRAM CAN CALCULATE THE VOLUMES" 150 PRINT "OF THE FOLLOWING SOLIDS"'' 160 PRINT''"1. SPHERE" 170 PRINT''"2. CYLINDER" 180 PRINT''"3. PYRAMID" 190 PRINT''"Enter the appropriate key value" 200 PRINT "for a particular choice, key 4 to" 210 PRINT "finish with program" 220 response=VAL(GET$):flag=0 230 ON response GOSUB 270,370,470:ELSE flag=1 240 UNTIL flag=1 250 CLS 260 END 270 REM This subroutine calculates the volume of a sphere 280 CLS 290 PRINT''"Calculating the volume of a sphere" 300 INPUT''"Enter the radius",r 310 volume=4*PI*r*r*r/3 320 PRINT''"Volume of sphere radius ";r;'"is ";volume 330 PRINT''"Press any key to return to main menu"'' 340 A$=GET$ 350 RETURN:REM end of subroutine 360 370 REM This subroutine calculates the volume of a cylinde r 380 CLS 390 PRINT''"Calculating the volume of a cylinder" 400 INPUT''"Enter the base radius",r 410 INPUT "Enter the height",ht 420 volume=PI*r*r*ht 430 PRINT''"Volume of a cylinder"'"radius ";r'"and height ";ht,'"is"''volume 440 PRINT''"Press any key to return to main menu"'' 450 A$=GET$ 460 RETURN:REM end of subroutine 470 REM This subroutine calculates the volume of a pyramid 480 CLS 490 PRINT''"CALCULATION OF AREA OF CONE" 500 PRINT''"Do you know the base area(Y/N)" 510 a$=GET$ 520 IF a$="Y" OR a$="y" THEN INPUT "Enter the base area",a rea ELSE PROCarea 530 INPUT'"Enter the height of the pyramid or cone",ht 540 volume=area*ht/3 550 PRINT'"Volume of pyramid with"'"base area=";area,'"and height=";ht,'"is"';volume 560 PRINT '"Press any key to return to the main menu" 570 A$=GET$ 580 RETURN:REM end of subroutine 590 600 REM The following procedure calculates the base area o f a pyramid or cone 610 DEF PROCarea 620 REPEAT 630 REM subsidiary menu to select base 640 CLS 650 PRINT''"Select base shape by pressing" 660 PRINT "appropriate key" 670 PRINT'"1. Equilateral triangle" 680 PRINT'"2. Square" 690 PRINT'"3. Circle" 700 response=VAL(GET$) 710 flag_1=0 720 IF response=1 THEN INPUT'"Enter side",s:area=s*s*SIN(R AD(60))/2:flag_1=1 730 IF response=2 THEN INPUT'"Enter side",s:area=s*s:flag_ 1=1 740 IF response=3 THEN INPUT'"Enter radius",r:area=PI*r*r: flag_1=1 750 UNTIL flag_1=1 760 ENDPROC 770 780 REM End of program
P79 and P80 Physics
These two programs show how a micro could be used within a physics lab to take some of the drudgery out of experimentation.
The programs are based on two experiments in F. Tyler's "A Laboratory Manual Of Physics" (Edward Arnold, 1966).
COMMAND
Use WORK SHEETS and programs to perform the experiments.
Work Sheet 1
The weight m is allowed to fall through a measured distance (s) to the ground, and the time of descent (t) is taken by a stop-watch. The number of revolutions (n) of the wheel during this time is taken by observing a mark made on the circumference of the wheel at P. The further revolutions (n) made by the wheel before coming to rest after m is detached are also counted by reference to the mark P. The experiment is repeated three times for the same distance (s).
Perform the experiment as follows:
Power on the microcomputer. |
Load program P79. |
Take measurements m, r and s. |
Run the program. |
Perform the experiment as directed, and enter values as prompted. |
100 REM Program P79 - Moment of Inertia 110 MODE 6 120 PRINT TAB(8,12) "Physics - Experiment 1" 130 PRINT TAB(4,14) "Moment of Intertia of a Flywheel" 140 Z=INKEY(300) 150 CLS 160 PRINT ''"SEE WORK SHEET!!!!" 170 PRINT ''"Input the following values" 180 INPUT '"Radius of axle (cm) "r 190 INPUT "Mass (g) "m 200 INPUT "Distance to the ground (cm) "s 210 g=981 220 PRINT ''"Perform experiment now"'' 230 FOR I=1 TO 3 240 PRINT TAB(0,13)"RUN - "STR$(I) 250 INPUT TAB(0,15)"t(secs)= "t 260 INPUT "n(rev) = "n 270 INPUT "N(rev) = "N 280 tt=tt+t:nn=nn+n:NN=NN+N 290 PRINT TAB(0,15)STRING$(39," "); 300 PRINT TAB(0,16)STRING$(39," "); 310 PRINT TAB(0,17)STRING$(39," "); 320 NEXT I 330 t=tt/3 340 n=nn/3 350 N=NN/3 360 I=m*r*r*(g*t*t/2/s - 1)*(N/(N + n)) 370 PRINT ''"Moment of inertia I =";I 380 END
Work Sheet 2
The object pin O is placed a given distance u from the concave mirror, and the position of the image I formed by reflection in the mirror is located by the method of non-parallax using the second pin (locating pin LP). The distance v of the locating pin from the mirror is measured. O and I are said to be conjugate points, and a series of values of v for a given range of values of u is obtained.
The computer program is used to calculate the focal length of the mirror from each measurement. The average of these values, and their standard deviation are calculated and presented on the screen.
100 REM Program P79 - Focal Length 110 MODE 6 120 PRINT TAB(8,12) "Physics - Experiment 2" 130 PRINT TAB(4,14) "Determination of the focal length" 140 PRINT TAB(4,15) "of a concave mirror" 150 Z=INKEY(300) 160 CLS 170 PRINT ''"SEE WORK SHEET!!!!" 180 INPUT "How many measurements were taken "n 190 DIM f(n) 200 FOR I=1 TO n 210 PRINT "Measurement "STR$(I) 220 INPUT "u ="u 230 INPUT "v ="v 240 f(I)=1/(1/u+1/v) 250 sum=sum+f(I) 260 sum_sq=sum_sq + f(I)*f(I) 270 CLS 280 NEXT I 290 300 mean=sum/n 310 sdev=SQR(sum_sq/n - mean*mean) 320 PRINT "Average focal length= ";mean 330 PRINT "Standard Deviation =";sdev 340 END
P81 Resistors
This program computes the resultant resistance of an electric circuit of the following type:
COMMANDS
Key in program and type RUN.
Follow instructions and enter resistances when required.
100 REM Program P81 - Resistors 110 MODE 6 120 PRINT TAB(12,12)"R E S I S T O R S" 130 Z=INKEY(300) 140 CLS 150 PRINT '''"This program computes the resistance" 160 PRINT "in an electric circuit consisting" 170 PRINT "of branches of series resistors" 180 PRINT "connected n parallel" 190 INPUT ''"How many branches are there ",branches 200 DIM res(branches) 210 @%=3 220 FOR I=1 TO branches 230 PRINT '"How many resistors in branch "I; 240 INPUT resist 250 FOR J=1 TO resist 260 PRINT "What is the value of resistor "J; 270 INPUT r 280 res(I)=res(I)+r 290 NEXT J 300 conductance=conductance+1/res(I) 310 NEXT I 320 @%=10 330 PRINT '''"TOTAL RESISTANCE ="1/conductance 340 END
P82 Calculator
There are many occasions when you need the capability of a simple calculator rather than a complex computer. This program simulates a simple four function (+,-,/,*) calculator.
When running the program notice that the appearance of the numbers is not quite the same as in the usual calculator. For example, if we add 111 to 123, the following happens:
User keys in | Screen Displays | |
1 | 1 | |
2 | 12 | |
3 | 123 | |
+ | 123 | |
1 | 124 | |
1 | 134 | |
1 | 234 |
Key in program and type RUN.
Use numeric keys and (+,-,/,*) to perform arithmetic. Use the full stop for the decimal point.
100 REM Program P82 - Calculator
110 MODE 2 140 result$="." 150 PROCprint(result$) 160 a$="0" 170 180 REPEAT 190 i$=GET$ 200 PRINT TAB(0,12);STRING$(20," ") 210 IF i$="*" OR i$="/" OR i$="+" OR i$="-" THEN result$ =STR$(EVAL(a$)):a$=result$+i$ 220 IF (ASC(i$)>47 AND ASC(i$)<58) THEN a$=a$+i$:result$ =STR$(EVAL(a$)) 230 IFi$="." THEN a$=a$+i$ 240 PROCprint(result$) 250 UNTIL 0 260 270 DEF PROCprint(result$) 280 R$=STRING$(13-LEN(result$)," ")+result$ 290 PRINT TAB(0,12);R$ 310 ENDPROC
P83 Coordinate Conversion
It can quite often happen that you have some points plotted on a graph in the rectangular (x,y) format, and you wish to convert this to the polar format (r,T), as in the following figure:
with slight variations for the various quadrants.
COMMANDS
Key in program and type RUN.
Follow instructions as presented on the screen.
100 REM Program P63 - Coordinate Conversion 105 MODE 6 110 REPEAT 120 CLS 130 PRINT "This program allows the user to convert" 140 PRINT "from rectangular to polar coordinates" 150 PRINT "and vice versa." 160 170 REM We initialize all variables at this point, which is the main module of the program 180 x_coord=0:y_coord=0:r=0:theta=0 190 PRINT ''"Choose which conversion you want and" 200 PRINT "press the appropriate key" 210 PRINT'"1 for polar to rectangular" 220 PRINT'"2 for rectangular to polar" 230 PRINT'"any other to end." 240 keyin=VAL(GET$):flag=1 250 ON keyin GOSUB 290,460:ELSE flag=0 260 UNTIL flag=0 270 END 280 290 REM This subroutine converts polar to rectangular coor dinates 300 CLS 310 PRINT''"Enter the coordinates of your point in" 320 PRINT "the form r,theta" 330 INPUT r,theta 340 INPUT''"Is theta degrees (Y/N)",answer$ 350 IF LEFT$(answer$,1)="Y" OR LEFT$(answer$,1)="y" THEN t heta=RAD(theta) 360 370 REM Notice the use of the RAD function 380 x_coord=r*COS(theta):y_coord=r*SIN(theta) 390 PRINT''"radial value=";r,"angle=";(DEG(theta)) 400 PRINT''"x_coordinate=";x_coord,'"y_coordinate=";y_coor d 410 PRINT''"Press any key to return to the main" 420 PRINT "module of the program" 430 A$=GET$:REM This line delays return 440 RETURN:REM end of subroutine 450 460 REM This subroutine converts rectangular to polar coor dinates, with the option of the angle in degs or rads. 470 CLS 480 INPUT''"Enter the x_coordinate of your point"',x_coord 490 INPUT''"Enter the y_coordinate of your point"',y_coord 500 r=SQR(x_coord*x_coord+y_coord*y_coord) 510 IF x_coord=0 THEN theta=RAD(90)*(y_coord>0)-RAD(270)*( y_coord<0) 520 IF x_coord<>0 THEN theta=ATN(y_coord/x_coord)+RAD(180) *(x_coord<0)*(y_coord<0)+RAD(180)*(x_coord<0)*(y_coord>0)+RA D(360)*(x_coord>0)*(y_coord<0) 530 INPUT''"Do you wish theta to be given in degrees(Y/N)" ,answer$ 540 IF LEFT$(answer$,1)="Y" OR LEFT$(answer$,1)="y" THEN t heta=DEG(theta) 550 PRINT''"x_coordinate=";x_coord 560 PRINT"y_coordinate=";y_coord 570 PRINT''"radial value=";r,'"angle=";theta 580 PRINT''"Press any key to return to the main" 590 PRINT "modle of the program" 600 A$=GET$:REM This line delays return 610 RETURN:REM end of subroutine 620 REM The end of the program