首页 > > 详细

讲解 COMP9032 Lab 0 Getting Started with Microchip Studio调试R语言程序

COMP9032 Lab 0

Getting Started with Microchip Studio

Sept. 2025

1. Objective

•     Install Microchip Studio at home.

•     Learn how to use Microchip studio to debug and run AVR assembly programs.

2. Installing Microchip Studio

Download the Microchip Studio installer from the following link

https://www.microchip.com/en-us/tools-resources/develop/microchip-studio#Downloads.

The software is also available on the course website (follow the link References → Tools → Microchip Studio). There are different types of MCUs. As we will use AVR 8-bit MCU (Microcontroller Unit) in our course, make sure you select the AVR 8-bit MCU option during installation.

Unfortunately, Microchip Studio only supports Windows. If you want to install Microchip Studio on a non-Windows computer, you need to set up a Windows virtual machine. Obtain necessary software for setting up a Windows virtual machine from the following link:

https://taggi.cse.unsw.edu.au/FAQ/Windows/

There are also plenty of resources available online about installing Windows virtual machines.

3. Introduction to Microchip Studio

Below is a short tutorial on how to use Microchip Studio (previously called Atmel Studio).

3.1 Start Microchip Studio

To start Microchip Studio, double click the Microchip Studio icon, or click on Start → Programs → Microchip Studio 7.0.

3.2 Create a New Project

To create a new project, on the Start Page screen, click the “New Project …” link. The dialog box will appear.

Figure 1: New Project

Among the installed programs, select Assembler and enter a project name (e.g. “lab_0”), as shown in Figure 1. Next, select the project location. This is the location where Microchip Studio will store all files associated with the project. It is good practice to create a separate directory for each lab. After choosing the project software type, name, and location, press “OK” to continue. You will be asked to choose the device for your project. Choose “ATmega2560” from the Device list, as shown in Figure 2. Then press “OK” to continue.

Figure 2: Device Selection

Now the project window with a file called main.asm appears, as shown in Figure 3.

Figure 3: Project Window

Replace the sample code (that was automatically generated by the Studio) with your code given in Figure 4.

Figure 4: Your assembly code

In the assembly code, file m2560def.inc is included. It contains the definitions required by the assembler for the microcontroller. The next step is to build the code (i.e. assemble the assembly program into machine instructions) . This is done by selecting “ Build Solution” from the “Build” menu (or press F7). The Output window (see Figure 5) then displays the information from the assembler. From this window we can see that the assembly process was completed with no errors and the executable file is 12 bytes long.

Figure 5: Build Your Program

Now we can investigate the code execution in the debug mode by selecting “Start Debugging and Break” under the Debug menu. If you are prompted to select a connected tool, select Simulator and try again. Notice that a yellow arrow is pointing to the first instruction “ldi a, 10” in the assembly code window, as shown in Figure 6. This arrow indicates the next instruction to be executed.   Before simulation, we may want to set up the Register View so that we can see the value of each register during the program execution. Select DebugWindowsProcessor Status and drag the created window to the right-side window (see Figure 6).

Figure 6: Start Debugging

The value of each register is initially 0. These registers will be dynamically updated during the program execution. You can also assign and change values of these registers by clicking on the value of a register and entering a new value at any time during the simulation. You can also change the value display format (binary or hexadecimal or decimal) by right clicking on the value and selecting a format you want to use from the list, as shown in Figure 6.

3.3 Run Simulation

There are two commands to single step through the code: “Step Over” F10 and “Step Into” F11. The difference between these two commands is that F10 does not trace into subroutines. Since our example does not contain any subroutines, there is no difference between the two here. Now, single step down to the third line of the code by repeatedly pressing the F11 key (For some computers you may need to use Fn key to active the function key, e.g. Fn+F11). Notice how the color changes from black to red on the registers when their values are just updated (See Figure 7). This makes it easy to identify which register changes its value when an instruction is executed.

Figure 7: Single-Step Execution

You can also run the code with breakpoints. To add a breakpoint, move the cursor to the instruction you want to stop on, and right click mouse and select BreakpointInsert Breakpoint. Figure 8 shows a breakpoint (indicated by the red dot) is added on the mov instruction.

Figure 8: Setting Breakpoint

Now press the Continue (or F5) button. The simulation will continue and then stop at the → breakpoint, as shown in Figure 9. The breakpoint can be removed/disable by selecting Breakpoint Delete Breakpoint/Disable Breakpoint.

Figure 9: Execution with Breakpoint

To end the debugging session, press “Ctrl+Shift+F5” or selecting Debug → Stop Debugging from the menu.

3.4 Status Register

Each AVR microcontroller has a Status REGister (named as SREG) that keeps eight flags such as C, S and V.  The definitions of these flags can be found in Mega2560 Data Sheet (page 14), which is available on the course website (follow the link References Documents → Mega2560 Data Sheet. These flags are dynamically updated during the program execution and can also be observed in the Processor Status window.  When a flag bit is set, the corresponding bit block is highlighted in red. For example, after instruction add a, b” is finished, bit 0 (C) and bit 1 (Z), are set, as shown in Figure 9.

3.5 Entry File

There is only one assembly file (main.asm) in the project. You can add more files into your project by right-clicking on the project name and clicking Add on the drop-down menu, as shown in Figure 10. You can then add a new or an existing file.

Figure 10: Adding More Files to Project

By default, main.asm is the entry file and only the entry file will be built and simulated. To set an assembly file as the entry file, right click on the file and select the Set As EntryFile option, as shown in Figure 11.

Figure 11: Set Entry File

Note that the work of this lab will not be assessed. However, you are strongly recommended to complete it in Week 1 and be ready for the following lab exercises.




联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!