SlidePub
Home
Categories
Login
Register
Home
General
AVR_ Microcontroller_Muhammad Ali_Mazidi_AVR_Lecture4_Fall2023
AVR_ Microcontroller_Muhammad Ali_Mazidi_AVR_Lecture4_Fall2023
60 views
34 slides
Aug 17, 2024
Slide
1
of 34
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
About This Presentation
AVR Microcontroller Muhammad Ali Mazidi
Size:
855.73 KB
Language:
en
Added:
Aug 17, 2024
Slides:
34 pages
Slide Content
Slide 1
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Branch, Call, and Time Delay LoopBranch, Call, and Time Delay Loop
Chapter 4Chapter 4
The AVR microcontroller
and embedded
systems
using assembly and c
Slide 2
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Branch Instruction and LoopingBranch Instruction and Looping
•Looping in AVR:
•Repeating a sequence of instructions or an operation a certain number of times is
called a loop.
•In the above program, we add 3 to R16 six times. That makes 6 x 3 = 18 = 0x12.
•One problem with the above program I that too much code space would be needed to
increase the number of repetitions to 50 or 100.
Slide 3
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Using BRNE instruction for looping:
•The BRNE (branch if not equal) instruction uses the zero flag in the status register.
Slide 4
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 5
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 6
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Loop inside a loop
•We use a loop inside a loop, which is called a nested loop.
Slide 7
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 8
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 9
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Other conditional jumps
•BREQ (branch if equal, branch if Z = 1)
Slide 10
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
BRSH (branch if same or higher, branch if C = 0)
will execute the next instruction below BRSH.
Slide 11
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 12
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Unconditional branch instruction
•JMP (JMP is a long jump):
•JMP is an unconditional jump that can go to any memory location in the 4M (word)
address space of the AVR.
•10 bit for opcode.
•The 22 bit target address allows a jump to 4M (words) of memory locations from
$000000 to $3FFFFF so it can cover the entire address space.
•RJMP (relative jump):
•In this 2 byte (16bit) instruction, the first 4 bit are the opcode and the rest (lower 12
bits) is the relative address of the target location.
•The address range of $000 - $FFF is divided into forward and backward jumps.
•IJMP(indirect jump):
•IJMP is a 2 byte instruction. When the instruction executes, the PC is loaded with the
content of the Z register, so it jump to the address pointed by the Z register.
Slide 13
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Call instructions and StackCall instructions and Stack
•CALL
Slide 14
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Stack and stack pointer in AVR
•The stack is a section of RAM used by the CPU to store information temporarily. This
information could be data or an address.
•How stack are accessed in the AVR:
•If the stack is a section of RAM, there must be a register inside the CPU to point to it.
The register used to access the stack is called the SP (stack pointer) register.
•SPL (low byte of the SP) and SPH (high byte of the SP).
Slide 15
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•To store the value in stack we use PUSH command and retrieve the value back POP.
•Pushing onto the stack
•The stack pointer (SP) point to the top of the stack (TOS). As we push data onto the
stack, the data are saved where the SP points to and the SP is decremented by one.
•Popping from the stack
•Popping the contents of the stack back into a given register I the opposite process of
pushing. When POP instruction is executed, the SP is incremented and the top
location of the stack is copied back to the register. That means the stack is LIFO (last
in first out) memory.
Slide 16
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Initializing the stack pointer
Slide 17
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 18
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•CALL instruction and the role of the stack
•RET instruction and the role of the stack
Slide 19
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 20
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 21
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Calling many subroutines from the main program:
•In Assembly language programming, it is common to have one main program and
many subroutines that are called from the main program.
Slide 22
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•RCALL (relative call)
Slide 23
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 24
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
AVR Time Delay and Instruction PipelineAVR Time Delay and Instruction Pipeline
•Delay calculation for the AVR:
•In creating a time delay using Assembly language instruction, one must be mindful of
two factors that can affect the accuracy of the delay
•1. The crystal frequency
•2. The AVR design
•Done using three ways to do that
•1. Use Harvard architecture
•2. Use RISC architecture
•3. Use pipelining
•Pipelining
Slide 25
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•AVR multistage execution pipeline
•In AVR each instruction is executed in 3 stages: operand fetch, ALU operation
execution, and result write back.
Slide 26
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
•Instruction cycle time for the AVR
•It takes a certain amount of time for the CPU to execute an instruction.
•This is referred to as machine cycles.
•Because all the instructions in the AVR are either 1 word (2byte) or 2 word (4byte)
most instruction take no more than one or two machine cycles to execute.
Slide 27
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 28
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 29
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 30
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 31
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 32
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 33
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Slide 34
www. Mi cro D igit al Ed. com
BIH E universit y
AVR Microcontroller and Embedded System Using Assembly and C
Mazidi, Naimi, and Naimi
© 2011 Pearson Higher Education,
Upper Saddle River, NJ 07458. • All Rights Reserved.
Questions and AnswersQuestions and Answers
END
Tags
Categories
General
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
60
Slides
34
Age
472 days
Related Slideshows
22
Pray For The Peace Of Jerusalem and You Will Prosper
RodolfoMoralesMarcuc
32 views
26
Don_t_Waste_Your_Life_God.....powerpoint
chalobrido8
33 views
31
VILLASUR_FACTORS_TO_CONSIDER_IN_PLATING_SALAD_10-13.pdf
JaiJai148317
31 views
14
Fertility awareness methods for women in the society
Isaiah47
30 views
35
Chapter 5 Arithmetic Functions Computer Organisation and Architecture
RitikSharma297999
27 views
5
syakira bhasa inggris (1) (1).pptx.......
ourcommunity56
29 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-34)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better