CSEP567 Lab 1: "Breadboard Basics"
Objectives
Assemble/wire up the breadboard that you will be using from the majority
of the quarter. Then test your breadboard with some AVR Assembly
code.
Reading
-
AVR CPU Core & Memory (ATmega16 datasheet, pp 6-16, 21)
-
General I/O Ports (ATmega16 datasheet, pp 48-52)
Helpful Hints
-
Instruction set summary is on page 331 of the ATmega16 datasheet that is
located in your course pack
-
Detailed instruction descriptions available
at Atmel's website.
Please don't print out (149 pages) as the rest of your programming will be in
C.
-
General purpose registers are r0-r31, watch for instructions that only operate
on some of them (ldi, load immediate, only works on r16-31)
-
Include [.include "m16def.inc"] to get logical names [PORTA] for registers (as
opposed to having to use addresses [$3B])
Resources
Part 1: Wiring up the breadboard
-
The resistors values have been purposefully left off the schematic. You should
consult the datasheet to find the chip's electrical characteristics to
determine the appropriate values of the reset pull-up resistor and the current
limiting resistors for the LEDs. You will need to calculate the value of the
current limiting resistor (Question 1). For decent brightness the
7-segment LEDs should have around 5mA of current. The pull-up resistor is
meant to mimize the current used to keep the pin pulled high. 10 K to 20 Kohm
values are typical pull-up resisitor values; however, values can range into the
mega-ohms.
Question 1: Calculate the theoretical amount of current flowing through a single
segment of the 7-segment LEDs when it is illuminated. In your calculation
use only values from datasheets or labels. Do not use any measured values in
your calculation. (You may measure the current to verify your calculations)
-
Wire the circuit in the schematic on your
breadboard. Make sure the power is disconnected when wiring up your breadboard.
The 7-segment LEDs displays are not connected to the ATmega16 in the schematic.
You and your partner will need to decide how to connect the 8 wires from the
ATmega16 to the 7-segment LED displays. The wiring pattern used should be
exactly the same for both of the 7-segment displays allowing the same constant
to be used when displaying numbers. Also note that the 7-segment LED displays
combine to make the number (one will represent the tens digit and the other
will represent the ones digit). To make the actual value of the counter easy to
read place the 7-segment LEDs so that they are horizontally aligned and the
bottom of the 7-segment LEDs are parallel. The left most 7-segment should be
the tens-digit.
-
Before powering on the breadboard, verify with a multimeter that there are no
shorts between power and ground, and that power and ground are actually hooked
up to the chips' pins. Ask a TA if you need instruction on how to use a
multimeter
-
Power on your breadboard and connect the serial cable from your computer.
-
To verify your hardware is working properly program your wired up breadboard
with flash.hex. (This program should cause your
7-sement LEDs to flash "88")
-
The ATMega16 is programmed via an application called MegaLoad. When the
ATMega16 is reset, it attempts to communicate with MegaLoad over the serial
port to upload the specified hex file. NOTE: This communication can cause a
delay when resetting the ATmega16 as it will attempt to communicate with
MegaLoad before executing your program. (the delay is especially long when
MegaLoad is not running because of the timeout)
To upload a program to the ATmega16:
-
Open MegaLoad (c:\program files\microsyl) and select the hex file you want to
upload to the flash of the ATmega16.
-
Reset the ATmega16 (this will cause the communication to begin).
Part 2: Create a simple program in Assembly
-
Open AVRStudio 4 and follow these instructions to setup a new project:
-
Click on the "Create New Project" button that is on the window that appears
when it opens.
-
The Project Type is "AVR Assembler". Give the project a name and change the
location to a lab partner's network share. Then hit next.
-
Select "AVR Simulator" as the Debug Platform and "ATmega16" as the Device then
hit finished.
-
You should also verify that you output will be in .hex so go to the Project
menu and select AVR Assembler Setup. The Additional Output file format should
be set to "Intel intellec 8/MDS (Intel hex)".
-
Copy the following code to the assembly file. (The code should display an "8"
on one of the 7-segment LEDs)
.include
"m16def.inc"
.cseg
ldi r16, 0xff
out DDRB, r16
ldi r16, 0x00
out PORTB, r16
loop:
jmp loop
-
Build the hex file and upload it to the ATMega16 via MegaLoad.
-
Modify the code to determine the constants needed to generate the other 9
numbers on the 7-segment LED displays.
Deliverables
Demonstrate that your breadboard is working to a
TA by the end of lab. The 7-segment LED should be showing some numbers other
than 8.