ESunit 1
ESunit 1
Unit 1
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 – Basic concept
Addres
s
Control
Boot
CPU Instruction
Data Input/ External
ROM (program)
RAM Output Comm.
Used at ROM
startup
Data
Dat
a
• Microprocessor: • Microcontroller:
System
SOFTWARE PROGRAM
#include <16f876a.h>
#use delay (clock=20000000)
#byte P ORT 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 ) ;
portb=0b10101010; //binary
delay_ms(500);
}
Characteristics of Embedded Systems
• Other considerations
– Code density: affects power consumption, performance and system cost
– Hardware availability: make sure you can actually
purchase the microcontroller before designing it in
– Prior expertise, licensing, etc
• 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
AVR Features
Program ROM
• ROM is used to store program and is called
program ROM or code ROM
• Program ROM size 1k to 256k
• AVR was one of first microcontrollers to use
on-chip Flash memory for program storage
• For fast development flash memory is ideal
as it can erase the data within seconds
Data RAM and EEPROM
• RAM space is for data storage
• AVR has maximum of 64k of data RAM space
• RAM space has three components
1. General purpose registers
2. I/O memory
3. Internal SRAM- used for a read/write
scratch pad
• 32 General purpose registers but the SRAM
size and the I/O memory size varies from chip
to chip
• It contains a small amount of EEPROM to store
critical data that does not need to be changed
very often
I/O pins
• 3 to 86 pins for I/O
• Number of I/O depends on the number of pins
in the package
Peripheral
s
• AVR comes with
1. ADC
2. Timers
3. USART
Special capabilities are:- LCD
controller. USB controller,
Ethernet controller etc
AVR with other Microcontrollers
• AVR have many registers for arithmetic and
logic operation
• CPU uses many registers to store data
temporarily
• That information can be byte of data to be
processed or address pointing to the data to
be fetched
• AVR registers are 8 bit registers
8 bit register ranging form MSB to LSB
• With an 8 bit data type , any data
larger than 8 bits must be
broken into 8 bit chunks before
it is processed.
• In AVR there are 32 general purpose registers
• They are R0-R31and are located in the lowest
location of memory address
• GPRs in AVR are the same as accumulator in
other microprocessor
• GPRs are used by all arithmetic and logic
instruction
• To understand the use of GPRs we can see two
instruction
1. LDI Rd, k; load Rd (destination)
with immediate value K
• D must be between 16 and 31
• K is an 8-bit value that can be 0-255
in decimal
• I stands for immediate value
• LDI R31,0X25
R31=0X25
• We cannot load values into registers
R0- R15using the LDI instruction
ADD instruction
2. ADD Rd, Rr ;add Rr to Rd and store the
result in Rd
• LDI R16, 0X25 ;load 0x25 into R16
• LDI R17,0x34 ; load 0x34 into R17
• ADD R16,R17;add the values in R16 and R17
AVR data memory
• In AVR there are two kinds of memory
• Code memory space and data memory space
• Data memory space is composed of three
parts
➢ GPRs
➢I/O memory
➢internal data SRAM
GPRs
• GPRs use 32 byte of data memory space
• They always take the address location $00-$1F
I/O memory (SFRs)
• The I/O memory is dedicated to specific
function such as status register, timers,serial
communication, I/O ports. ADC, and so on
• The function of each I/O memory location is
fixed by the CPU designer at the time of
design because it is used for control of the
microcontroller or peripherals
• The AVR I/O memory is made of 8-bit registers
• The number of location in the data memory
for I/O depends on the pin numbers and
peripheral functions supported by that chip
• All AVRs have 64 bytes of I/O memory
location
• This 64 byte section is called standard I/O
memory
• In AVR with more than 32 I/O pins there is
also an extended I/O memory which
contains registers for controlling extra ports
and extra peripherals
• In other microcontrollers I/O registers are
called Special Function Registers (SFR)
Internal data SRAM
• Internal data SRAM is widely used for storing
data parameters by AVR programmers and
compilers
• Generally it is called scratch pad
• Each location of SRAM can be accessed by its
address
• Each location is 8 bit wide and can be used to
store any data .
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.
AVR Status register
• Status register is an 8 bit register also
known a flag register.
-status register indicate the arithmetic
condetion or the current status of the
processor.
-the I/O address of the status register is
$3F(memery address $5F).
• All the bits are cleared to logic 0 at reset and
can be read from or written to by the program.
• 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.
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.
• The negative(N) and V flags are used for the
signed number arithmetic operations.
Overflow Bit v
• This flag is set whenever the result of an
signed number operation is too large.
• The higher-order bit is overflow into the
sign bit.
• The carry fag is used to detect errors in
unsigned arithmetic operations .
• While overflow fag is used to detect
errors in signed arithmetic operations.
Sign Bit s