As M Programming in at Mel Studio 7
As M Programming in at Mel Studio 7
As M Programming in at Mel Studio 7
Sepehr Naimi
www.NicerLand.com
12/1/2017
Contents
Introduction............................................................................................................................ 2
Downloading and Installing Atmel Studio ................................................................................... 3
Opening Atmel Studio .............................................................................................................. 3
Creating the first project .......................................................................................................... 4
Writing the first Assembly program ........................................................................................... 6
Building .................................................................................................................................. 6
Debugging .............................................................................................................................. 7
Using Breakpoints...................................................................................................................10
Introduction
This tutorial will teach you how to write, compile, and trace a simple program in Atmel Studio 7.
Page 2
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
Page 3
Creating the first project
1. Go to the File menu. Choose New and then Project.
1 2
Page 4
3. In the Device Selection dialog
a. Select megaAVR as the Device family.
b. Choose ATmega328 (or any other Chips you want to use)
c. Select OK.
The compiler automatically makes the toggleProject and adds an assembly file to it.
Page 5
Writing the first Assembly program
Type the following program.
;
; toggleProject.asm
;
LDI R16,0xFF
OUT DDRB,R16
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.
Page 6
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 toggleProject.
Page 7
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 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.
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.
Page 8
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. Press F10 (Step Over) a few times and see the PORTB register changes in the I/O window.
Page 9
Using Breakpoints
If you want to debug a portion of a program, add a breakpoint to the beginning of this part of the
code and press the run button. The IDE runs the program and when it reaches the breakpoint, it
stops running and the yellow cursor is shown on the breakpoint line. Below, you see the steps in
detail.
1. Right click on the "OUT PORTA,R20" instruction. A pop-up menu appears. Choose Breakpoint
and then Insert Breakpoint. A red bullet appears on the left side of the "OUT PORTB,R20"
instruction.
2. Press F5 or the Continue button. The IDE runs program until it reaches the Breakpoint. Now,
you can continue debugging from the breakpoint using the Step into and Step over buttons.
Step over
(F10)
A breakpoint
3. Using Stop Debugging, you can stop debugging whenever you want.
Page 10