BASIC programming for the Radio Amateur

By

 A.G.E. Leighton (ZS6BNE)

 

Eddie Leighton (ZS6BNE)

 

 

To         : PROGRA@ZAF

Type       : B

Date/time  : 09-Oct 06:45

Bid        : 440054ZS6BNE

Title      : Basic Programming....

Hi all,  

From OM Joe ZS6ANW after a discussion on computer programming.

“If you have the time, please do go ahead and put out a series of bulletins with respect to basic programming. Very little is being contributed to packet scene by locals, I'm sure many of the ZAF packet guys will appreciate getting information on basic programming. I for one will appreciate such a series...”  

I am in no way an expert at programming , but I have been fiddling around with programming since the Sinclair ZX81 days in the early 1980's. That is where I taught myself the BASIC language (While on holiday at Amanzimtoti) 

I later played around with the Commodore VIC20 which I still have and went into a lot of detail in interfacing with the outside world via the user port.

PASCAL was always a dark area but I had do use it while doing a course through UNISA in the early 90's and now use Natural and Visual basic.

I still use PASCAL to play around with robotics and the printer port of a standard IBM compatible PC. 

I did a little 8088 Assembler in my second year and it is very handyknowledge in times of need. 

Because just about everyone will have QBASIC because it is supplied with DOS 6.22 , I will concentrate on that particular version of BASIC , not that that is my preference , I prefer the old Turbo Basic or later it was known as Power Basic. The chances that you may have these compilers is very scarce nowadays.

Now don't be alarmed ..... programming is fun and EASY! If you make a mistake just fix it ! You don't have to drive into town to buy a new component that has just been blown , this is one of the main reasons why I got into programming!!! 

Computers have outputs to tell you what it is saying and inputs to hear what you have to say. (Quite a gentleman if you treat him right!.)  

That I will handle on the next bulletin .... I must run off now.  

73's de Eddie ZS6BNE@ZS0LTG , Lichtenburg.

 

  

To         : PROGRA@ZAF

Type       : B

Date/time : 09-Oct 22:03

Bid        : 6B0055ZS6BNE

Title     : Basic programming (1)

Hi All,  

As promised , lesson (1)  

Computers have outputs to tell you what it is saying and inputs to HEAR what you have to say. (Quite a gentleman if you treat him right!)  

Okay , at the DOS prompt type CD\DOS and Enter .....

type   QBASIC and Enter .....

press Esc .................  

Now you are ready to go !!  

Type in the following code:  

CLS                           'Clears the screen

PRINT "This is lesson 1"

PRINT "----------------"

PRINT "What is your name ";  'Output ....

INPUT Your name$               'Input  ....

PRINT "Hi " + Yourname$ + " I am very pleased to meet you"

Okay now press Alt and R to run your program! You can save it too , press Alt and F then A (Or S) to Save as anything you want.....

This lesson teaches you quite a lot really , Output ... and Input.

Yourname$ (A STRING Variable ie: All characters , denoted by the $)

Try removing the ; from the 4th line to see the effects , this is an important thing in BASIC's output control....  

The ' is the beginning of a comment. 

OK , that is lesson 1 , play around and change what you want and how you want , remember you cannot cause any harm .... at this stage anyhow.  

The last line shows what is called concatenation or joining strings. 

73's de Eddie ZS6BNE@ZS0LTG , Lichtenburg Amateur Radio Club. 

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 11-Oct 21:19

Bid        : EA0057ZS6BNE

Title      : Basic Programming (2) 

Hi All, 

As promised , lesson (2)

It may be a good idea to show you now , how the computer can respond to two different inputs..... 

Type in the following code:  

CLS                           'Clears the screen

PRINT "This is lesson 2"

PRINT "----------------"

PRINT "What is your name ";  'Output ....

INPUT Yourname$               'Input  ....

PRINT "Hi " + Yourname$ + " I am very pleased to meet you"

PRINT "Are you Male or Female  [M | F]"

INPUT Gender$

Gender$ = UCASE$(Gender$)    'Convert to upper case in case of m or f

SELECT CASE Gender$

CASE "M"

  PRINT "We can calculate your petrol consumption"

CASE "F"

  PRINT "We can display your recipe"

CASE ELSE

  PRINT "Only F or M is allowed...."       'Input VALIDATION (Handy !!)

END SELECT

Okay now press Alt and R to run your program! You can save it too , press Alt and F then A (Or S) to Save as anything you want.....

This lesson teaches you quite a lot really , Output ... and Input.

Yourname$ (A STRING Variable ie: All characters , denoted by the $)

Try removing the $ from Gender$ in INPUT Gender$ to see the effects , this is an important thing in BASIC's TYPE Specification , String.

Press Cntrl Break (The pause button at the top of the keyboard) if you battle .....  

OK , that is lesson 2 , play around and change what you want and how you want , remember you cannot cause any harm .... at this stage anyhow.

73's de Eddie ZS6BNE@ZS0LTG , Lichtenburg Amateur Radio Club.

 

 

  

To         : PROGRA@ZAF

Type       : B

Date/time : 15-Oct 21:26

Bid        : 5E0060ZS6BNE

Title      : Basic programming (3)

Hi All,  

Here is lesson 3. Comments are of course most welcome , then I know I am not wasting my time or confusing you .....  

Okay , you know how to get into QBASIC by now ..  

Enter the following code ... (I must get my cutting and pasting going , I develop the lesson on a DOS 6.22 computer and use Winpack on another....) 

CLS 

PRINT "           My Main Menu"

PRINT "           ------------"

PRINT " 1. Calculate my petrol consumption"

PRINT " 2. Read my recipe"

PRINT

PRINT "Enter your choice: "; 

INPUT MyChoice%

SELECT CASE MyChoice%

CASE 1

  CLS

  INPUT "What was your total distance travelled in Km "; Mileage

  INPUT "What were the total liters of fuel used "; Liters

  PRINT

  PRINT "Your consumption was "; Mileage / Liters; " Km / liter"

CASE 2

  CLS

  PRINT "I can display your recipe if I could read files!!!"

CASE ELSE

  PRINT "Only 1 or 2 are allowed

END SELECT 

Note the % after the MyChoice variable. This denotes an INTEGER variable that cannot have a decimal point. Try putting a % after the variables Mileage and Liters to see the effect..  

Okay I Have a long drive tomorrow , I will be going up to the ZS0TFK BBS Site on my way back to put the PC back and do a little housekeeping with the blower!  

73's , and happy programming!!  

de Eddie ZS6BNE@ZS0LTG

  

 

To         : PROGRA@ZAF

Type       : B

Date/time : 17-Oct 22:06

Bid        : 210063ZS6BNE

Title      : Basic Programming (Summary 1)

Hi Guys,  

Maybe we are going a little slow for some but maybe a little fast for others. Sounds like a happy medium.

With this bulletin we will highlight the main objectives presented in the first 3 lessons. Firstly with these very basic commands we are able to actually program the computer to do something useful!  

The commands and structures covered so far are:  

CLS to clear the screen.

PRINT to show text on the screen. 

INPUT to accept input from the user (2 Variations) 

SELECT CASE structure to respond to either a numeric value or a character value.

Two variable types have been handled , namely STRING and INTEGER denoted by $ and % respectively after the variables name. Variables are just like X and Y in algebra , only we give it a more detailed and explanatory name.

Note the programming techniques using "Indentation" for example the SELECT CASE / END SELECT structure for easy reading. 

With these three lessons you are already in a position to write quite useful programs!  

We will concentrate on loops in the next few lessons. Practice what you have learnt so far and even write programs to do something for you with the knowledge you have gained.  

CU es 73's de Eddie ZS6BNE@ZS0LTG

  

 

To         : PROGRA@ZAF

Type       : B

Date/time : 21-Oct 13:17

Bid        : 710067ZS6BNE

Title      : Basic programming (4)

Hi all,  

My apologies for the delay with the latest lessons , ZS0TFK is going down occasionally and it forms the main gateway into the NW Province.  

It is so good to see that even with the very basic principles that have been shown in the first 3 lessons , that programs can already be written and are being written! Congratulations to OM Joe ZS6ANW for his first program that actually calculates series and parallel resistor circuits!  

The first loop. This concept is widely used amongst all programming languages.  

I introduce the DIM statement (Which has nothing to do with loops but brings us in line with the latest BASIC programming requirements)  

DIM i AS INTEGER                  'Same as i%  

CLS

PRINT "This routine shows the IBM Graphic Character set!!"  

FOR i = 128 to 255

  PRINT "I="; i; CHR$(i),

NEXT i  

The loop will count from 128 to 255 and then terminate. Note the , at the end of the PRINT Statement , this is another one of BASIC's Output controls. It does a wonderful job of tabulating our output!  

The function CHR$() is one of BASIC's built in functions for displaying IBM Graphic characters.  

There are however special characters , like Linefeeds CHR$(10) , Carriage returns CHR$(13) and Form feeds CHR$(12) ....... which can be used when printing to a printer!  

Okay play around with this loop , another form of loop will follow in the next lesson , which will typically be used to read a file! (Remember the recipe?)  

One thing I would like to mention , and that is the importance of "Indentation" which makes reading of source code a little easier , note the FOR / NEXT Structure and the SELECT CASE / END SELECT Structure.  

FOR .....

---> PRINT ..... (Indentation)

NEXT ..  

Enjoy this lesson.

73's de Eddie ZS6BNE@ZS0LTG

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 21-Oct 14:05

Bid        : 760068ZS6BNE

Title      : Basic programming (5)

Hi All,  

Loops .... continued ....  

Now this is a very interesting loop. Loops can be helpful but they can also be a pain if they are not controlled. You get endless loops even in the most sophisticated of programs (Commonly called soft waits). I had a loop this morning while upgrading the operating system on the Mainframe computer.  

Type in the following code ....  

DIM MyStop AS STRING  

WHILE MyStop <> "S"

  PRINT "I am Looping ........ Press S to STOP"

  MyStop = INKEY$

WEND  

The <> means Not Equal To .... INKEY$ Accepts any character without having to press Enter.  

Run the program .... Remember this simple program will only stop when you press a CAPITAL S!  

Okay now put a comment indicator ' in front of MyStop = INKEY$ and run the program again.  

Try and stop the program by pressing S. What did you say? Okay switch off your computer you were in an uncontrolled loop , don't worry I had to shut the mainframe down too ....  

Comments?  

73's de Eddie ZS6BNE@ZS0LTG

 

  

To         : PROGRA@ZAF

Type       : B

Date/time : 21-Oct 14:43

Bid        : 890069ZS6BNE

Title      : Basic programming (6)

Hi All,  

You can see this is Sunday , I have packed away the dishes , fed the dogs and the XYL is resting and I have time to make up for the backlog in sending you lessons .....  

This lesson may be a little advanced but we have all experienced a runaway bicycle once in our lives and we’re still here aren't we?  

Enter the following code:  

DIM MyData AS STRING  

CLS

PRINT "This program reads the AUTOEXEC.BAT File on C: Drive"  

OPEN "C:\Autoexec.bat" FOR INPUT AS #1    'Open file 1 for READING!  

  WHILE NOT EOF(1)                  'Loop until the End Of File 1

    LINE INPUT #1 , MyData          'Read a line of text from file 1

    PRINT MyData                    'Show what you read ....

  WEND                              'Loop till EOF(1)  

CLOSE (1)                           'Close file 1 (Good practice!!)

Remember the recipe? Now we CAN read a text file , ANY text file , by just providing the path and filename of the file in the OPEN Statement.  

Note the indentation?  OPEN / CLOSE , WHILE / WEND.  

Please do NOT substitute OPEN .... FOR INPUT  with OPEN  .... FOR OUTPUT at this stage , you WILL Damage the file!!!!!!

Take this advice and we will handle the OUTPUT and APPEND at a later stage okay?  

Well your mouth must be watering by now , have a cup of coffee and enjoy your latest knowledge.  

73's de Eddie ZS6BNE@ZS0LTG

  

To         : PROGRA@ZAF

Type       : B

Date/time : 23-Oct 06:37

Bid        : 530071ZS6BNE

Title      : Basic programming (7)

Hi All,  

In this lesson I want to introduce you to arrays. An array can have many dimensions but we will concentrate on a single dimensional array.  

An array is basically a table of variables of the SAME TYPE.  

Enter the following code.  

DIM MyIndex AS INTEGER

DIM MyArray(50) AS INTEGER      'Table has 51 entries 

FOR MyIndex = 0 to 50

  MyArray(MyIndex) = MyIndex

NEXT MyIndex  

CLS  

FOR MyIndex = 0 to 50

  PRINT "Index"; MyIndex; Value"; MyArray(MyIndex)

NEXT MyIndex  

The first FOR NEXT Loop is used to "Populate" the array or table with values and I typically use the values of MyIndex while the FOR NEXT loop is stepping through it's range from 0 to 50.  

The second FOR NEXT loop is just used to display the values stored in the table.

Understand this concept and as far as I am concerned you will understand computer programming in general.  

So far I have received only comments from OM Joe ZS6ANW. Is there anyone else out there that is also enjoying this newly found knowledge?  

Please if you have any questions , let me hear from you.  

73's de Eddie ZS6BNE@ZS0LTG , Lichtenburg Amateur Radio Club.

 

  

To         : PROGRA@ZAF

Type       : B

Date/time  : 25-Oct 17:25

Bid        : ED0074ZS6BNE

Title      : Basic Programming Summary (2)

Hi All,  

I have heard that some of the lessons that I have sent out have not been received by potential readers. Unfortunately I have no control over that I just ensure that they are distributed to ZS0TFK and ZS0LTG and they must go further via ZS0RBG in Rustenburg.  

OM Jannie ZR6BBX put a timer in at ZS0TFK so we get a reboot every day in case of hang-ups. That does seem to help a lot.  

There are a few things in BASIC that I have purposefully not mentioned for the sake of good programming habits. For example IF / END IF , GOTO and GOSUB etc. etc.  

IF statements allow your program to make decisions on various inputs or conditions. Goto should never be used although it has raised it's head in the latest Visual Basic for Windows where you can use it to do error processing. GOSUB / RETURN was previously used by "Unstructured" BASIC and I won't even mention it here! The CALL command to call a "Subroutine" is the preferred method.  

With QBASIC you can define "Subroutines" and "Functions" which is basically building small pieces of reusable code so you don't have to repeat yourself over and over.  

If you wish your program to continue from the beginning when it ends , simply put the whole program within a loop , but remember to build in some type of control to be able to escape from this loop when you really want to!

I hope the lessons are going well so far , we can very soon start "Walking" instead of "Crawling".  

Best 73's de Eddie ZS6BNE@ZS0LTG

 

  

To         : PROGRA@ZAF

Type       : B

Date/time : 25-Oct 17:59

Bid        : 660075ZS6BNE

Title      : Basic Programming (8)

Hi All,  

We already have a very good foundation after only seven lessons and two summaries.  

I want to introduce to you the Hexadecimal numbering system. You don't have to be a mathematician to understand this , I am certainly not one.  

We will take the most basic way of describing Hexadecimal values by using another built in function of BASIC and that is HEX$().  

Type in the following code:  

DIM i AS INTEGER  

FOR i = 0 TO 15

  PRINT i; HEX$(i)

NEXT i 

Run the program. This program displays the decimal values 0 to 15 and their corresponding Hexadecimal values. Let me draw up a table for you .....  

Dec    Hex      Binary(Or +5v / 0v)

 0      0       0000

 1      1       0001

 2      2       0010

 3      3       0011

 4      4       0100

 5      5       0101

 6      6       0110

 7      7       0111

 8      8       1000

 9      9       1001

10       A        1010

11       B        1011

12       C        1100

13       D        1101

14       E        1110

15       F        1111 

Note the binary numbers have a sequence........ 

Weight                   8  4  2  1

Most significant bit     x  x  x  x      Least significant bit  

Where there is a 1 add the defined weight. For example binary 1010 = 12 decimal (8+2). Understand this and the arrays mentioned in the previous lesson and we will later use it to program the printer port to switch on a relay or something similar!!  

In the meantime build up a transistor switching circuit to activate a relay by applying +5v to the base via a resistor .....(I'll leave that up to you)

Preferably make 4 of them , we will use it for the printer port program!

73's de Eddie ZS6BNE@ZS0LTG

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 26-Oct 07:04

Bid        : 1B0076ZS6BNE

Title      : Basic programming Response (1)

Hi All,  

In response to a few very valid questions which may also be asked by many others too , I am giving a reply to all.

“I'm trying to figure out why things work the way they do. For example the purpose of the DIM function used as integer or string when before we had $ as string and % as integer.”  

The older versions of BASIC used the $ to designate a STRING variable and a % to designate an INTEGER variable.  

“Does DIM stand for "Dimension" and is it only used in connection with Arrays? I notice for instance that some "DIM statements" are similar to 'Comments and do not affect the program when they are left out.” 

In the old days BASIC was not a very "Structured" language (Remember GWBASIC and IBM's BASICA) and you could write just about anything down and it would work. Later versions of BASIC introduced the DIM statement which is used to "Declare" a variable name. You could of course leave it out and the program will still work but that is a bad programming habit. What we are learning here can be applied to the latest versions of BASIC as well.  

For example in Visual Basic , if you specify "Option Explicit" in one of it's "Modules" you are forced to declare the variable names via a DIM statement otherwise the program will not run. This ensures that the variables you are using have in fact been made known to the compiler and limits typing errors too.  

“Fortunately the Qbasic program tells you if there is a "syntax" error, for example in your lesson 8 you left out the "=" in the second line FOR i 0 to 15. I suspected that there should be a "equal to" symbol when Qbasic indicated there was something wrong with that line, after changing the line the program ran.” 

That was a typing error. My wife is also going through the lessons and found a few other typing errors. She noticed them too. Was it done on purpose? I must admit , no but you must have learn't something in the previous lessons or you probably will not have known why there was a "Syntax error"!! 

You probably have all seen the Help menu in the QBASIC menu. If you press Alt and H you will expose all the syntax definitions for QBASIC. At this stage I think it is safe to browse through the help. The greatest problem with learning to program is to prevent bad habits. BASIC can easily allow you to write programs in a sloppy way.  

Later we will handle subroutines and functions with parameter (Variable) passing. Programs can be written by writing "Building blocks" and when it is all put together you will have a professional working and "Maintainable" program!  

I hope I have answered the questions in a suitable manner. Thanks to OM Joe ZS6ANW for his feedback.  

73's de Eddie ZS6BNE@ZS0LTG

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 28-Oct 10:13

Bid        : 490077ZS6BNE

Title      : Basic programming (9)

Hi All,  

Well it's Sunday again. I got up early and had breakfast , went to the saltmine to shut down the mainframe so the electrician could replace the UPS batteries , had a slow 9 Km jog around Lichtenburg , listened to the Pretoria bulletin on HF and now I'm ready to present lesson nine!  

We introduced the hexadecimal numbering system in lesson eight.  

Enter the following code:  

DIM MyKey AS STRING

DIM MyDec AS INTEGER           'Use this for good practice....  

WHILE (MyKey <> "S") AND (MyKey <> "s")

  CLS

  INPUT "Enter a decimal number: " ; MyDec

  PRINT "Your decimal number"; MyDec; " = "; HEX$(MyDec); "Hexadecimal"

  PRINT

  INPUT "Enter S to End , any other key to continue"; MyKey

WEND 

The loop allows us to continue with the program if you so wish or to enter "S" or "s" to end the program. I have introduced one of the "Logical operators" here (AND) and it works very much like digital logic gates. More about this later....  

We are going to find out what your printer port address is. Run the program. Enter the decimal addresses 956 and also 888. Let me know by packet radio what your results are...... There are very exciting things to come from now on!!  

Enjoy the programming. Are we walking? Please let me know if you do not understand what we have handled so far, otherwise congratulations!  

73's de Eddie ZS6BNE@ZS0LTG

email: edleighton@hotmail.com

or     eddieleighton@nwk.co.za          (Saltmine address)

  

To         : PROGRA@ZAF

Type       : B

Date/time : 29-Oct 06:43

Bid        : 190079ZS6BNE

Title      : Basic programming Note (1)

Hi all,

Okay on the 3BC and 378. When your computer starts up you should have a display of your BIOS settings depending on what BIOS System you have.  

Press pause when such a screen is shown , and you should see your printer port address is either 3BC or 378 for LPT1 and LPT2. You may only have one and a maximum of three printer ports.

My apologies for the lesson eight typing mistakes sent via packet radio. I must really have been in a hurry then and it shows you how computers are. They only understand what has been put into their "Minds" and nothing else Hi.....  

Lesson eight’s mistakes ....  

> DIM i AS INTEGER

>

> FOR i 0 TO 15        

>    PRINT i; HEX(i)  'HEX(i) was treated as an array of default size

> NEXT i              'hence subscript out of range ....

 

It should be .... 

DIM i AS INTEGER  

FOR i = 0 to 15             'Note the = ....

  PRINT i; HEX$(i)          'Note the $ ....

NEXT i  

For interests sake , if DIM Hex(50) AS INTEGER for example was entered at the beginning of lesson eight's program , the subscript out of range message would not have appeared.  

Enjoy the programming!  

73's de Eddie ZS6BNE@ZS0LTG

 

To         : PROGRA@ZAF

Type       : B

Date/time : 31-Oct 20:43

Bid        : BD0081ZS6BNE

Title      : Basic programming Info (1)

I use the following information to identify the inputs and the outputs on up to 3 different printer ports with my programs. The input and output ports are kept standard. They can be configured differently , but require additional programming. In order to test your programs , build your self an LED display. The output is +5v. Use the table below for pin outs. Use a DIP switch from an old PCB to apply switched +5v to the input lines biasing them to ground via a 1K resistor. 

Pin 25 on the DB25 connector is the common ground connection.

(P1). i128. Input  signal (I5). Pin 11 on DB25. Pump bypass IN-ACTIVE

(P1). i064. Input  signal (I4). Pin 10 on DB25. Signal I4

(P1). i032. Input  signal (I3). Pin 12 on DB25. Signal I3

(P1). i016. Input  signal (I2). Pin 13 on DB25. Signal I2

(P1). i008. Input  signal (I1). Pin 15 on DB25. Signal I1

(P1). o128. Output signal (O8). Pin  9 on DB25. Swimming pool Pump ON.

(P1). o064. Output signal (O7). Pin  8 on DB25.

(P1). o032. Output signal (O6). Pin  7 on DB25.

(P1). o016. Output signal (O5). Pin  6 on DB25. 

(P1). o008. Output signal (O4). Pin  5 on DB25.

(P1). o004. Output signal (O3). Pin  4 on DB25.

(P1). o002. Output signal (O2). Pin  3 on DB25.

(P1). o001. Output signal (O1). Pin  2 on DB25. Watchdog LED ON.

(P2). i128. Input  signal (I5). Pin 11 on DB25. Dip

(P2). i064. Input  signal (I4). Pin 10 on DB25. Dip

(P2). i032. Input  signal (I3). Pin 12 on DB25. Dip

(P2). i016. Input  signal (I2). Pin 13 on DB25. Dip

(P2). i008. Input  signal (I1). Pin 15 on DB25. Dip

(P2). o128. Output signal (O8). Pin  9 on DB25. LED

(P2). o064. Output signal (O7). Pin  8 on DB25. LED

(P2). o032. Output signal (O6). Pin  7 on DB25. LED

(P2). o016. Output signal (O5). Pin  6 on DB25. LED

(P2). o008. Output signal (O4). Pin  5 on DB25. LED

(P2). o004. Output signal (O3). Pin  4 on DB25. LED

(P2). o002. Output signal (O2). Pin  3 on DB25. LED

(P2). o001. Output signal (O1). Pin  2 on DB25. LED

(P3). i128. Input  signal (I5). Pin 11 on DB25. Dip

(P3). i064. Input  signal (I4). Pin 10 on DB25. Dip

(P3). i032. Input  signal (I3). Pin 12 on DB25. Dip

(P3). i016. Input  signal (I2). Pin 13 on DB25. Dip

(P3). i008. Input  signal (I1). Pin 15 on DB25. Dip

(P3). o128. Output signal (O8). Pin  9 on DB25. LED

(P3). o064. Output signal (O7). Pin  8 on DB25. LED

(P3). o032. Output signal (O6). Pin  7 on DB25. LED

(P3). o016. Output signal (O5). Pin  6 on DB25. LED

(P3). o008. Output signal (O4). Pin  5 on DB25. LED

(P3). o004. Output signal (O3). Pin  4 on DB25. LED

(P3). o002. Output signal (O2). Pin  3 on DB25. LED

(P3). o001. Output signal (O1). Pin  2 on DB25. LED

Programming information will follow.

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 02-Nov 14:34

Bid        : 160085ZS6BNE

Title      : Basic programming (10)

Hi All, 

We should have no more typing mistakes. I copy and paste a tested program now and it makes my life easier. After writing my latest message , A day in the life of a South African and answered my first reply , I've cooled down and here is lesson 10. I hope you have either made a plan with an LED display or a relay switch and connected it to your printer port.  

Run the following program: 

DIM MyKey AS STRING

DIM MyDec AS INTEGER

DIM MyPort AS INTEGER 

'MyPort = 888             'Initialize variable

MyPort = 956 

WHILE (MyKey <> "S") AND (MyKey <> "s")

  CLS

  INPUT "Enter a decimal number   [0 to 15] : "; MyDec

  OUT MyPort, MyDec

  PRINT "Printer port "; HEX$(MyPort); " is set to "; MyDec

  PRINT

  INPUT "Enter S to End , any other key to continue"; MyKey

WEND 

At one stage we initialize a variable to EITHER 888 OR 956 (The other one is commented out) 

A new command which is ONLY used in the earlier versions of BASIC. OUT PortNumber , PortValue. This is a form of PARAMETER or VARIABLE Passing! Your first taste of this important concept. We are calling a procedure OUT and passing values in the correct sequence and the procedure will do what it is designed to do! You don't have to know how it does it! You will later write your own procedures! 

Lets have some feedback now ......... 

73's de Eddie ZS6BNE@ZS0LTG

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 04-Nov 09:13

Bid        : 690088ZS6BNE

Title      : Basic programming Response (2)

Hi All ,  

Response received concerning lesson 10 ........

> If I understood correctly, Program 10 would enable me to control the

> logic states of the printer port pins.

Absolutely correct. Now that is exciting , you are actually controlling hardware with software!

>  pin 1 = 5v

>  pin 2 = 5v

>  pin 3 = 0v but if I enter decimal number 2 it goes high (i.e. 5V)

>  pin 4 = 0v but if I enter decimal 4 it goes high

>  pin 5 = 0v, on entering decimal 8 it goes high

Remember the table I sent you ? .......

(P1). o008. Output signal (O4). Pin  5 on DB25.  .... Decimal 8!

(P1). o004. Output signal (O3). Pin  4 on DB25.  .... Decimal 4!

(P1). o002. Output signal (O2). Pin  3 on DB25.  .... Decimal 2!

(P1). o001. Output signal (O1). Pin  2 on DB25.  .... Try Decimal 1

Note the decimal values. if you set the port to decimal 15 , all 4 lines would go high! ie: 1 + 2 + 4 + 8 = 15

Some printer manuals give you an explanation of each line , mine (LX400) has no detail .... I have some more info somewhere ....

>  I am not very clear on how to interpret the info you gave in your

>   note "Basic programming Info (1)".  

That is a file I created long ago when I was playing around with computer control using PASCAL , I used the file to display information on the screen as to the status of the ports while the "Controller" was running.  

I presently , Permanently , use this concept to control my swimming pool pump. My timer went US and so I built a 286 with IDE Controller and Video card / LPT Port into a box with a 5 volt (Only 5 volt) supply to provide power to the controller. When the time is right , a specific output on LPT1 goes high and I get the message saying "Swimming pool pump ON". I also use the port for INPUT too , I can bypass the software timer with a signal to the printer port via a "Bypass Switch". The software interprets this signal and controls the port outputs. Imagine building the hardware to accomplish all this? The 286 costs you nothing and the rest too and you get a lot of fun out of experimenting.  

Happy experimenting with programming!  

73's de Eddie ZS6BNE@ZS0LTG

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 05-Nov 18:01

Bid        : B20089ZS6BNE

Title      : Basic programming (11)

Hi all,  

Well it is Sunday afternoon again!! I've just come back from Pretoria. I took my son , Edwill ZU1AAI 's bicycle through to him so he can get to his MCSD classes during the day seeing his (My) car was stolen last Thursday. (I'm only starting to get mad now !)  

By playing around I conjured up the following program for you. This program reads input from the printer port. A new function INP() and IF THEN Statements are handled here. If / Then at last!!  

DIM MyKey AS STRING

DIM MyDec AS INTEGER

DIM MyPort AS INTEGER  

'MyPort = 888                     'Initialize variable

MyPort = 956  

WHILE (MyKey <> "S") AND (MyKey <> "s")

  CLS  

  MyDec = INP(MyPort + 1)         'Retrieve Input port 957 / 889  

  IF MyDec AND 8 THEN PRINT "Input 1 Active"

  IF MyDec AND 16 THEN PRINT "Input 2 Active"

  IF MyDec AND 32 THEN PRINT "Input 3 Active"

  IF MyDec AND 64 THEN PRINT "Input 4 Active"  

  'Input 5 inverted in the IBM Hardware!

  IF MyDec AND 128 THEN PRINT "Input 5 Inactive"  

  INPUT "Enter S to End , any other key to continue"; MyKey  

WEND  

Run the program using your newly built DIP Switch interface. Oh ... you haven't built it yet?  

Okay mine looks more or less like this .... ASCII Follows:    

    +--+--+--+--+-------------- 0 Volt (Gnd)

    |  |  |  |  |

    \  \  \  \  \

    |  |  |  |  |

    |  |  |  |  |     1K

    +---------------XXXX------- +5 Volt supply ....

       +------------XXXX-------

          +---------XXXX-------

             +------XXXX-------

                +---XXXX-------

    |  |  |  |  |

    1  2  3  4  5                Input lines to LPT Port   

Okay enjoy.  

Ever heard of the three types of monkey?  

1. Those that MAKE Things happen .....

2. Those that WATCH things happen ....

3. Those that WONDER what happened? ...

 

Choose YOUR lifestyle! .....  

73's de Eddie ZS6BNE@ZS0LTG

 

  

To         : PROGRA@ZAF

Type       : B

Date/time : 07-Nov 06:41

Bid        : A40091ZS6BNE

Title      : Basic programming response (3)

Thank you for lesson 11. I would like to ask you to "who'a" a bit here, I'm  still  scrounging   around  for  parts  to  build  the  dip switch interface,  but should have it ready in a day or two. As soon as I have it finished and played around with it using program 11, I will give you some feedback.

To make sure I understand correctly, the following question. With reference  to  your  ascii sketch of the dip switch interface and the table of Info 1:

 

    +--+--+--+--+-------------- 0 Volt (Gnd)

    |  |   |  |  |

    \  \   \  \  \

    |  |   |  |  |

    |  |   |  |  |    1K

    +---------------XXXX------- +5 Volt supply ....

       +------------XXXX-------

          +---------XXXX-------

             +------XXXX-------

                +---XXXX-------

    |  |   |  |  |

    1  2   3  4  5                Input lines to LPT Port

 

 

Am I correct in assuming that input lines 1 to 5, shown in the Diagram above, refer to pins 15, 13, 12, 10 and 11 respectively in the table of Info 1 (below)  

(P1). i128. Input  signal (I5). Pin 11 on DB25. Pump bypass IN-ACTIVE

(P1). i064. Input  signal (I4). Pin 10 on DB25. Signal I4

(P1). i032. Input  signal (I3). Pin 12 on DB25. Signal I3

(P1). i016. Input  signal (I2). Pin 13 on DB25. Signal I2

(P1). i008. Input  signal (I1). Pin 15 on DB25. Signal I1

 

73 de Joe ZS6ANW

 

Absolutely correct. I will standby and give you a chance to get the hardware going. Mine is built onto a "Simulation robot". I have two stepper motors who's coils I fire by software control on the printer port.  

I can get the object to go forward and backward and also turn clockwise or counterclockwise.  

The input line to the printer port used to be an infrared detection system but that didn't work too well , the detection system that is.  

The inputs can be used for an alarm system too or anything you can imagine.

 

 

To         : PROGRA@ZAF

Type       : P

Date/time : 08-Nov 11:07

Bid        : 340094ZS6BNE

Title      : Basic programming (12)

Hi all,  

The following program is similar to lesson 11 but more complete , and it handles most of the concepts we have dealt with so far. I tested it last night and it works quite well.  

DIM MyKey AS STRING

DIM MyDec AS INTEGER

DIM MyPort AS INTEGER

DIM MyArray(4) AS STRING         'For input message table

DIM i AS INTEGER                  'For delay counter 

'MyPort = 888                     'Initialize variable with port address

MyPort = 956

                                 'Initialize input message table

MyArray(0) = "Signal detected on pin 15 on LPT Port " + HEX$(MyPort)

MyArray(1) = "Signal detected on pin 13 on LPT Port " + HEX$(MyPort)

MyArray(2) = "Signal detected on pin 12 on LPT Port " + HEX$(MyPort)

MyArray(3) = "Signal detected on pin 10 on LPT Port " + HEX$(MyPort)

MyArray(4) = "Signal MISSING on pin 11 on LPT Port " + HEX$(MyPort)

CLS 

INPUT "Note: Press E to End input port scanning or Enter to continue", MyKey 

WHILE (MyKey <> "E") AND (MyKey <> "e")

   CLS 

   MyDec = INP(MyPort + 1)           'Retrieve Input port 957 / 889 

   IF MyDec AND 8 THEN PRINT MyArray(0)

   IF MyDec AND 16 THEN PRINT MyArray(1)

   IF MyDec AND 32 THEN PRINT MyArray(2)

   IF MyDec AND 64 THEN PRINT MyArray(3)

   IF MyDec AND 128 THEN PRINT MyArray(4) 

   FOR i = 1 TO 1000 STEP 1       'Delay the next scan (Optional)

   NEXT

   MyKey = INKEY$

Run the program using the input switch interface when it is built. You may even have an effect keeping your printer connected and removing the paper or by putting it offline.  

Good luck!  

73's de Eddie ZS6BNE@ZS0LTG  ...... (Going to lie down for a while ..... not feeling too good :(......)

 

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 09-Nov 07:53

Bid        : 300098ZS6BNE

Title      : Basic programming Response (4)

Hi all,  

Our latest response ............  

Running the program (lesson 11) and applying 5V, in turn, to inputs 1, 2,  3, 4, and 5 (pins 15, 13, 12, 10 and 11 respectively on the   DB25)

I got the following results:

Action                        Comments on running program

Input 1 (5V - high)) others (0V - low):  Input 1 active                                          Input 5 inactive 

Input 2 (5V - high) others (0V - low):   Input 2 active

                                         Input 5 inactive 

Input 3 (5V - high) others (0V - low):   Input 3 active                                          Input 5 inactive 

Input 4 (5V - high) others (0V - low):   Input 4 active

                                         Input 5 inactive 

Input 5 (5V - high) others (0V - low):   No comments

 

5V applied to all inputs:                Input 1 active

                                         Input 2 active 

                                         Input 3 active              

                                         Input 4 active

I SUPPOSE input 5 is also active! 

I  also built 5 transistor switches, switching 5 leds connected to  pins 3,  4,  5, 6 and 7 and ran program 10 to check the logic state at   each output upon entering decimals 002, 004, 008, 016 etc.  

Thanks, I am now ready for further lessons...  

Regards Joe ZS6ANW

Thanks to OM Joe for the results of his experiments. On a standard printer port we have 5 inputs and 8 outputs to play around with.  

"I SUPPOSE input 5 is also active!"  

This is what we must be aware of concerning input 5. When a logic 1 is applied to the input pin it won't be recognized as such by the program , because the signal is inverted within the IBM PC Hardware. See lesson 12. 

Actually the comment Signal MISSING on pin 11 on LPT Port should say logic 0 or something similar to be more accurate.  

Well I think you have enough knowledge now to do something with the printer port. Write a program to do whatever you wish with the inputs and outputs and lets see what comes out.  

We will handle "String manipulation" from now on starting from Lesson 14.

73's de Eddie ZS6BNE@ZS0LTG

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 09-Nov 10:42

Bid        : 4C0099ZS6BNE

Title      : Basic programming Lesson(13)

Hi all,  

Before we handle "String manipulation" I would like to finally show you something that will be able to switch an output line On or OFF regardless of the state of the other lines. !  

Run the following program. Here you can see "Indentation" like you have never seen before to make the program more "Readable".  

The IF / END IF Structure is introduced too , with an ELSE , check it out. The OR operator has also been introduced. There is also an audible warning built into the program to alert the user to a message , with the BEEP Command.  

DIM MyKey AS STRING

DIM MyDec AS INTEGER

DIM MyPort AS INTEGER

DIM PortVal AS INTEGER

DIM MyOption AS INTEGER  

MyPort = 888             'Initialize variable with port address

'MyPort = 956  

WHILE (MyKey <> "S") AND (MyKey <> "s")

   CLS

   PRINT "1. Switch output line on"

   PRINT "2. Switch output line off"

   PRINT

   INPUT "Enter your selection [1 2]: ", MyOption  

   SELECT CASE MyOption  

   CASE 1                    'Switch OP Line ON

      INPUT "Enter a decimal number  [1 2 4 8 16 32 64 128] : "; MyDec

      IF MyDec < 255 THEN

        PortVal = INP(MyPort)

        OUT MyPort, MyDec OR PortVal

      ELSE

        BEEP

        PRINT "You cannot enter a value greater than 255!"

      END IF 

   CASE 2                    'Switch OP Line OFF

      INPUT "Enter a decimal number  [1 2 4 8 16 32 64 128] : "; MyDec

      IF MyDec < 255 THEN

         PortVal = INP(MyPort)

         IF PortVal AND MyDec THEN

            OUT MyPort, PortVal - MyDec

         ELSE

            BEEP

            PRINT "Output line already inactive ..."

         END IF

      ELSE

         BEEP

         PRINT "You cannot enter a value greater than 255!"

      END IF

   CASE ELSE

       BEEP

      PRINT "Only options 1 or 2 are allowed ...."

   END SELECT 

   PRINT

   INPUT INPUT "Enter S to End , any other key to continue"; MyKey

WEND

 

73's de Eddie ZS6BNE@ZS0LTG , Lichtenburg Amateur Radio Club ......

 

 

To         : PROGRA@ZAF

Type       : B

Date/time : 09-Nov 11:18

Bid        : 560100ZS6BNE

Title      : Basic programming Lesson (14)

Hi there,  

As promised , a quick rundown on string manipulation. The functions LEN(), LEFT$(), RIGHT$() and MID$() are handled here.  

You must understand this fully in order to be able to write dynamic programs.  

DIM MyString AS STRING

DIM StrLength AS INTEGER

DIM CharCount AS INTEGER

DIM SpaceCount AS INTEGER  

MyString = "This is a demonstration for string manipulation"

SpaceCount = 0  

CLS

PRINT MyString

PRINT

PRINT "The length of the string is "; LEN(MyString); " Characters"

PRINT "The 10 Leftmost characters are: "; LEFT$(MyString, 10)

PRINT "The 12 Rightmost characters are: "; RIGHT$(MyString, 12)

PRINT "In the 11 th position is a 12 character word: "; MID$(MyString, 11, 12)

PRINT 

FOR CharCount = 1 TO LEN(MyString)

  IF MID$(MyString, CharCount, 1) = " " THEN

    PRINT "A space was found at position "; CharCount; " within the sentence"

    SpaceCount = SpaceCount + 1

  END IF

NEXT CharCount

PRINT

PRINT "A total of "; SpaceCount; " Spaces were detected."

BEEP

PRINT

PRINT "That's all folks!"  

I will stand by for further comments , I can feel a sweat breaking out again , I have some or other stomach flu ..... going to lie down..