ES&RTOS-Firstppt IMODULE
ES&RTOS-Firstppt IMODULE
Operating System(5131)
1
Course Objectives:
● Introduce the technologies behind embedded
computing systems.
● Provide knowledge on the working of microcontrollers
and its applications.
● Familiarize the key concepts of embedded systems
such as I/O, timers, interrupts and interaction with
peripheral devices.
● Introduce the basic concepts of Embedded Operating
Systems.
•
Reference Textbooks
3
• Course Outcomes :
5
Content Details
What is Microprocessor ?
Central Processing Unit
(CPU): Control the
operation of the computer
and performs its data CPU
processing functions;
often simply referred to
as PROCESSPR
Microprocessor
Addres
s
Control
Boot
CPU Instruction
Data Input/ External
ROM (program
RAM Output Comm.
Used at ) ROM
startup
Data
• The fixed amount of on chip RAM,ROM and number of I/O ports and
timers in microcontrollers makes them ideal for many applications in
which cost and size are critical.
Microcontroller – Basic concept
Addres
s
Control
Dat
a
-CPU
-RAM
-ROM/EPROM
-I/O ports
-Timers and counters
-interrupt logic
-ADC
-DAC
• -Serial port
• -Oscillator Circuitry
• -Additional device and specific functional blocks.
Microcontroller
Some major 8-bit microcontrollers
are :
◦ Freescale Semiconductor’s 68HC08/68HC11
◦ Intel’s 8051
◦ Atmel’s AVR
◦ Zilong’s Z8
15
16
Microprocessor vs Microcontroller
• Microprocessor: • Microcontroller:
• a microprocessor-based system
• built to control a function or range of functions
• not designed to be programmed by the end user in the
same way that a PC is
• Usually embedded as part of a complete
device including hardware and mechanical parts
System
SOFTWARE PROGRAM
#include <16f876a.h>
#use delay (clock=20000000)
#byte P O RT B = 6
main()
{
set_tris_b(0);
portb=255; //decimal
d e la y _ m s (1 0 0 0 );
portb=0x55; //hexadecimal
d e la y _ m s (1 0 0 0 );
p o rtb = 0 b 1 0 1 0 1 0 1 0 ; //binary
delay_ms(500);
}
Embedded system
• So the designer need not add any additional digital part(to make system
functional) to complete the system and thus the system is economic and
handy.
• The additional external parts always makes the system more expensive
and bulkier.
1)Computing need:-
-Microcontroller should meet the task at hand efficiently and economically.
-this can be analyzed with the following features
• ---Bit size(8 bit, 16 bit, or 32 bit)
----power consumption
----speed
-------Instruction set(RISC or CISC)
-----
Criteria for Choosing a Microcontroller
3.Availability:-
-the next criteria in choosing the microcontroller is its availability in the
required quantity both now and future.
44
You should now be able
to:◦ Compare and contrast microcontrollers and
microprocessors.
◦ List some names of MCs.
◦ Discuss advantages of MCs for Ess
◦ Compare MPs with MCs.
◦ Discuss criteria for considering a MC.
45
By the end of this session, you should be
able to:
46
AVR stand
for?
Advanced Virtual RISC,
the founders are Alf Egil Bogen,
Vegard Wollan
47
OVERVIEW OF AVR
MICROCONTROLLER
51
• Many kinds of AVR with different properties
• Except for AVR32 which is 32bit all AVRs are 8
bit meaning that the CPU can work on only 8
bit of data.
• Data larger than 8 bit is broken in to 8 bit
pieces
• Programs written for one family is not 100%
compatible for other family
• AVRs are classified into four
• Mega
• Tiny
• Special purpose
• Classic
• Mega family is widely used as they are
powerful.
• widely available and comes in Dip
packages
The AVR is a modified Harvard architecture
machine where program and data is stored in
separate physical memory systems that
appear in different address spaces, but
having the ability to read data items from
program memory using special instructions.
54
55
The Harvard architecture is a computer
architecture with physically separate
storage and signal pathways for
instructions and data.
56
The term originated from the Harvard
Mark I relay-based computer, which
stored instructions on punched tape (24
bits wide) and data in electro-
mechanical counters.
57
58
59
In contrast with the Harvard architecture, the
von Neumann architecture has a single
storage structure to hold both instructions
and data.
The CPU can be either reading an instruction
or reading/writing data f r om/ t o the
memory because instructions and data use
the same bus system.
60
The phrase Von Neumann architecture
derives name of the mathematician and
early computer scientist John von
Neumann.
61
series of 8 - b i t RISC microcontrollers from Atmel.
62
AVR is a family of 8 - b i t microcontrollers with
a large range of variants differing in:
63
64
65
All of the product numbers start with AT,
which stands for Atmet.
Now, look at the product number, from left to
right, and
find the biggest number that is power of 2.
This number most probably
shows the amount of microcontroller’s ROM.
66
Eg:-
Atmega 1280,the biggest power of 2 is 128.
-so it has 128 Kbytes of ROM.
-ATtiny 44,the amount of memory is 4K.
-ATmega169 ,the amount of ROM is 16K.
Classic AVR (AT90Sxxxx)
Mega AVR (ATmegaxxxx)
Tiny AVR (ATtinyxxxx)
Special purpose AVR
* x x x x is the product
number
69
71
73
75
Special capabilities are:- LCD
controller. USB controller,
Ethernet controller etc
77
AVR with other Microcontrollers
85
Basics About AVR microcontroller.
-AVR microcontroller is an 8 bit , RISC single chip mc with Harvard
architecture that come with some std features
---on-chip ROM
----data RAM
---data EEPROM
---timers and I/O ports.
-it consists of 32,8 bit general purpose working registers.
AVR does not have registers like accumulator .
-so the operation can be performed b/w any of the registers and can be
stored in either of them.
-it follows Harvard architecture format .
-the processor equipped with separate memories and buses for pgm and
data .
-so prefetching is possible.
-AVR can execute a million instructions per second if cycle frequency is
1MHz.
-higher is the frequency,higher will be the processing speed.
Basic AVR architecture
Oscillator:-
-calibrated with an internal oscillator for driving its clock.
-By default it is set to operate with a frequency of 1 MHz.
-maximum frequency is 8MHz.
-it also set with an external crystal oscillator with a maximum frequency of
16 MHz.
AVR-Basic Architecture
ADC interface:-
-it is equipped with an 8 channel ADC with resolution of 10 bits.
-ADC reads the analog i/p from a sensor or from any other sources and
converts it into digital information which is understandable by the
microcontroller.
AVR-Basic Architecture
Timers/Counters:
It consists of 2 8-bit and 1 16-bit imer/counter.
-timers are useful for creating time delays b/w two operations.
WDT:-
-it is present with internal oscillator.
-WDT continously monitors and reset the controller if the code gets stuck
at any execution action for more than a defined interval.
AVR-Basic Architecture
Interrupt:-
-it consists of 21 interrupt sources out of which 4 are external.
-the remaining are internal which support the peripherals like
USART,ADC,and timers etc.
USART:-
-USART interface is available for interfacing with external device
capable of communicating serially(data transmission bit by bit).
Registers: Two types of registers
◦ GERNEL purpose & SPECIAL purpose registers
GERNERAL purpose(GPRs)
◦ 32 general purpose registers having storage capacity of 8-Bits
◦ Named as R0,R1,R2 to R31 coupled directly with ALU.
◦ Register 0 to 15 & 16 to 31 are different.
◦ Can store both Data & Addresses.
94
There are 32 GPR
All are of size 8 bit
D0 is LSB
D7 is MSB
R0-R31 are located in the lowest
memory location of mem addr.
95
AVR-GPRS
99
LDI R20, 0x25 ; load R20 with 0x25 (R20 = 0x25)
100
LDI R5, 0x25 ; why?
101
ADD Rd, Rr ; ADD Rr to Rd and store
the result in Rd.
102
LDI R16, 0x25 ; load 0x25 into
R16 LDI R17, 0x34 ; load 0x34
into R17 ADD R16, R17
Executing the above lines results R16=0x59.
103
/*
* adding.asm
* Created: 1 2 / 2 / 2 0 1 7 9:35:52
PM
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X25 ; load 0x25 into R16
LDI ; load 0x32 into R17
ADD R17,0X35 ; add value R17 to R16
R16, R17
NEXT: JMP
NEXT
104
105
106
DATA MEMORY
GPRs
◦ GPRs use 32 bytes of data memory space.
◦ They always take the address location $00 - $1F in
the data memory space, regardless of the AVR
chip number.
109
I/O MEMORY(SFRs)
-functions of I/O memory is fixed by the CPU designer at the time of
design.
-it is used for control of the microcontroller or peripheral..
-the AVR I/O memory is made of 8-bit registres.
-it is used for specific functions such as
----status register
----temers
----serial communication
-I/O ports
---ADC
-all the AVR ha at least 64bytes of I/O memory locations
-this 64 byte is called standard I/O memory.
-AVR with more than 32 pins(Atmega64,Atmega128etc),there are an
extended I/O memory .
-extended I/O memory is used for controlling the extra ports and
peripherals.
-I/O memory is called SFRs since each one is dedicated to a specific
function.
112
Internal data
SRAM
◦ Internal data is widely used for storing data and
parameters by AVR programmers and C compilers.
Generally that is called scratch pad.
◦ Each location of SRAM can be accessed by its
address.
◦ Each location is 8 bits wide.
◦ Size of data SRAM can vary form chip to chip
113
SRAM vs EEPROM
• AVR as an EEPROM memory that is used for storing
data.
• EEPROM does not lose it’s data when power id off
where as SRAM lose its data when power is on
• EEPROM is used for storing data that should rarely be
changed whereas the SRAM is used for storing data
and parameters that are changed frequently.
• In AVR data sheet EEPROM refers to EEPROM’s size
and SRAM is the internal SRAM’s size.
115
USING INSTRUCTIONS WITH DATA MEMORY
117
LDS:-
This instruction instruct CPU to copy one byte from a location in the data
memory to one of the GPRs.
119
120
STS K, Rr ; Store Rr into locaton K
; K is an addr b / w $0000 to
$FFFF
121
STS(Store direct To data space)
- this instruction tells the CPU to store the content of the GPR to an
address in the data memory.
Eg:-
STS 0x230,R25 ;store R25 to data space location 0x230
To add the content of location 0x300 to content of location 0x302 and
store the result in 0x303
LDS R16,0x300
LDS R17,0X302
ADD R16,R17
STS 0X303,R16
STP:JMP STP
SAMPLE PROGRAMS
Load the value 0x92 into location from 0x200 to 0x203 of the SRAM region
in the data memory.
LDI R20,0X99
STS 0X200,R20
STS 0X201,R20
STS 0X202,R20
STS 0X203,R20
/*
* STA.asm
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X99
0X212,R16
ST R16,0X85
S 0X213,R16
LDI R16,0X3F
0X214,R16
ST R16,0X63
S 0X215,R16
LDI NEXT
ST
S
LDI 125
IN instruction(IN from I/O location
IN
IN Rd,A ;load an I/O location to GPR
0<=d<=31
0<=A<=63
IN instruction tells the CPU to load one byte from an I/O register to GPR.
After the execution,GPR will have the same value as I/O register.
In IN instruction,the I/O registers are referred by their I/O address.($00 to
$3F)
IN Instruction
129
IN R19, 0x10 ; load R19 with location $10
130
IN R1, PIND ; load R1 with PIND
IN R2, PINB ; load R2 with PINB
ADD R1, ;R1=R1+R2
R2 ;Store R1 to $0300
STS 0x300,
R1
131
1. The CPU executes the IN instruction faster than LDS.
The IN lasts 1 machine cycle, where LDS lasts 2
machine cycles.
132
OUT A, Rr ; store register to I/O location
;0≤d≤31
;A is an I/O addr b / w $00 to $3F
;(0≤A≤63)
133
OUT (Out to I/O location)
OUT instruction tells the CPU to store GPR to the I/O register.
135
MOV Rd,
; Rd = Rr (copy Rr to Rd)
Rr ; Rd and Rr can be any of
GPRS
136
MOV
-This instruction is used to copy the data among the GPR register to R0-
R31
MOV Rd,Rr
MOV R10,R20
Eg:-
Add the immediate value 0x19 with the content of memory location
0x220 and the result has to be stored in to 0x225
LDI R20,0x19
LDS R21,0x220
ADD R20,R21
STS 0X225,R20
INC
; increment the content of Rd by one
Rd ; 0≤d≤31
INC R2 ; R2 = R2 + 1
139
DEC
; decrement the content of Rd by one
Rd ; 0≤d≤31
DEC R2 ; R2 = R2 - 1
140
SUB Rd,
; Rd = Rd - Rr
Rr ; Rd and Rr can be any of
GPRS
141
Complements (inverts) the content of Rd
and place the result back into the Rd
register.
142
AVR Status register
• Status register is an 8 bit register also known a
flag register.
• The bits C,Z,N,V,S, and H are called conditional
flag meaning that they indicate some
condition that result after an instruction is
executed.
144
Carry Flag C
• This flag is set whenever there is a carry out
from the D7 bit.
• This flag bit is affected after an 8 bit addition
or subtraction.
ZERO flag Z
• This flag reflect the result of an arithmetic or
logic operation .
• If the result is 0 then Z=1
• If the result is not = 0 then Z=0
Negative flag N
• Binary representation of signed numbers uses
D7 as the sign bit.
• Negative flag reflect the result of an
arithmetic operation .
• If the D7 bit of the result is 0, then N=0 and
the result is positive.
• If the D7 bit of the result is 1, then N=1 and
the result is negative.
Overflow Bit V
• This flag is set whenever the result of an
signed number operation is too large .
• Overflow flag is used to detect errors in signed
arithmetic operation .
Sign Bit S
• Used with BLD (bit load) and BST(bit store)instructions for loading
and storing bit from one register to another.
Global Interrupt Enable
166
Thank
ou
167
What is an Embedded System?
• a microprocessor-based system
• built to control a function or range of functions
• not designed to be programmed by the end user in the
same way that a PC is
• Usually embedded as part of a complete
device including hardware and mechanical parts
System
SOFTWARE PROGRAM
#include <16f876a.h>
#use delay (clock=20000000)
#byte P O RT B = 6
main()
{
set_tris_b(0);
portb=255; //decimal
d e la y _ m s (1 0 0 0 );
portb=0x55; //hexadecimal
d e la y _ m s (1 0 0 0 );
p o rtb = 0 b 1 0 1 0 1 0 1 0 ; //binary
delay_ms(500);
}
Embedded system
• So the designer need not add any additional digital part(to make system
functional) to complete the system and thus the system is economic and
handy.
• The additional external parts always makes the system more expensive
and bulkier.
1)Computing need:-
-Microcontroller should meet the task at hand efficiently and economically.
-this can be analyzed with the following features
• ---Bit size(8 bit, 16 bit, or 32 bit)
----power consumption
----speed
-------Instruction set(RISC or CISC)
-----
Criteria for Choosing a Microcontroller
3.Availability:-
-the next criteria in choosing the microcontroller is its availability in the
required quantity both now and future.
183
You should now be able
to:◦ Compare and contrast microcontrollers and
microprocessors.
◦ List some names of MCs.
◦ Discuss advantages of MCs for Ess
◦ Compare MPs with MCs.
◦ Discuss criteria for considering a MC.
184
By the end of this session, you should be
able to:
185
AVR stand
for?
Advanced Virtual RISC,
the founders are Alf Egil Bogen Vegard
Wollan RISC
186
OVERVIEW OF AVR
MICROCONTROLLER
190
• Many kinds of AVR with different properties
• Except for AVR32 which is 32bit all AVRs are 8
bit meaning that the CPU can work on only 8
bit of data.
• Data larger than 8 bit is broken in to 8 bit
pieces
• Programs written for one family is not 100%
compatible for other family
• AVRs are classified into four
• Mega
• Tiny
• Special purpose
• Classic
• Mega family is widely used as they are
powerful.
• widely available and comes in Dip
packages
The AVR is a modified Harvard architecture
machine where program and data is stored in
separate physical memory systems that
appear in different address spaces, but
having the ability to read data items from
program memory using special instructions.
193
194
The Harvard architecture is a computer
architecture with physically separate
storage and signal pathways for
instructions and data.
195
The term originated from the Harvard
Mark I relay-based computer, which
stored instructions on punched tape (24
bits wide) and data in electro-
mechanical counters.
196
197
198
In contrast with the Harvard architecture, the
von Neumann architecture has a single
storage structure to hold both instructions
and data.
The CPU can be either reading an instruction
or reading/writing data f r om/ t o the
memory because instructions and data use
the same bus system.
199
The phrase Von Neumann architecture
derives name of the mathematician and
early computer scientist John von
Neumann.
200
series of 8 - b i t RISC microcontrollers from Atmel.
201
AVR is a family of 8 - b i t microcontrollers with
a large range of variants differing in:
202
203
204
All of the product numbers start with AT,
which stands for Atmet.
Now, look at the product number, from left to
right, and
find the biggest number that is power of 2.
This number most probably
shows the amount of microcontroller’s ROM.
205
Eg:-
Atmega 1280,the biggest power of 2 is 128.
-so it has 128 Kbytes of ROM.
-ATtiny 44,the amount of memory is 4K.
-ATmega169 ,the amount of ROM is 16K.
Classic AVR (AT90Sxxxx)
Mega AVR (ATmegaxxxx)
Tiny AVR (ATtinyxxxx)
Special purpose AVR
* x x x x is the product
number
208
210
212
214
Special capabilities are:- LCD
controller. USB controller,
Ethernet controller etc
216
AVR with other Microcontrollers
224
Basics About AVR microcontroller.
-AVR microcontroller is an 8 bit , RISC single chip mc with Harvard
architecture that come with some std features
---on-chip ROM
----data RAM
---data EEPROM
---timers and I/O ports.
-it consists of 32,8 bit general purpose working registers.
AVR does not have registers like accumulator .
-so the operation can be performed b/w any of the registers and can be
stored in either of them.
-it follows Harvard architecture format .
-the processor equipped with saparate memories and buses for pgm and
data .
-so prefetching is possible.
-AVR can execute a million instructions per second if cycle frequency is
1MHz.
-higher is the frequency,higher will be the processing speed.
Basic AVR architecture
Oscillator:-
-calibrated with an internal oscillator for driving its clock.
-By default it is set to operate with a frequency of 1 MHz.
-maximum frequency is 8MHz.
-it also set with an external crystal oscillator with a maximum frequency of
16 MHz.
AVR-Basic Architecture
ADC interface:-
-it is equipped with an 8 channel ADC with resolution of 10 bits.
-ADC reads the analog i/p from a sensor or from any other sources and
converts it into digital information which is understandable by the
microcontroller.
AVR-Basic Architecture
Timers/Counters:
It consists of 2 8-bit and 1 16-bit imer/counter.
-timers are useful for creating time delays b/w two operations.
WDT:-
-it is present with internal oscillator.
-WDT continously monitors and reset the controller if the code gets stuck
at any execution action for more than a defined interval.
AVR-Basic Architecture
Interrupt:-
-it consists of 21 interrupt sources out of which 4 are external.
-the remaining are internal which support the peripherals like
USART,ADC,and timers etc.
USART:-
-USART interface is available for interfacing with external device
capable of communicating serially(data transmission bit by bit).
Registers: Two types of registers
◦ GERNEL purpose & SPECIAL purpose registers
GERNERAL purpose(GPRs)
◦ 32 general purpose registers having storage capacity of 8-Bits
◦ Named as R0,R1,R2 to R31 coupled directly with ALU.
◦ Register 0 to 15 & 16 to 31 are different.
◦ Can store both Data & Addresses.
233
There are 32 GPR
All are of size 8 bit
D0 is LSB
D7 is MSB
R0-R31 are located in the lowest
memory location of mem addr.
234
AVR-GPRS
238
LDI R20, 0x25 ; load R20 with 0x25 (R20 = 0x25)
239
LDI R5, 0x25 ; why?
240
ADD Rd, Rr ; ADD Rr to Rd and store
the result in Rd.
241
LDI R16, 0x25 ; load 0x25 into
R16 LDI R17, 0x34 ; load 0x34
into R17 ADD R16, R17
Executing the above lines results R16=0x59.
242
/*
* adding.asm
* Created: 1 2 / 2 / 2 0 1 7 9:35:52
PM
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X25 ; load 0x25 into R16
LDI ; load 0x32 into R17
ADD R17,0X35 ; add value R17 to R16
R16, R17
NEXT: JMP
NEXT
243
244
245
DATA MEMORY
GPRs
◦ GPRs use 32 bytes of data memory space.
◦ They always take the address location $00 - $1F in
the data memory space, regardless of the AVR
chip number.
248
I/O MEMORY(SFRs)
-functions of I/O memory is fixed by the CPU designer at the time of
design.
-it is used for control of the microcontroller or peripheral..
-the AVR I/O memory is made of 8-bit registres.
-it is used for specific functions such as
----status register
----temers
----serial communication
-I/O ports
---ADC
-all the AVR ha at least 64bytes of I/O memory locations
-this 64 byte is called standard I/O memory.
-AVR with more than 32 pins(Atmega64,Atmega128etc),there are an
extended I/O memory .
-extended I/O memory is used for controlling the extra ports and
peripherals.
-I/O memory is called SFRs since each one is dedicated to a specific
function.
251
Internal data
SRAM
◦ Internal data is widely used for storing data and
parameters by AVR programmers and C compilers.
Generally that is called scratch pad.
◦ Each location of SRAM can be accessed by its
address.
◦ Each location is 8 bits wide.
◦ Size of data SRAM can vary form chip to chip
252
SRAM vs EEPROM
• AVR as an EEPROM memory that is used for storing
data.
• EEPROM does not lose it’s data when power id off
where as SRAM lose its data when power is on
• EEPROM is used for storing data that should rarely be
changed whereas the SRAM is used for storing data
and parameters that are changed frequently.
• In AVR data sheet EEPROM refers to EEPROM’s size
and SRAM is the internal SRAM’s size.
254
USING INSTRUCTIONS WITH DATA MEMORY
256
LDS:-
This instruction instruct CPU to copy one byte from a location in the data
memory to one of the GPRs.
258
259
STS K, Rr ; Store Rr into locaton K
; K is an addr b / w $0000 to
$FFFF
260
STS(Store direct To data space)
- this instruction tells the CPU to store the content of the GPR to an
address in the data memory.
Eg:-
STS 0x230,R25 ;store R25 to data space location 0x230
To add the content of location 0x300 to content of location 0x302 and
store the result in 0x303
LDS R16,0x300
LDS R17,0X302
ADD R16,R17
STS 0X303,R16
STP:JMP STP
SAMPLE PROGRAMS
Load the value 0x92 into location from 0x200 to 0x203 of the SRAM region
in the data memory.
LDI R20,0X99
STS 0X200,R20
STS 0X201,R20
STS 0X202,R20
STS 0X203,R20
/*
* STA.asm
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X99
0X212,R16
ST R16,0X85
S 0X213,R16
LDI R16,0X3F
0X214,R16
ST R16,0X63
S 0X215,R16
LDI NEXT
ST
S
LDI 264
IN instruction(IN from I/O location
IN
IN Rd,A ;load an I/O location to GPR
0<=d<=31
0<=A<=63
IN instruction tells the CPU to load one byte from an I/O register to GPR.
After the execution,GPR will have the same value as I/O register.
In IN instruction,the I/O registers are referred by their I/O address.($00 to
$3F)
IN Instruction
268
IN R19, 0x10 ; load R19 with location $10
269
IN R1, PIND ; load R1 with PIND
IN R2, PINB ; load R2 with PINB
ADD R1, ;R1=R1+R2
R2 ;Store R1 to $0300
STS 0x300,
R1
270
1. The CPU executes the IN instruction faster than LDS.
The IN lasts 1 machine cycle, where LDS lasts 2
machine cycles.
271
OUT A, Rr ; store register to I/O location
;0≤d≤31
;A is an I/O addr b / w $00 to $3F
;(0≤A≤63)
272
OUT (Out to I/O location)
OUT instruction tells the CPU to store GPR to the I/O register.
274
MOV Rd,
; Rd = Rr (copy Rr to Rd)
Rr ; Rd and Rr can be any of
GPRS
275
MOV
-This instruction is used to copy the data among the GPR register to R0-
R31
MOV Rd,Rr
MOV R10,R20
Eg:-
Add the immediate value 0x19 with the content of memory location
0x220 and the result has to be stored in to 0x225
LDI R20,0x19
LDS R21,0x220
ADD R20,R21
STS 0X225,R20
INC
; increment the content of Rd by one
Rd ; 0≤d≤31
INC R2 ; R2 = R2 + 1
278
DEC
; decrement the content of Rd by one
Rd ; 0≤d≤31
DEC R2 ; R2 = R2 - 1
279
SUB Rd,
; Rd = Rd - Rr
Rr ; Rd and Rr can be any of
GPRS
280
Complements (inverts) the content of Rd
and place the result back into the Rd
register.
281
AVR Status register
• Status register is an 8 bit register also known a
flag register.
• The bits C,Z,N,V,S, and H are called conditional
flag meaning that they indicate some
condition that result after an instruction is
executed.
283
Carry Flag C
• This flag is set whenever there is a carry out
from the D7 bit.
• This flag bit is affected after an 8 bit addition
or subtraction.
ZERO flag Z
• This flag reflect the result of an arithmetic or
logic operation .
• If the result is 0 then Z=1
• If the result is not = 0 then Z=0
Negative flag N
• Binary representation of signed numbers uses
D7 as the sign bit.
• Negative flag reflect the result of an
arithmetic operation .
• If the D7 bit of the result is 0, then N=0 and
the result is positive.
• If the D7 bit of the result is 1, then N=1 and
the result is negative.
Overflow Bit V
• This flag is set whenever the result of an
signed number operation is too large .
• Overflow flag is used to detect errors in signed
arithmetic operation .
Sign Bit S
• Used with BLD (bit load) and BST(bit store)instructions for loading
and storing bit from one register to another.
Global Interrupt Enable
305
Thank
ou
306
What is an Embedded System?
• a microprocessor-based system
• built to control a function or range of functions
• not designed to be programmed by the end user in the
same way that a PC is
• Usually embedded as part of a complete
device including hardware and mechanical parts
System
SOFTWARE PROGRAM
#include <16f876a.h>
#use delay (clock=20000000)
#byte P O RT B = 6
main()
{
set_tris_b(0);
portb=255; //decimal
d e la y _ m s (1 0 0 0 );
portb=0x55; //hexadecimal
d e la y _ m s (1 0 0 0 );
p o rtb = 0 b 1 0 1 0 1 0 1 0 ; //binary
delay_ms(500);
}
Embedded system
• So the designer need not add any additional digital part(to make system
functional) to complete the system and thus the system is economic and
handy.
• The additional external parts always makes the system more expensive
and bulkier.
1)Computing need:-
-Microcontroller should meet the task at hand efficiently and economically.
-this can be analyzed with the following features
• ---Bit size(8 bit, 16 bit, or 32 bit)
----power consumption
----speed
-------Instruction set(RISC or CISC)
-----
Criteria for Choosing a Microcontroller
3.Availability:-
-the next criteria in choosing the microcontroller is its availability in the
required quantity both now and future.
321
You should now be able
to:◦ Compare and contrast microcontrollers and
microprocessors.
◦ List some names of MCs.
◦ Discuss advantages of MCs for Ess
◦ Compare MPs with MCs.
◦ Discuss criteria for considering a MC.
322
By the end of this session, you should be
able to:
323
AVR stand
for?
Advanced Virtual RISC,
the founders are Alf Egil Bogen Vegard
Wollan RISC
324
OVERVIEW OF AVR
MICROCONTROLLER
328
• Many kinds of AVR with different properties
• Except for AVR32 which is 32bit all AVRs are 8
bit meaning that the CPU can work on only 8
bit of data.
• Data larger than 8 bit is broken in to 8 bit
pieces
• Programs written for one family is not 100%
compatible for other family
• AVRs are classified into four
• Mega
• Tiny
• Special purpose
• Classic
• Mega family is widely used as they are
powerful.
• widely available and comes in Dip
packages
The AVR is a modified Harvard architecture
machine where program and data is stored in
separate physical memory systems that
appear in different address spaces, but
having the ability to read data items from
program memory using special instructions.
331
332
The Harvard architecture is a computer
architecture with physically separate
storage and signal pathways for
instructions and data.
333
The term originated from the Harvard
Mark I relay-based computer, which
stored instructions on punched tape (24
bits wide) and data in electro-
mechanical counters.
334
335
336
In contrast with the Harvard architecture, the
von Neumann architecture has a single
storage structure to hold both instructions
and data.
The CPU can be either reading an instruction
or reading/writing data f r om/ t o the
memory because instructions and data use
the same bus system.
337
The phrase Von Neumann architecture
derives name of the mathematician and
early computer scientist John von
Neumann.
338
series of 8 - b i t RISC microcontrollers from Atmel.
339
AVR is a family of 8 - b i t microcontrollers with
a large range of variants differing in:
340
341
342
All of the product numbers start with AT,
which stands for Atmet.
Now, look at the product number, from left to
right, and
find the biggest number that is power of 2.
This number most probably
shows the amount of microcontroller’s ROM.
343
Eg:-
Atmega 1280,the biggest power of 2 is 128.
-so it has 128 Kbytes of ROM.
-ATtiny 44,the amount of memory is 4K.
-ATmega169 ,the amount of ROM is 16K.
Classic AVR (AT90Sxxxx)
Mega AVR (ATmegaxxxx)
Tiny AVR (ATtinyxxxx)
Special purpose AVR
* x x x x is the product
number
346
348
350
352
Special capabilities are:- LCD
controller. USB controller,
Ethernet controller etc
354
AVR with other Microcontrollers
362
Basics About AVR microcontroller.
-AVR microcontroller is an 8 bit , RISC single chip mc with Harvard
architecture that come with some std features
---on-chip ROM
----data RAM
---data EEPROM
---timers and I/O ports.
-it consists of 32,8 bit general purpose working registers.
AVR does not have registers like accumulator .
-so the operation can be performed b/w any of the registers and can be
stored in either of them.
-it follows Harvard architecture format .
-the processor equipped with saparate memories and buses for pgm and
data .
-so prefetching is possible.
-AVR can execute a million instructions per second if cycle frequency is
1MHz.
-higher is the frequency,higher will be the processing speed.
Basic AVR architecture
Oscillator:-
-calibrated with an internal oscillator for driving its clock.
-By default it is set to operate with a frequency of 1 MHz.
-maximum frequency is 8MHz.
-it also set with an external crystal oscillator with a maximum frequency of
16 MHz.
AVR-Basic Architecture
ADC interface:-
-it is equipped with an 8 channel ADC with resolution of 10 bits.
-ADC reads the analog i/p from a sensor or from any other sources and
converts it into digital information which is understandable by the
microcontroller.
AVR-Basic Architecture
Timers/Counters:
It consists of 2 8-bit and 1 16-bit imer/counter.
-timers are useful for creating time delays b/w two operations.
WDT:-
-it is present with internal oscillator.
-WDT continously monitors and reset the controller if the code gets stuck
at any execution action for more than a defined interval.
AVR-Basic Architecture
Interrupt:-
-it consists of 21 interrupt sources out of which 4 are external.
-the remaining are internal which support the peripherals like
USART,ADC,and timers etc.
USART:-
-USART interface is available for interfacing with external device
capable of communicating serially(data transmission bit by bit).
Registers: Two types of registers
◦ GERNEL purpose & SPECIAL purpose registers
GERNERAL purpose(GPRs)
◦ 32 general purpose registers having storage capacity of 8-Bits
◦ Named as R0,R1,R2 to R31 coupled directly with ALU.
◦ Register 0 to 15 & 16 to 31 are different.
◦ Can store both Data & Addresses.
371
There are 32 GPR
All are of size 8 bit
D0 is LSB
D7 is MSB
R0-R31 are located in the lowest
memory location of mem addr.
372
AVR-GPRS
376
LDI R20, 0x25 ; load R20 with 0x25 (R20 = 0x25)
377
LDI R5, 0x25 ; why?
378
ADD Rd, Rr ; ADD Rr to Rd and store
the result in Rd.
379
LDI R16, 0x25 ; load 0x25 into
R16 LDI R17, 0x34 ; load 0x34
into R17 ADD R16, R17
Executing the above lines results R16=0x59.
380
/*
* adding.asm
* Created: 1 2 / 2 / 2 0 1 7 9:35:52
PM
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X25 ; load 0x25 into R16
LDI ; load 0x32 into R17
ADD R17,0X35 ; add value R17 to R16
R16, R17
NEXT: JMP
NEXT
381
382
383
DATA MEMORY
GPRs
◦ GPRs use 32 bytes of data memory space.
◦ They always take the address location $00 - $1F in
the data memory space, regardless of the AVR
chip number.
386
I/O MEMORY(SFRs)
-functions of I/O memory is fixed by the CPU designer at the time of
design.
-it is used for control of the microcontroller or peripheral..
-the AVR I/O memory is made of 8-bit registres.
-it is used for specific functions such as
----status register
----temers
----serial communication
-I/O ports
---ADC
-all the AVR ha at least 64bytes of I/O memory locations
-this 64 byte is called standard I/O memory.
-AVR with more than 32 pins(Atmega64,Atmega128etc),there are an
extended I/O memory .
-extended I/O memory is used for controlling the extra ports and
peripherals.
-I/O memory is called SFRs since each one is dedicated to a specific
function.
389
Internal data
SRAM
◦ Internal data is widely used for storing data and
parameters by AVR programmers and C compilers.
Generally that is called scratch pad.
◦ Each location of SRAM can be accessed by its
address.
◦ Each location is 8 bits wide.
◦ Size of data SRAM can vary form chip to chip
390
SRAM vs EEPROM
• AVR as an EEPROM memory that is used for storing
data.
• EEPROM does not lose it’s data when power id off
where as SRAM lose its data when power is on
• EEPROM is used for storing data that should rarely be
changed whereas the SRAM is used for storing data
and parameters that are changed frequently.
• In AVR data sheet EEPROM refers to EEPROM’s size
and SRAM is the internal SRAM’s size.
392
USING INSTRUCTIONS WITH DATA MEMORY
394
LDS:-
This instruction instruct CPU to copy one byte from a location in the data
memory to one of the GPRs.
396
397
STS K, Rr ; Store Rr into locaton K
; K is an addr b / w $0000 to
$FFFF
398
STS(Store direct To data space)
- this instruction tells the CPU to store the content of the GPR to an
address in the data memory.
Eg:-
STS 0x230,R25 ;store R25 to data space location 0x230
To add the content of location 0x300 to content of location 0x302 and
store the result in 0x303
LDS R16,0x300
LDS R17,0X302
ADD R16,R17
STS 0X303,R16
STP:JMP STP
SAMPLE PROGRAMS
Load the value 0x92 into location from 0x200 to 0x203 of the SRAM region
in the data memory.
LDI R20,0X99
STS 0X200,R20
STS 0X201,R20
STS 0X202,R20
STS 0X203,R20
/*
* STA.asm
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X99
0X212,R16
ST R16,0X85
S 0X213,R16
LDI R16,0X3F
0X214,R16
ST R16,0X63
S 0X215,R16
LDI NEXT
ST
S
LDI 402
IN instruction(IN from I/O location
IN
IN Rd,A ;load an I/O location to GPR
0<=d<=31
0<=A<=63
IN instruction tells the CPU to load one byte from an I/O register to GPR.
After the execution,GPR will have the same value as I/O register.
In IN instruction,the I/O registers are referred by their I/O address.($00 to
$3F)
IN Instruction
406
IN R19, 0x10 ; load R19 with location $10
407
IN R1, PIND ; load R1 with PIND
IN R2, PINB ; load R2 with PINB
ADD R1, ;R1=R1+R2
R2 ;Store R1 to $0300
STS 0x300,
R1
408
1. The CPU executes the IN instruction faster than LDS.
The IN lasts 1 machine cycle, where LDS lasts 2
machine cycles.
409
OUT A, Rr ; store register to I/O location
;0≤d≤31
;A is an I/O addr b / w $00 to $3F
;(0≤A≤63)
410
OUT (Out to I/O location)
OUT instruction tells the CPU to store GPR to the I/O register.
412
MOV Rd,
; Rd = Rr (copy Rr to Rd)
Rr ; Rd and Rr can be any of
GPRS
413
MOV
-This instruction is used to copy the data among the GPR register to R0-
R31
MOV Rd,Rr
MOV R10,R20
Eg:-
Add the immediate value 0x19 with the content of memory location
0x220 and the result has to be stored in to 0x225
LDI R20,0x19
LDS R21,0x220
ADD R20,R21
STS 0X225,R20
INC
; increment the content of Rd by one
Rd ; 0≤d≤31
INC R2 ; R2 = R2 + 1
416
DEC
; decrement the content of Rd by one
Rd ; 0≤d≤31
DEC R2 ; R2 = R2 - 1
417
SUB Rd,
; Rd = Rd - Rr
Rr ; Rd and Rr can be any of
GPRS
418
Complements (inverts) the content of Rd
and place the result back into the Rd
register.
419
AVR Status register
• Status register is an 8 bit register also known a
flag register.
• The bits C,Z,N,V,S, and H are called conditional
flag meaning that they indicate some
condition that result after an instruction is
executed.
421
Carry Flag C
• This flag is set whenever there is a carry out
from the D7 bit.
• This flag bit is affected after an 8 bit addition
or subtraction.
ZERO flag Z
• This flag reflect the result of an arithmetic or
logic operation .
• If the result is 0 then Z=1
• If the result is not = 0 then Z=0
Negative flag N
• Binary representation of signed numbers uses
D7 as the sign bit.
• Negative flag reflect the result of an
arithmetic operation .
• If the D7 bit of the result is 0, then N=0 and
the result is positive.
• If the D7 bit of the result is 1, then N=1 and
the result is negative.
Overflow Bit V
• This flag is set whenever the result of an
signed number operation is too large .
• Overflow flag is used to detect errors in signed
arithmetic operation .
Sign Bit S
• Used with BLD (bit load) and BST(bit store)instructions for loading
and storing bit from one register to another.
Global Interrupt Enable
443
Thank
ou
444
What is an Embedded System?
• a microprocessor-based system
• built to control a function or range of functions
• not designed to be programmed by the end user in the
same way that a PC is
• Usually embedded as part of a complete
device including hardware and mechanical parts
System
SOFTWARE PROGRAM
#include <16f876a.h>
#use delay (clock=20000000)
#byte P O RT B = 6
main()
{
set_tris_b(0);
portb=255; //decimal
d e la y _ m s (1 0 0 0 );
portb=0x55; //hexadecimal
d e la y _ m s (1 0 0 0 );
p o rtb = 0 b 1 0 1 0 1 0 1 0 ; //binary
delay_ms(500);
}
Embedded system
• So the designer need not add any additional digital part(to make system
functional) to complete the system and thus the system is economic and
handy.
• The additional external parts always makes the system more expensive
and bulkier.
1)Computing need:-
-Microcontroller should meet the task at hand efficiently and economically.
-this can be analyzed with the following features
• ---Bit size(8 bit, 16 bit, or 32 bit)
----power consumption
----speed
-------Instruction set(RISC or CISC)
-----
Criteria for Choosing a Microcontroller
3.Availability:-
-the next criteria in choosing the microcontroller is its availability in the
required quantity both now and future.
459
You should now be able
to:◦ Compare and contrast microcontrollers and
microprocessors.
◦ List some names of MCs.
◦ Discuss advantages of MCs for Ess
◦ Compare MPs with MCs.
◦ Discuss criteria for considering a MC.
460
By the end of this session, you should be
able to:
461
AVR stand
for?
Advanced Virtual RISC,
the founders are Alf Egil Bogen Vegard
Wollan RISC
462
OVERVIEW OF AVR
MICROCONTROLLER
466
• Many kinds of AVR with different properties
• Except for AVR32 which is 32bit all AVRs are 8
bit meaning that the CPU can work on only 8
bit of data.
• Data larger than 8 bit is broken in to 8 bit
pieces
• Programs written for one family is not 100%
compatible for other family
• AVRs are classified into four
• Mega
• Tiny
• Special purpose
• Classic
• Mega family is widely used as they are
powerful.
• widely available and comes in Dip
packages
The AVR is a modified Harvard architecture
machine where program and data is stored in
separate physical memory systems that
appear in different address spaces, but
having the ability to read data items from
program memory using special instructions.
469
470
The Harvard architecture is a computer
architecture with physically separate
storage and signal pathways for
instructions and data.
471
The term originated from the Harvard
Mark I relay-based computer, which
stored instructions on punched tape (24
bits wide) and data in electro-
mechanical counters.
472
473
474
In contrast with the Harvard architecture, the
von Neumann architecture has a single
storage structure to hold both instructions
and data.
The CPU can be either reading an instruction
or reading/writing data f r om/ t o the
memory because instructions and data use
the same bus system.
475
The phrase Von Neumann architecture
derives name of the mathematician and
early computer scientist John von
Neumann.
476
series of 8 - b i t RISC microcontrollers from Atmel.
477
AVR is a family of 8 - b i t microcontrollers with
a large range of variants differing in:
478
479
480
All of the product numbers start with AT,
which stands for Atmet.
Now, look at the product number, from left to
right, and
find the biggest number that is power of 2.
This number most probably
shows the amount of microcontroller’s ROM.
481
Eg:-
Atmega 1280,the biggest power of 2 is 128.
-so it has 128 Kbytes of ROM.
-ATtiny 44,the amount of memory is 4K.
-ATmega169 ,the amount of ROM is 16K.
Classic AVR (AT90Sxxxx)
Mega AVR (ATmegaxxxx)
Tiny AVR (ATtinyxxxx)
Special purpose AVR
* x x x x is the product
number
484
486
488
490
Special capabilities are:- LCD
controller. USB controller,
Ethernet controller etc
492
AVR with other Microcontrollers
500
Basics About AVR microcontroller.
-AVR microcontroller is an 8 bit , RISC single chip mc with Harvard
architecture that come with some std features
---on-chip ROM
----data RAM
---data EEPROM
---timers and I/O ports.
-it consists of 32,8 bit general purpose working registers.
AVR does not have registers like accumulator .
-so the operation can be performed b/w any of the registers and can be
stored in either of them.
-it follows Harvard architecture format .
-the processor equipped with saparate memories and buses for pgm and
data .
-so prefetching is possible.
-AVR can execute a million instructions per second if cycle frequency is
1MHz.
-higher is the frequency,higher will be the processing speed.
Basic AVR architecture
Oscillator:-
-calibrated with an internal oscillator for driving its clock.
-By default it is set to operate with a frequency of 1 MHz.
-maximum frequency is 8MHz.
-it also set with an external crystal oscillator with a maximum frequency of
16 MHz.
AVR-Basic Architecture
ADC interface:-
-it is equipped with an 8 channel ADC with resolution of 10 bits.
-ADC reads the analog i/p from a sensor or from any other sources and
converts it into digital information which is understandable by the
microcontroller.
AVR-Basic Architecture
Timers/Counters:
It consists of 2 8-bit and 1 16-bit imer/counter.
-timers are useful for creating time delays b/w two operations.
WDT:-
-it is present with internal oscillator.
-WDT continously monitors and reset the controller if the code gets stuck
at any execution action for more than a defined interval.
AVR-Basic Architecture
Interrupt:-
-it consists of 21 interrupt sources out of which 4 are external.
-the remaining are internal which support the peripherals like
USART,ADC,and timers etc.
USART:-
-USART interface is available for interfacing with external device
capable of communicating serially(data transmission bit by bit).
Registers: Two types of registers
◦ GERNEL purpose & SPECIAL purpose registers
GERNERAL purpose(GPRs)
◦ 32 general purpose registers having storage capacity of 8-Bits
◦ Named as R0,R1,R2 to R31 coupled directly with ALU.
◦ Register 0 to 15 & 16 to 31 are different.
◦ Can store both Data & Addresses.
509
There are 32 GPR
All are of size 8 bit
D0 is LSB
D7 is MSB
R0-R31 are located in the lowest
memory location of mem addr.
510
AVR-GPRS
514
LDI R20, 0x25 ; load R20 with 0x25 (R20 = 0x25)
515
LDI R5, 0x25 ; why?
516
ADD Rd, Rr ; ADD Rr to Rd and store
the result in Rd.
517
LDI R16, 0x25 ; load 0x25 into
R16 LDI R17, 0x34 ; load 0x34
into R17 ADD R16, R17
Executing the above lines results R16=0x59.
518
/*
* adding.asm
* Created: 1 2 / 2 / 2 0 1 7 9:35:52
PM
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X25 ; load 0x25 into R16
LDI ; load 0x32 into R17
ADD R17,0X35 ; add value R17 to R16
R16, R17
NEXT: JMP
NEXT
519
520
521
DATA MEMORY
GPRs
◦ GPRs use 32 bytes of data memory space.
◦ They always take the address location $00 - $1F in
the data memory space, regardless of the AVR
chip number.
524
I/O MEMORY(SFRs)
-functions of I/O memory is fixed by the CPU designer at the time of
design.
-it is used for control of the microcontroller or peripheral..
-the AVR I/O memory is made of 8-bit registres.
-it is used for specific functions such as
----status register
----temers
----serial communication
-I/O ports
---ADC
-all the AVR ha at least 64bytes of I/O memory locations
-this 64 byte is called standard I/O memory.
-AVR with more than 32 pins(Atmega64,Atmega128etc),there are an
extended I/O memory .
-extended I/O memory is used for controlling the extra ports and
peripherals.
-I/O memory is called SFRs since each one is dedicated to a specific
function.
527
Internal data
SRAM
◦ Internal data is widely used for storing data and
parameters by AVR programmers and C compilers.
Generally that is called scratch pad.
◦ Each location of SRAM can be accessed by its
address.
◦ Each location is 8 bits wide.
◦ Size of data SRAM can vary form chip to chip
528
SRAM vs EEPROM
• AVR as an EEPROM memory that is used for storing
data.
• EEPROM does not lose it’s data when power id off
where as SRAM lose its data when power is on
• EEPROM is used for storing data that should rarely be
changed whereas the SRAM is used for storing data
and parameters that are changed frequently.
• In AVR data sheet EEPROM refers to EEPROM’s size
and SRAM is the internal SRAM’s size.
530
USING INSTRUCTIONS WITH DATA MEMORY
532
LDS:-
This instruction instruct CPU to copy one byte from a location in the data
memory to one of the GPRs.
534
535
STS K, Rr ; Store Rr into locaton K
; K is an addr b / w $0000 to
$FFFF
536
STS(Store direct To data space)
- this instruction tells the CPU to store the content of the GPR to an
address in the data memory.
Eg:-
STS 0x230,R25 ;store R25 to data space location 0x230
To add the content of location 0x300 to content of location 0x302 and
store the result in 0x303
LDS R16,0x300
LDS R17,0X302
ADD R16,R17
STS 0X303,R16
STP:JMP STP
SAMPLE PROGRAMS
Load the value 0x92 into location from 0x200 to 0x203 of the SRAM region
in the data memory.
LDI R20,0X99
STS 0X200,R20
STS 0X201,R20
STS 0X202,R20
STS 0X203,R20
/*
* STA.asm
*/
.INCLUDE "M32DEF.INC"
.ORG 00
LDI R16,0X99
0X212,R16
ST R16,0X85
S 0X213,R16
LDI R16,0X3F
0X214,R16
ST R16,0X63
S 0X215,R16
LDI NEXT
ST
S
LDI 540
IN instruction(IN from I/O location
IN
IN Rd,A ;load an I/O location to GPR
0<=d<=31
0<=A<=63
IN instruction tells the CPU to load one byte from an I/O register to GPR.
After the execution,GPR will have the same value as I/O register.
In IN instruction,the I/O registers are referred by their I/O address.($00 to
$3F)
IN Instruction
544
IN R19, 0x10 ; load R19 with location $10
545
IN R1, PIND ; load R1 with PIND
IN R2, PINB ; load R2 with PINB
ADD R1, ;R1=R1+R2
R2 ;Store R1 to $0300
STS 0x300,
R1
546
1. The CPU executes the IN instruction faster than LDS.
The IN lasts 1 machine cycle, where LDS lasts 2
machine cycles.
547
OUT A, Rr ; store register to I/O location
;0≤d≤31
;A is an I/O addr b / w $00 to $3F
;(0≤A≤63)
548
OUT (Out to I/O location)
OUT instruction tells the CPU to store GPR to the I/O register.
550
MOV Rd,
; Rd = Rr (copy Rr to Rd)
Rr ; Rd and Rr can be any of
GPRS
551
MOV
-This instruction is used to copy the data among the GPR register to R0-
R31
MOV Rd,Rr
MOV R10,R20
Eg:-
Add the immediate value 0x19 with the content of memory location
0x220 and the result has to be stored in to 0x225
LDI R20,0x19
LDS R21,0x220
ADD R20,R21
STS 0X225,R20
INC
; increment the content of Rd by one
Rd ; 0≤d≤31
INC R2 ; R2 = R2 + 1
554
DEC
; decrement the content of Rd by one
Rd ; 0≤d≤31
DEC R2 ; R2 = R2 - 1
555
SUB Rd,
; Rd = Rd - Rr
Rr ; Rd and Rr can be any of
GPRS
556
Complements (inverts) the content of Rd
and place the result back into the Rd
register.
557
AVR Status register
• Status register is an 8 bit register also known a
flag register.
• The bits C,Z,N,V,S, and H are called conditional
flag meaning that they indicate some
condition that result after an instruction is
executed.
559
Carry Flag C
• This flag is set whenever there is a carry out
from the D7 bit.
• This flag bit is affected after an 8 bit addition
or subtraction.
ZERO flag Z
• This flag reflect the result of an arithmetic or
logic operation .
• If the result is 0 then Z=1
• If the result is not = 0 then Z=0
Negative flag N
• Binary representation of signed numbers uses
D7 as the sign bit.
• Negative flag reflect the result of an
arithmetic operation .
• If the D7 bit of the result is 0, then N=0 and
the result is positive.
• If the D7 bit of the result is 1, then N=1 and
the result is negative.
Overflow Bit V
• This flag is set whenever the result of an
signed number operation is too large .
• Overflow flag is used to detect errors in signed
arithmetic operation .
Sign Bit S
• Used with BLD (bit load) and BST(bit store)instructions for loading
and storing bit from one register to another.
Global Interrupt Enable
581
Thank
ou
582