Basic programming converter




















You can see the beginning and the end of the DO LOOP more clearly. It's important to make your programs look nice so other people can read them. So far our programs have only talked to us. Let's write one that will listen. Try this:. To be variable means that things can change. Sure enough, the message changes. Variables hold letters and numbers.

These are called "string variables". Variables without a dollar sign can only hold numbers. We'll be seeing them soon. You can call your variables anything you want. What happens when you run it? Another way to think of a variable is to imagine a small bucket with a name on it. This is the bucket's variable's name.

Now take a piece of paper and write your name on it and drop it into the imaginary bucket. Computer variables can only hold one piece of paper one value at a time.

This program will show you how this works:. Let's make that last program a little smarter. I want to be able to identify intruders playing with my programs. Wouldn't it be great if the computer could recognize someone's name and print a special message for them?

How about this:. Run the program and type in your name hopefully it isn't Mike. You should see the same old message as before. Now run it again and try entering "Mike" or "Joe" or whatever you changed it to. If it didn't tell the right person to go away, make sure you typed the name correctly.

Make sure you enter the name exactly the way you put it in the program. The "IF.. THEN is called the "condition". With numbers you can also check for "greater than" and "less than":.

Another option is "not equal" which can be done like this: "Number ". Using IF THEN can make your programs very interesting. It lets your program make decisions and do something appropriate.

Computers are very good at math. Let's get the computer to do some math for us. Here's a simple multiplication calculator:. Run it, and enter two numbers. It does an excellent job multiplying for you. This is because they are only holding numbers, not letters. Because there's no division sign key on the keyboard.

At least I haven't found one. The first thing we need to think about is where we are going to save our programs. The two main places we can save things are the hard disk, and onto a floppy disk. Let's look at both places. Using a floppy is a good idea if you don't want other people looking at your programs. The floppy can be removed from the computer and kept in a safe place. Floppies are also good when you want to move programs from one computer to another.

Let's try it. Find a blank floppy and place it into the computer's floppy drive. The floppy can have stuff on it, as long as there is some free space left. You'll need to have a program up on the screen for this to work properly.

Go back to the previous chapter and type in the example if you need to get something up on the screen. The "Save" dialog will appear on the screen. Notice that the cursor is in a box field called "File Name:". Type this:. What happened? Did you hear something? Where'd the "Save" dialog go? Hmmmm, ok, hopefully that worked.

How can we check? Wait, it's already there. Ok, then let's clear it out and try to get it back from the floppy. Remember how to get rid of a program? Hint: "File" then "New" on the menu. Let's do it. Click on "File" then "Open Now you will see the "Open" dialog. BAS" in the box called "Files". Two clicks oughta do it.

BAS" and the program is back from the floppy. The hard disk is the most convenient place to save programs. Since it is always in the computer, your programs are always there for you to load when you need them. Hard Disks usually have a lot more information on them than a floppy. Because of this, you need to be concerned about keeping things neat.

You'll never be able to find what you need otherwise. The best way to organize your collection of programs is to put them into a "subdirectory" or "folder" on the hard disk. Let's make a folder on the hard disk for our programs. In Windows 95 we will need to use Windows Explorer.

In Windows 3. First, the Windows 95 way. Go ahead and type in a name for the new folder, but keep it short! I called mine "TedsPrgs" meaning Ted's Programs. Good, that's done. We won't need to do that again, unless you'd like to make another directory at a later date. Saving to the hard disk is only a little different from saving to a floppy. You'll need to have a program up on the screen to save.

The cursor is in a box field called "File Name:". Now you will see a list of programs in that directory. Since you haven't saved anything yet, there shouldn't be any programs there. Go ahead and type this:. Hmmm, no sound at all that time. Hard disks are much more quiet than floppies. So, let's make sure it worked properly. First, get rid of what's on the screen with a "File" then a "New".

This is also very similar to the way we loaded a program from floppy. This will bring up the "Open" dialog.

BAS" in the "Files" box. BAS" to load it. That wasn't too bad, was it? Once you figure out whether you want to save to floppy or hard disk, you only need to remember one way to save and load. ELSE is fine if you only have two things you want to check. What if you have 5 or 6 friends that might use your computer and you want the computer to say something different to each of them?

Whew, that was a big one. Fortunately we learned how to save in Chapter 8. Save it if you want before running it. Feel free to change "Ted" and "Mike" to "Laura" and "Robin" or whoever.

So far, we've only let the user fill in our variables. We can fill in variables on our own inside our programs too. Like this:. You get the picture. Then the program prints them out to prove to you that they are there. See if you can figure out what this rather clever program will do. Then type it in and run it to see if you were right. Did you get it right? Did the output go by way too fast? You'll have to press Break to stop it. Then take a closer look and see if you can see what's going on.

Random numbers are numbers that you can't predict. Flipping a coin or rolling dice will give you a random number. Random numbers are very important in games and in some kinds of Math. Computers can generate random numbers pretty well. RND is a special function that gives us a random number between 0 and 1.

We can use this in games to make things interesting. RND is perfect for rolling dice or flipping a coin. First let's see RND in action:. This program will print RND twice. Notice that you'll get two numbers that appear to be unpredictable and random. But, try running the program again.

You'll get the same "random" numbers. This means your games would always be the same each time the user runs them. Fortunately, there's a way to fix this. Random numbers between 0 and 1 aren't really very useful. What you will need for a game might be a random number between 1 and 6, like when you roll dice. To get something more useful, we'll use math.

Fortunately, computers are very good at math. There are two problems we must solve to get the results we want. First, the range of random numbers has to be expanded from 0 through 1 to 1 through 6. That's easily done like this:. By multiplying by 6, we increase the range to 0 through 5.

By adding 1 we shift the range up to 1 through 6. However, there's still a problem. All that decimal stuff. Here's a program that rolls two dice and prints the value of each. The variables Die1 and Die2 are used to hold the values of each die before printing. In a real game, Die1 and Die2 would be used in some clever way to change the outcome of the game.

Did you see what it did? It simply printed a blank line on the screen. Basically, both Input 1 and Input 2 can control the switching of the circuit. In the AND operation, the relays were placed in series. This means that the input must be different from each other, hence the term exclusive. XOR can be used as comparators. Comparators, as implied, compares two input signals and sends an output signal based on predetermined criteria or functions. In this case, the comparator outputs a HIGH signal when the inputs become different.

Hence, you can expect the truth table to be an inverted version of the AND truth table in terms of the output. In practical applications, the NAND operation may be used for temperature regulation in a freezer, for example. The resistance of the thermistor decreases when it gets colder, hence decreasing the voltage drop to a low enough level to be detected as two LOW signals by the NAND operation.

Usually, the inverted versions of logical operations are not used in practical circuits as you can easily change inputs into a Normally Closed one instead of a Normally Open one more on that later. But, it is still helpful to have a basic understanding of them. In studying these logical operations, Boolean algebra is used.

Boolean Algebra provides a way to simplify even the most complex series of logical operations imaginable. What this means for us is a shorter program that performs the same operation, and that is highly desirable.

There are different laws that consist Boolean Algebra, and most of them are similar to the mathematical laws that we have studied in elementary school. The three basic rules are:. The answer is equivalent to 1, not 2 because we still follow the Binary number system. Again, this law is just similar to the associative law in Mathematics. Either adding or multiplying three variables together in a grouped fashion does not affect the result.

Makes sense? Same goes for the AND. The distributive law is critical in simplifying logical equations in Boolean Algebra. Long equations that use 3 logic operations can be simplified into 2, as evident in the equations below. So, when you see an equation that resembles the one on the right, it is actually more practical to use the equivalent equation on the left because that ultimately results in the same output using a shorter program.

Now, if you wanted to take this logic gate representation back into a boolean equation, you would have to turn EVERY operation into a representation using just three operations:.

The IEC or the International Electrotechnical Commission is the international standards and conformity assessment body for all fields of electrotechnology, which essentially covers Programmable Logic Controllers.

PLC programming language refers to the set of semantics or methods that allow the user to communicate information to the PLC. Textural programming languages are those in the form of text and consists of commands that the user must all be familiar with in order to create a program. If you have a background in C programming, you will closely see its resemblance. The structured text language are written as a series of statements terminated by semicolons like in C. These statements are defined by the language libraries and makes it easier to set input-output relationships in the program.

The example above directly shows the relationship between the variables for the input and the output. For example, in the structured text above, all variables within the parentheses will be executed first. Instruction lists are also considered a way of entering ladder programs, except by using text. It gives a series of instructions for each new line and uses mnemonics for each one.

Since different manufacturers use different mnemonics, I will only give the IEC as an example. PLC programming languages that are visual are also high-level languages. Previous Page. Next Page. Useful Video Courses. Computer Organization Lectures More Detail. This is the default. It is a consequence of the fundamental decision to pass expressions as-they-are to the C compiler, which otherwise can cause name conflicts with existing C keywords and C functions from external libraries.

However, BaCon can accept lowercase also by using the '-z' command line option. Feel free to do so at your own risk. Your mileage may vary.

The generated C code is hard to read! That maybe so. For example, when using string variables, BaCon adds code which makes sure that sufficient memory is allocated. And if the string gets bigger, BaCon also includes code to enlarge that memory. Another example is that BaCon can break out loops to any preferred level. To achieve such functionality, loops like 'while' and 'repeat' contain extra code. Therefore, the generated C code may look confusing and complicated.

How about a Win32 Version? That will never be. However, BaCon works in a Cygwin environment.



0コメント

  • 1000 / 1000