file:button flash
[[file:button_flash]] last edit on
Feb 28, 2006
10:24 AM
by Anonymous
Download: helloword.txt
Size: 880 bytes
Uploaded : 2006-02-28 10:24:00.0
get a chance to study it in more detail.
Refer to this pin diagram of the LogoChip as I go on:

The LogoChip has 17 different pins for output and input. They are aptly numbered according to their Port names, that is, A0 through A5 for Port A, B0 through B7 for Port B. Because some of the pins are already used up by the LogoChip hardware, Port C
only contains three useable pins - C2, C6 and C7.
If you noticed, the numbers for Port A and Port B start with 0. This is just a convention adopted by computers and other digital stuff. As an example, B0 to B7 would contain 8 different pins, and not 7.
You can use any of the 17 pins as inputs or outputs. But for now, let's not use PORT A yet. I'll explain later.
These pins are bi-directional. This means that it can be either an input or an output.
How does the LogoChip know if it's an input or an output? Good question! Read on!
For our use, we can connect the positive side to the output of the LogoChip and the negative side to the ground side.
Which side of an LED is positive or negative? There are three ways to find out the negative side:
Let's choose one of the pins on Port B to do this example... I'm going with Port B, pin 2 or simply B2.
Look closely at the pinout of the LogoChip and look for pin B2. Now do these steps:

Now go ahead and turn on the power switch on the LogoChip. We're going to start programming!
As mentioned earlier, the ports are bi-directional. So you must've guessed that we need to tell the LogoChip which direction to use, right? That is precisely what we have to do next.
Now let's set pin B2 as an output. Type the following command in the command center:
clearbit 2 portb-ddr
Let's look at the commands used.
The command is written in the form
what_to_do_with_the_bit which_bit which_direction_port
Here's an easy way of remembering which commands to use:
setbit (1) makes it an (I)nput
clearbit (0) makes it an (O)utput
Notice how the initials I and O resemble 1 and 0?
In place of portb-ddr, you could've also used portc-ddr or porta-ddr depending on where the output is to be connected.
We have set pin B2 as an output. Now we can tell the LogoChip what to do with it. Type this command in the command center:
setbit 2 portb
Voila! The LED lights up!
What we just did was we sent a high output or simply a '1' to the output. This is done in a similar manner to setting up a port.
As before, the command is written in the form:
what_to_do_with_the_bit which_bit which_port
All there is to the command is that it tells the LogoChip to send a '1' (setbit) to the specific pin (2) of the output port (portb).
You just made the LogoChip follow your orders. Be proud.
Okay, so you are happy with the LED lighting up and now you want it to go away. As you might have guessed, the command to do just this is simply:
clearbit 2 portb
It turns off! That was easy, wasn't it?
Try making the LED go on and off several times by typing the commands again.
You might have learned that by turning the LED on and off several times creates a blinking effect. Sure, we can type it over and over again, but let's make our LogoChip do that for us.
Before that, let me introduce two new commands:
loop [what_to_loop]: loop causes whatever is in the bracket to loop over and over again.
wait how_long: wait is a delay between instructions. You specify how long it has to wait in tenths of a second
So, the command to turn it on and off forever is:
loop [setbit 2 portb wait 5 clearbit 2 portb wait 5]
Which means, in English, turn LED on then wait half a second (5/10 of a second) then turn off and wait another half a second and then loop forever
Another variant of wait is mwait which delays in thousands of a second.
You'll see that the LED will keep on flashing until you turn the power off, or if you typ no-op, which breaks out of the loop.
no-op is really "no operation". Besides breaking out of loops, it is just a command to "waste time".
Okay, the part about the LED flashing forever might have startled you a bit. Say we just want to flash it a specific number of times.
The command to do this is repeat. Try typing this command:
repeat 10 [setbit 2 portb wait 5 clearbit 2 portb wait 5]
And it does just what it's supposed to do - repeat the instruction 10 times.
To make something happen at the output, you need to:
In the next lesson, you will learn to write longer programs and will soon see why typing all the commands in the command center is not the most effective way to write longer programs.
Size: 880 bytes
Uploaded : 2006-02-28 10:24:00.0
Lesson 1 - Output Ports
In this lesson, we will cover these topics:- Input and output ports of a LogoChip
- Setting a port to be an input/output
- Using LEDs
- Turn something on/off
- The wait command
- The loop and repeat command
Input and Output Ports
I have surfaced the topic of inputs and outputs in the introduction, and now we'll getget a chance to study it in more detail.
Refer to this pin diagram of the LogoChip as I go on:

The LogoChip has 17 different pins for output and input. They are aptly numbered according to their Port names, that is, A0 through A5 for Port A, B0 through B7 for Port B. Because some of the pins are already used up by the LogoChip hardware, Port C
only contains three useable pins - C2, C6 and C7.
If you noticed, the numbers for Port A and Port B start with 0. This is just a convention adopted by computers and other digital stuff. As an example, B0 to B7 would contain 8 different pins, and not 7.
You can use any of the 17 pins as inputs or outputs. But for now, let's not use PORT A yet. I'll explain later.
These pins are bi-directional. This means that it can be either an input or an output.
How does the LogoChip know if it's an input or an output? Good question! Read on!
Our First Example -Lighting up an LED
Setting up a port is a piece of cake. Before you begin,- have your LogoChip Logo program running and your LogoChip connected to the PC.
- Get these two additional parts:
- an LED (any color)
- a resistor (any value between 220 Ohms to 10KOhms would be ok).
Step 1. Connect the LED and the resistor
An LED is a device that has to be connected according to its polarity. This means that, its positive side must be conencted to the positive (or higher potential)output of the circuit, and its negative side to the lower potential.For our use, we can connect the positive side to the output of the LogoChip and the negative side to the ground side.
Which side of an LED is positive or negative? There are three ways to find out the negative side:
- the shorter of two leads is the negative side.
- for rounded LEDs, there is a small flat edge if you look at it from above. The flat edge is the negative side.
- all LEDs have a triangular "flag"-like pole in its body. The flag is the negative side.
Let's choose one of the pins on Port B to do this example... I'm going with Port B, pin 2 or simply B2.
Look closely at the pinout of the LogoChip and look for pin B2. Now do these steps:
- Connect the positive side of the LED to pin B2
- Place the negative end of the LED to an unused slot on your breadboard. You might need to use a jumper wire to extend the connection from the LogoChip.
- Connect one end of the resistor in line with the negative side of the LED.
- Place the other end of the resistor to Ground.

Now go ahead and turn on the power switch on the LogoChip. We're going to start programming!
As mentioned earlier, the ports are bi-directional. So you must've guessed that we need to tell the LogoChip which direction to use, right? That is precisely what we have to do next.
Step 2. Setting a port as an Output
Verify that you have proper connection by typing flash in the command center. If you can see the red/green flash, you're all set.Now let's set pin B2 as an output. Type the following command in the command center:
clearbit 2 portb-ddr
Let's look at the commands used.
- clearbit does just what its name implies, it clears a bit by letting it become 0. The opposite of this instruction is setbit, which sets a bit as 1.
- portb-ddr is the directional register for Port B. This is where you select which direction it should go.
The command is written in the form
what_to_do_with_the_bit which_bit which_direction_port
Here's an easy way of remembering which commands to use:
setbit (1) makes it an (I)nput
clearbit (0) makes it an (O)utput
Notice how the initials I and O resemble 1 and 0?
In place of portb-ddr, you could've also used portc-ddr or porta-ddr depending on where the output is to be connected.
Step 3. Lighting up the LED
We have set pin B2 as an output. Now we can tell the LogoChip what to do with it. Type this command in the command center:
setbit 2 portb
Voila! The LED lights up!
What we just did was we sent a high output or simply a '1' to the output. This is done in a similar manner to setting up a port.
As before, the command is written in the form:
what_to_do_with_the_bit which_bit which_port
All there is to the command is that it tells the LogoChip to send a '1' (setbit) to the specific pin (2) of the output port (portb).
You just made the LogoChip follow your orders. Be proud.
Step 4. Turning the LED off
Okay, so you are happy with the LED lighting up and now you want it to go away. As you might have guessed, the command to do just this is simply:
clearbit 2 portb
It turns off! That was easy, wasn't it?
Try making the LED go on and off several times by typing the commands again.
Step 5. Flashing the LED
You might have learned that by turning the LED on and off several times creates a blinking effect. Sure, we can type it over and over again, but let's make our LogoChip do that for us.
Before that, let me introduce two new commands:
loop [what_to_loop]: loop causes whatever is in the bracket to loop over and over again.
wait how_long: wait is a delay between instructions. You specify how long it has to wait in tenths of a second
So, the command to turn it on and off forever is:
loop [setbit 2 portb wait 5 clearbit 2 portb wait 5]
Which means, in English, turn LED on then wait half a second (5/10 of a second) then turn off and wait another half a second and then loop forever
Another variant of wait is mwait which delays in thousands of a second.
You'll see that the LED will keep on flashing until you turn the power off, or if you typ no-op, which breaks out of the loop.
no-op is really "no operation". Besides breaking out of loops, it is just a command to "waste time".
Step. 6 Flashing the LED
Okay, the part about the LED flashing forever might have startled you a bit. Say we just want to flash it a specific number of times.
The command to do this is repeat. Try typing this command:
repeat 10 [setbit 2 portb wait 5 clearbit 2 portb wait 5]
And it does just what it's supposed to do - repeat the instruction 10 times.
Summary
To wrap up this lesson, here are some key points:To make something happen at the output, you need to:
- Select an unused pin and identify its Port letter and number
- Change the direction of the port-ddr by clearing (0) it to make it an output. Setting it, will make it an input
- Set the bit to turn something on
- Clear the bit to turn something off
- use loop [what_to_loop] to make it loop forever
- use wait [how_long] to insert a delay
- use repeat how_many_times [what_to_repeat] to repeat a specific number of times
In the next lesson, you will learn to write longer programs and will soon see why typing all the commands in the command center is not the most effective way to write longer programs.