Lab 1. Atmel Studio – review.
Arithmetic and logic program
debugging
Professor: Oleg Nepomnuashchiy
Assistant: Svetlana Leshchenko
Course lab outline (Semester one)
№1 – Microchip Studio – review. Arithmetic and logic program debugging.
№2 – Memory and data application design.
№3 – IO Ports.
№4 – Embedded interrupt controller.
№5 – EEPROM controller.
№6 – Timers.
№7 – Analog to digital converter.
We`ll use: the AVR Assembler, Microchip Studio IDE and STK500/600 - evolution board.
The second one is free available by link:
https://www.microchip.com/content/dam/mchp/documents/parked-documents/as-
installer-7.0.2542-web.exe
2
First Project Creating
Lets start the Atmel Studio
and go on step by step
1. Select <New Project>
See more at https://start.atmel.com/
3
First Project Creating
2. Choose a type of Project.
So, We`ll use the AVR
assembler.
3. Enter a project name.
Whatever you want.
4
First Project Creating
4. Now lets select the
microcontroller`s type we`ll
used for.
Choose ATmega32A from
the list.
5
First Project Creating
5. Choose
Evolution board
Tools >> Add
target
6
First Project Creating
In the appeared window,
select:
1) connected board STK500
2) the port through which
the board is connected.
As usually COM3
7
First Project Creating
6. Choose a
target which will
run IDE
Select Simulator
8
First Project Creating
7. Select debugger/programmer
In the window that appears in the
Tools tab, specify:
• Board used – STK500
• Interface - ISP
9
First Project Creating
8. Build the project
To compile the project and
download the firmware to the
device, click on the
Start Debugging button (F5)
or Start Without Debugging
(Ctrl + Alt + F5)
10
Debugging a project
1. Breakpoints
To make a breakpoint put your
mouse on a grey stripe and
click on it.
Now, you have a red point – it
is BREAKPOINT.
11
Debugging a project
2. Manual debugging.
Use the Debug menu
By pressing the
hotkeys, you can
manually control the
debugging of the
project.
For example:
Continue to pressing
F10 if you`d like to
follow step by step
12
Example 1 numeric systems
Window >> Registers
Use the Registers window to visual control and manual fill
a register. Double click on a content and write a data.
When a content will changed, it will be have red color. 13
Example 2. Summary and Status register
SREG (Status Register)
Bit Flag Flag Description
0 C Carry flag
1 Z Zero flag
2 N Negative flag
3 V Two`s complement overflow flag
4 S Sign bit
5 H Half carry flag
6 T Bit copy storage
7 I Global interrupt enable
Example 3. Branching and loops
15
Example 4. the couple of life hack
// What is the 3-th bit of r22
// 1 or 0?
// if it`s one then r25=255
// else r25=0
ldi r22, 0b00010011 // the number
andi r22, 0b00001000 // the mask
brne zero // branch if
// SREG (bit Z=1)
ldi r25,0xFF // else r25=255
…
zero: ldi r25,0 // r25=0
…
16
Lab 1. The task
Purpose of work: writing a number to a register, supporting addition and subtraction over
registers, comparing registers and constants, organizing loops, working with bits.
Find the function F(r28) of the numbers A(r31), B(r30), C(r29). If F is greater than the number
D(r27), then I(r26)=9, if less then 12. Multiply the numbers E(r25) by I. And in the received
result bits under the G number, if the bit is 1, then write all ones in the resulting register (r20),
and if the bit is 0, then all zeros.
An example:
Function: F=A-B+3*C,
Where A=160, B=55, C=2, D=110, E=2, G=5.
When F=160-55+3*2=111
Compare the resulting number with the number D=110. It is more, therefore I = 9. We carry
out multiplication 2*9=18. The number 18 in the binary system will be 00010010. Bit with the
number G=5 is equal to 1 - 00010010. The resultant r20 register write all ones.
17
Lab 1. The forms
Forms Function (F) A B C D E G
1 A+3*B-C 12 32 53 120 2 0
2 2*A+B+C 4 150 9 76 3 1
3 A+3*B+C 45 14 34 244 4 2
4 A-2*B+C 232 68 10 65 2 3
5 (A+B)-C 105 29 74 101 3 4
6 2*(A-B)+C 68 43 129 149 4 5
7 A+(B-2*C) 22 142 62 48 2 6
8 A-(B+C) 178 13 102 50 3 7
9 A-B-2*C 164 54 20 71 4 0
10 (A-B)+3*C 35 10 5 15 2 1
11 3*A+B-C 5 100 53 78 3 2
12 A+3*B-C 50 15 7 64 4 3
13 2*(A-B)+C 158 126 147 232 2 4
14 A+2*(B+C) 67 42 3 81 3 5
15 A-B+3*C 241 179 7 115 4 6
18
Useful links and reading
1. Microchip Studio IDE page free download:
https://www.microchip.com/content/dam/mchp/documents/parked-
documents/as-installer-7.0.2542-web.exe
2. Getting started with Microchip Studio. Video tutorials ep.1-6
https://www.youtube.com/watch?v=9W7tPUkaUZ0&list=PL9B4edd-
p2ajRbjkjMuTt8lz_VeE8IKva
3. Atmel assembler instructions free download
http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-
instruction-set-manual.pdf
4. Atmel assembler for beginners Beginners Introduction to the Assembly
Language of ATMEL-AVR-Microcontrollers by Gerhard Schmidt http://www.avr-
asm-tutorial.net April 2020.
19