As M Programming in at Mel Studio 7

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Contents

Introduction..............................................................................................................................1
Downloading and Installing Atmel Studio................................................................................2
Opening Atmel Studio.............................................................................................................2
Creating the first project..........................................................................................................2
Writing the first Assembly program.........................................................................................4
Building....................................................................................................................................5
Debugging...............................................................................................................................6

1
Introduction
This tutorial will teach you how to write, compile, and trace a simple program in Atmel Studio 7.

Downloading and Installing Atmel Studio


Download the newest version of Atmel Studio from the microchip website:

http://www.microchip.com/avr-support/atmel-studio-7

Run the downloaded program to install the Atmel Studio IDE.


Opening Atmel Studio
Go to the Start menu and open Atmel Studio in the Microchip Studio.

Creating the first project


1. Go to the File menu. Choose New and then Project.

2
2. In the opened dialog,
a. Choose Assembler.
b. Name the project as Add.
c. Choose the path where you like to save the project by clicking on the Browse
button.
d. Press OK.

3. In the Device Selection dialog


a. Select AtmegaAVR as the Device family.
b. Choose ATmega328 (or any other Chips you want to use)

3
c. Select OK.

The compiler automatically makes the Addition and adds an assembly file to it.

Writing the first Assembly program


Type the following program.

; Program to add two numbers in ATmega8


; Define constants
.equ num1 = 0x05 ; First number (5)
.equ num2 = 0x03 ; Second number (3)

; Start of the program


.org 0x00 ; Reset vector
rjmp main ; Jump to main program

4
main:
; Load the first number into the register
ldi r16, num1 ; Load immediate value 5 into register r16
ldi r17, num2 ; Load immediate value 3 into register r17

; Add the two numbers


add r16, r17 ; r16 = r16 + r17

; r16 now contains the result (8)


; You can add further code to use or display the result

; End of program (loop forever)


loop:
rjmp loop ; Infinite loop to prevent program from ending

; End of the assembly program

Building
Press F7 to assemble, or choose Build Solution from the Build menu. The results of assembling the
program are shown in the Output window.

5
Debugging
1. To start debugging, press Alt+F5 or choose Start Debugging and Break from the Debug
menu.
2. The following Dialog appears and asks you to select the debugging tool. Press Continue.

3. In the following window, choose Simulator as the debugger and then close it by pressing the
x next to the Addition.

Note: Simulator vs. debugger

6
Using the simulator, you can execute the instructions, and watch the registers and variables. If
you have a debugger, e.g. AVRISP mkII or Atmel-ICE, you can connect a trainer board to your
computer. In the case, the microcontroller of the board executes the same instructions, when you
trace the program. This facilitates you to check the hardware while monitoring the variables in the
IDE.

4. Press Alt+F5 again. Now a yellow cursor is on the first line of the main program and the IDE
is ready to debug the program.

5. To execute the instructions line by line press F10 or click on the Step over icon.
Step Into vs. Step Over
Both F10 (Step over) and F11 (Step into) execute one instruction and go to the next instruction. But
they work differently when the cursor is on a function call. If the cursor is on the function call, Step
into goes into the first instruction of the function, but Step Over executes the whole function and
goes to the next instruction.

Step Out
If the execution is in a function, you can execute the function to the end by pressing the Step Out.

Run to Cursor
You can put the cursor on an instruction and then press the Run to Cursor button. In the case, the
program runs until it reaches the instruction which the cursor is on it.

7
Processor Tab
The Processor tab shows the current values of the CPU registers including R0-R31, SP (Stack Pointer)
and PC (Program Counter). You can also change the values of registers by double clicking on their
values and typing a new value.

6. To monitor the peripherals, including the I/O ports, click on the Debug menu, choose
Windows and then I/O.

7. The I/O tab appears on the right hand side which shows the peripherals of the
microcontroller, including the I/O ports. Select PORTB. The values of the related registers
(PINB, DDRB, and PORTB) will be shown below.

8. To Monitor Processor Status,,

8
9. To Monitor Registers

10. To Monitor Memory

11. To Disassembly the complied program

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy