You are on page 1of 5

EXPERIMENT NO.

1
THE OUTPUT INSTRUCTION
OBJECTIVES
Upon the completion of this lab, you should be able to:
Connect the PORTB of ATMEGA32 to LED board.
Use the OUTPUT instruction and be familiar to the environment of Flowcode
Software.
Configure the correct settings for the target ATMEGA32.
Design a simple program for ATMEGA32.
Simulate the program.
Compile and download the program to ATMEGA32.
Test the program loaded in the ATMEGA32.
EQUIPMENTS
Software:
Flowcode
PPP
BACKGROUND
The ATMEGA32 belongs to a class of 8 bit microcontrollers of RISC architecture.
It has ROM, RAM, EEPROM, Flash memory and two ports namely PORTA which has 5
pins (RA0RA4) and PORTB has 8 pins (RB0RB8). These ports are configurable as
input or output which means there are 13 input/output ports. They are used to interface
to different electronic devices such as LEDs, switches, motors, sensors, LCDs and
keypads.
The basic ATMEGA32 microcontroller circuit requires an oscillator and an
optional reset button. An oscillator is necessary for the ATMEGA32 to work properly
because it is the one that provides the clock pulse and determines how fast the
microcontroller will execute the program loaded to its memory. Resistor-Capacitor (RC),
Crystal and Resonator oscillators are types of oscillators that can be used for
ATMEGA32 micros. The crystal oscillator is the commonly used which ranges from
4MHz to 20MHz.
LEDs with current limiting resistors are connected to microcontroller in two ways.
One is to switch them on with logic zero, and the other using logic one. The value of
resistor is determined by the amount of current that can flow to the LED. The maximum
current flow through the LED is set by the manufacturer.
PROCEDURE
1. Set up the Hardware.

Place the ATMEGA32 to Multichip Programmer.


Plug-in and connect the AC adapter to Multipchip Programmer.
Connect the Programmer and PC using the USB cable.
Set the clock setting to crystal oscillator (XTAL).
Attach the LED board to PORTB of ATMEGA32 as shown in the ATMEGA32ture.

2. Set up the Software.

Open the Flowcode Software.

Page 1 of 5

Create a new flowchart by selecting FileNew. Select the ATMEGA32 microcontroller as


the target from the list.

Flowcode will then display the microcontroller in the Microcontroller view and create an
empty flowchart. If the microcontroller is not shown, click ViewChip

3. Configure clock and watchdog timer settings.

On menu bar, click ChipConfigure


Select XTAL as the oscillator and set Watchdog timer to OFF.

4. Connect LEDs to ATMEGA32 microcontroller virtually.


Move the cursor over the LED icon in the Components toolbar. It looks like this:
Click once on the icon. A set of LED's appears in the main window.

Click once on the

button. Then click once on the 'Components Connections...' option on

the menu. This opens the 'Specify Component Pin Connections' dialogue box, like the one
shown below. This shows which LED is connected to which port, and which bit of the port on
the ATMEGA32micro chip.

Page 2 of 5

Click on the

option in the menu that you see. Notice that the settings for 'ATMEGA32 Port' and
'ATMEGA32 Bit' change for all eight LED's.
Click on the 'Done' button to close the dialogue box.
You can change the color of the LED's by clicking on the
button on the LED display,

arrow by the ' Connect to Port' dialogue box, and select the PORTB

and choosing the 'Properties' option. The following dialogue box opens:

Click on the

arrow at the end of the 'LED Color' box, and select the color you want.

Then click the 'OK' button to close the dialogue box.

5. Place an Output icon in the flowchart.


You will now see your flowchart appears with a BEGIN and END icon. All flowcharts have
these icons. Move the cursor over the Output icon,
in the Icon toolbar, and click and drag
it over the work area. The normal cursor changes into a tiny copy of the icon. Move it in
between the BEGIN and END boxes. As you get close to the flowchart, an arrow appears
showing you where the Output box will end up.
Release the mouse button to drop the Output box in between the BEGIN and END boxes.
Move the cursor over the Output box, and click with the right mouse button. Choose
Properties from the menu that appears, by clicking once on it with the left mouse button.
You will now see a dialogue box like this:

Page 3 of 5

Move the cursor over the 0 in the Variable or value box and click once. This will highlight
the '0'. Now type a number 1 on the computer keyboard to change the value to a 1.
Move the cursor over the
arrow in the Port window. Click on Port B in the menu that
opens up. The dialogue box now looks like the one below.

Now click on the 'OK' button to close the box.

6. Simulate the program.


Click on the 'Run' icon, the blue arrow on the main toolbar.
The Run icon looks like this:
or press F5.
The result is that the first LED lights, and there is a message saying that the simulation is
completed.
When you pressed the 'play' button the program was over in a flash. This is one of the great
things about microcontrollers: they work really fast. In later programs you will learn to slow
microcontrollers down with delays or loops so that they go at the speed that humans can
cope with. But to debug your programs you will need a way of slowing the simulation down.
Fortunately Flowcode has a feature you can use to step through your program icon by icon. If
you select the Step into icon
on the menu toolbar then you will see that Flowcode will
step through your program icon by icon. This will slow your program down and you will be
able to see the effects on your virtual system of each icon. As you step through the program
you will see a red rectangle around each icon: this indicates which icon will be executed next
time you click on the 'Step into' icon as you can see here:

7. Compile and download your program to ATMEGA32micro.


To transfer your program to ATMEGA32micro, you need to save first the program by clicking
the menu FileSave or by pressing Ctrl+S in your keyboard. Once done, click
ChipCompile to Chip. A window appears and shows the compiling and downloading

Page 4 of 5

process. If the Multichip Programmer is properly connected, it should be successful. You will
see the actual output on the LED board.
8. Repeat Step 5 to 7
You can also use Hexadecimal number preceded by 0x. To input 45H, enter 0x45.
For Binary numbers, precede it with 0b followed by 8 bit binary number. For example 45H is
equivalent to 0b01000101 in Binary.
Modify the value of set in the Output icon
into the following:
a. 57
b. 36
c. 15
d. 150
e. 200
f. 0xCD
g. 0xAD
h. 0x1F
i. 0x35
j. 0xA1
Whats the actual output? Which LEDs are ON?
Which LEDs are OFF? Why?

Supplemental Activities
The program should be downloaded to the ATMEGA32 for verification and checking.

1.
2.
3.
4.
5.
6.

Use a single output icon that lights all of the LED's of Port B.
Alter the icon parameters so it puts only the odd LEDs of PortB 'on'
Now put only the even LEDs of PortB 'on'.
Now put the High nibble (bits 4 to 7) of Port B 'on'
Put only the LED on PB7 'on' by sending an 8-bit value to this port.
Write a program with at least 20 Outputs icons that writes a pattern of different
values to port B, one after the other, and review what the result is in simulation.
7. Draw up the full circuit diagram of the ATMEGA32 with 8 LEDs on port B, including
the clocking circuit, the reset circuit, VDD and VSS connected to the ATMEGA32 and
the correct current limiting resistors connected between LED and ATMEGA32.

Page 5 of 5

You might also like