Lab 1 { Introduction to AVR Development Tools Solution



Complete the following objectives:

  • Connect your AVR microcontroller board to a TekBot (optional).

  • Create a new Atmel Studio project.

  • Download and compile the sample AVR assembly source code given on the lab webpage (BasicBumpBot.asm).

  • Understand how to connect and operate the USBASP AVR programmer.

  • Upload the previously-compiled sample program to the ash memory of the TekBots AVR microcontroller board (mega128), and observe it running.


For most labs, you will be required to complete a prelab assignment before at-tending the lab session itself. These prelabs will cover the important concepts and background knowledge necessary to accomplish each corresponding lab. Note that you are required to use prelab template shared in the lab website.

Prelab assignments are due at the beginning of your lab session each week. If you have not submitted your prelab by the beginning of the lab session, you will receive no credit for that prelab. For general information about assignment submission policies, please refer to the syllabus on the lab webpage.

For this rst lab, there is no prelab assignment.


Wiring Your TekBot

  1. Use of the TekBot is optional for the ECE 375 lab. If you choose to use your TekBot, use the following instructions to ensure it is properly wired to the mega128 board. Otherwise, skip ahead to the next subsection, entitled \Compiling an AVR Assembly Program”.

Table 1: mega128 Port Usage for TekBot Connection

  1. Table 1 shows which port pins of the mega128 board must be connected to the TekBot. Use this table in conjunction with the wiring diagrams given on the lab webpage to perform the wiring properly.

To make the wires needed to connect your mega128 board to your TekBot, you can use the ribbon cable that came with your original TekBot kit, solder male headers to the ends, and add a bit of heat shrink tubing onto each connection. If you are not familiar with this technique, there is a short tutorial on the TekBots webpage that explains this process in detail.

Since we are working with a modular programmable AVR microcontroller board, you could connect the whisker inputs and motor controller outputs to any pins on any port on the board. But, for this lab and future labs to work properly, these speci c wires need to be connected in a certain way. Please follow the convention speci ed in Table 1 and maintain this wiring throughout the course, so that your use of some alternate pin functions in later labs behaves as expected.

  1. When you have completed the wiring, be sure to double-check all connections before you turn the power on. If you have wired things incorrectly (especially if you have switched Vcc and ground), you can easily destroy parts of your TekBot. If you aren’t con dent in the correctness of your wiring, please ask a fellow student, your TA, or the TekBots store to double-check your work.

Compiling an AVR Assembly Program

  1. Download the sample code (BasicBumpBot.asm) available on the lab web-page. This is a simple AVR assembly program that is well-commented and ready to compile. All code that you produce for this course should be as well-commented as this code. Save this code somewhere you can nd it.

  1. Atmel Studio is the Integrated Development Environment (IDE) that you will be using to develop your AVR assembly code throughout this course

©2020 Oregon State University Page 1

Lab 1 { Introduction to AVR Development Tools

ECE 375

(with the exception of Lab 2, which uses C). Atmel Studio is a powerful IDE created by Atmel for their line of AVR microcontrollers. You will be using it to write assembly programs for your AVR microcontroller board (mega128), which uses an ATmega128 microcontroller. Section 2 of the AVR Starter Guide, which can be found on the lab website, contains a good overview on how to use the IDE, as well as some step-by-step tutorials. Brie y read through this section to gain a basic understanding of the Atmel Studio work ow.

Atmel Studio is already installed on the computers in the lab classroom. If you plan to use your personal Windows computer for some or all of your lab work, the latest version of Atmel Studio is available for download on Atmel’s website. It is also possible to use your personal Mac OS X or Linux computer for AVR assembly programming, but you will need to nd an alternative to Atmel Studio on your own. Also, a few of the labs in this class rely heavily on the use of Atmel Studio’s built-in AVR simulator, so please keep in mind that occasionally you may be relegated to completing your work on one of the lab computers instead of your personal device.

  1. Once you have nished browsing through Section 2 of the AVR Starter Guide, follow the speci c steps in Section 2.1.2 to create a new project. In most IDE tools, a project is the base starting area to your program. It consists of all les you use and any settings for the program. In this case, the le you’ll want to include is the AVR assembly sample program, which you downloaded from the lab website earlier. Continue following the instructions in Section 2.1.2 to associate the sample program with the project you just created.

  1. Now that you have loaded the sample program into your Atmel Studio project, take a moment to look over the sample code. Although you haven’t seen any AVR assembly code in this class yet, read the comments and see if you can follow the general structure and ow of the program. For reference, the general operation of the program is described in Figure 1.

  1. Using the project you created, continue on to Section 2.1.3, and perform steps 1 and 2 to compile the sample program (you can disregard the simula-tion instructions in this section, as this topic will be covered in a later lab). Note: When an AVR assembly program is compiled, the resulting output is a binary program le (called a HEX le, with a .hex extension). This HEX le contains the actual binary instructions that will be executed by the ATmega128 microcontroller.

  • Initializes key components of the ATmega128

  • Starts the TekBot moving forward

  • Polls the whiskers for input

  • If right whisker is hit

{ Backs up for a second { Turns left for a second { Continues Forward

  • If left whisker is hit

{ Backs up for a second { Turns right for a second { Continues Forward

Figure 1: Theory of Operation for Lab 1 AVR Assembly Code

You now know how to create a new AVR project in Atmel Studio, include an assembly program into that project, and then compile the program into usable program code. Next, you will learn how to upload the compiled program to the microcontroller and watch it run.

Uploading a Compiled AVR Program

  1. Use the Windows application Universal GUI.exe (already installed on the lab computers, and available for download on the lab webpage) to upload the compiled .hex le to the ash memory of the ATmega128 microcontroller. (For detailed instructions, follow the steps given in the Universal GUI User Guide linked on the lab webpage.)

  1. With the HEX le uploaded to the microcontroller, you can observe the behavior of the sample program (if using a TekBot, unplug it from the computer and turn it on). The LEDs on the mega128 board should indicate that the board is performing a basic BumpBot routine (remember, Figure 1 gives a description of the full routine). To receive your implementation points for this lab, demonstrate to your TA that your board is performing this correct BumpBot behavior.

©2020 Oregon State University Page 2

Lab 1 { Introduction to AVR Development Tools

ECE 375


For most labs, you will be required to submit a short write-up that details what you did and why, but there is no write-up required for this rst lab. Instead, you will only need to hand in the answers to the study questions given later in this document.

When putting together each lab’s write-up, you must use one of the tem-plates (.doc or .tex) provided on the lab webpage. Include enough detail so another student could recreate the lab by using your write-up as a guide. See the lab webpage and template for speci c details on what should be included in the lab write-up. You must submit your write-up and code via Canvas by the start of the following lab. NO LATE WORK IS ACCEPTED.

You are responsible for turning in a clean, organized, and professional doc-ument free of misspelled words. The code you turn in must include su cient comments, such that ANOTHER STUDENT could reasonably be able to under-stand your code. Code that is not well-documented will result in a severe loss of points for the write-up portion of your lab grade. For an example of the style and detail expected of your comments, look at the code you just downloaded. Generally you should have a comment for every line of code.

Study Questions

Most of the labs you do in this class will have study questions that are to be answered within your lab write-up. This lab’s study questions are given below, and will be due at the start of lab next week. Although you will be exposed to some information that has not been covered in class, keep in mind that as a student accepted into pro school you will need to get into the habit of being proactive. This involves some independent learning, such as reading ahead and preparing yourself before going to lab or class.

  1. Go to the lab webpage and download the template write-up. Read it thor-oughly and get familiar with the expected format. What speci c font is used for source code, and at what size? From here on, when you in-clude your source code in your lab write-up, you must adhere to the speci ed font type and size.

  1. Go to the lab webpage and read Syllabus carefully. Expected format and naming convention are very important for submission. If you do not fol-low naming conventions and formats, you will lose some points. What is the naming convention for source code (asm)? What is the nam-

ing convention for source code les if you are working with your partner?

  1. Take a look at the code you downloaded for today’s lab. Notice the lines that begin with .def and .equ followed by some type of expression. These are known as pre-compiler directives. De ne pre-compiler directive. What is the di erence between the .def and .equ directives? (HINT: see Section 5.1 of the AVR Starter Guide).

  1. Take another look at the code you downloaded for today’s lab. Read the comment that describes the macro de nitions. From that explanation, deter-mine the 8-bit binary value that each of the following expressions evaluates to. Note: the numbers below are decimal values.

    1. (1 << 3)

    1. (2 << 2)

    1. (8 >> 1)

    1. (1 << 0)

    1. (6 >> 1j1 << 6)

  1. Go to the lab webpage and read the AVR Instruction Set Manual. Based on this manual, describe the instructions listed below.



Challenge problems are additional tasks that can be performed for several of the labs. By successfully completing a particular lab’s challenge problem, you can get extra credit for that lab. To get credit for a challenge problem, you must successfully demonstrate it to your TA, as well as document it in your lab write-up. This lab’s challenge problem is given below:

  • You have learned to use a simple tool to download a sample program into your mega128 board. Modify the sample program so the TekBot will re-verse for twice as long before turning away and resuming forward motion. Demonstrate this to your TA, and include a copy of your modi ed assembly program when you submit your answers to the study questions.

©2020 Oregon State University Page 3

error: Content is protected !!