the avr
microcontroIIer
and embedded
I
system
using assembly and c
M U H A M M A D ALI M A Z l D l 1
SARMAD N A l M l
S E P M R NAlMl
,the avr microcontroIIer
and embedded systems
using assembly gnd c
MUHAMMAD ALI MAZIDI, SARMAD N A I M I , A N D SEPEHR N A l M l
i
:I ..
+-
The AVR microcontroller CHAPTERS
from Atmel is one of the 0: Introduction to Computing
most widely used &bit 1: The AVR Microcontrollet?&iory and
microcontrollers in the
world. In this book the
Features
2: AVR *rch.iecture and Asg
g' & 'Y language
authors use a step-by-step I
and systematic approach to Programming
show the programming of 3: Branch, Call, and Time &lay Loop
the AVR chip. Examples in 4: AVR 110 Port Programming
both Assembly language 5: Arithmetic, Logic Instructions,
and C show how to program and Programs
maw of the AVR features.
such as timers, serial 6: AVR Advanced A%embly Language . .
Programming
communication, ADC, SPI, IZC, and PWM. The text is
wganized into two patts: AVR P r o g r m i n g in C
AVR Hardware Connection, Hex File, and
The fim seven chapters use Assembly language Flash Loaden
proQMming to examine the i n t e d architecture of AVRTimerProgwnminginAsserdyandC
rt# AVR. AVR Interrupt Rognmming in AcssmMy
chrp.n7-18u~bothAswmblyadCt0thowth and C
AVR pmiphab and 1
10interfacing to real-world
d.rriorsuchrLCDs,maton,dmmcm. AVR Serial Port Prognmming in Arsambly
and C
Th.AVR Microcootrdler and E m k d k d Systems is the LCD and Keybod Interfacing
ADC,DAC, and Sensor Interfacing
Relay, ~~ddicdator, and Stepper Motor
lnt+ yith AVR
lt-&C&mndWve~ammtionin~VR
m l E ~ S y s t w PWM Programmiog dDC Motor
Control in AVR
.
(2nd d.1,:;b
~PK:Mbrrconbdo.rndbnbsdd.dsystm SPI Protocol and MAX7221 Display
Th.-12 McmamtdJer and Embsddsd Systems Interfacing
12C Protocol and DS1307 RTC Interfacing
Tabctoconwhducb.
Th.ARM M&mcon* and Embedded Systems
PmItk0H.u
is an imprint of
PEARSON
, THE AVR MICROCONTROLLER
AND EMBEDDED SYSTEMS
Using Assembly and C
Muhammad Ali Mazidi
Sarmad Naimi
Sepehr Naimi
Prentice Hall
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
Amsterdam CapeTown Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
, Editor in Chief: Vernon Anthony Project Manager: Rex Davidson
Acquisitions Editor: Wyatt Morris Senior Operations Supervisor: Pat Tonneman
Editorial Assistant: Chris Reed Operations Specialist: Laura Weaver
Director of Marketing: David Gesell Art Director: Dianne Emsberger
Marketing Manager: Kara Clark Cover Designer: Jeff Vanik
Senior Managing Coordinator: Alicia Cover Art: Antonis Papantoniou, Fotolia.com
Wozniak Printerminder: CourierKendallville
Marketing Assistant: Les Roberts Cover Printer: Demand Production Center
Senior Managing Editor: JoEllen G o h Text Font: Times Roman
Copyright O 201 1 Pearson Education, Inc., publishing as Prentice Hall, 1 Lake Street, Upper Saddle
River, New Jersey, 07458. All rights reserved. Manufactured in the United States of America. This
publication is protected by Copyright, and permission should be obtained from the publisher prior to
any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any
means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use
material from this work, please submit a written request to Pearson Education, Inc., Permissions
Department, 1 Lake Street, Upper Saddle River, New Jersey, 07458.
Library of Congress Cataloging in Publication Data
Mazidi, Muhammad Ali.
The AVR microcontroller and embedded systems: using Assembly and C I
Muhammad Ali Mazidi, Sarmad Naimi, Sepehr Naimi.
p. cm.
ISBN-13: 978-0-13-800331-9 (alk. paper)
ISBN-10: 0-13-800331-9 (alk. paper)
1. Atmel AVR microcontroller. 2. Embedded computer systems. 3. Assembler language
(Computer program language) 4. C (Computer program language) I. Naimi, Sarrnad. 11. Naimi,
Sepehr. 111. Title.
TJ223.P76M378136 2009
004.16--dc22
2009039790
10987654321
Prentice Hall
ISBN 10: 0-13-800331-9
ISBN 13: 978-0-13-800331-9
microcontroIIer
and embedded
I
system
using assembly and c
M U H A M M A D ALI M A Z l D l 1
SARMAD N A l M l
S E P M R NAlMl
,the avr microcontroIIer
and embedded systems
using assembly gnd c
MUHAMMAD ALI MAZIDI, SARMAD N A I M I , A N D SEPEHR N A l M l
i
:I ..
+-
The AVR microcontroller CHAPTERS
from Atmel is one of the 0: Introduction to Computing
most widely used &bit 1: The AVR Microcontrollet?&iory and
microcontrollers in the
world. In this book the
Features
2: AVR *rch.iecture and Asg
g' & 'Y language
authors use a step-by-step I
and systematic approach to Programming
show the programming of 3: Branch, Call, and Time &lay Loop
the AVR chip. Examples in 4: AVR 110 Port Programming
both Assembly language 5: Arithmetic, Logic Instructions,
and C show how to program and Programs
maw of the AVR features.
such as timers, serial 6: AVR Advanced A%embly Language . .
Programming
communication, ADC, SPI, IZC, and PWM. The text is
wganized into two patts: AVR P r o g r m i n g in C
AVR Hardware Connection, Hex File, and
The fim seven chapters use Assembly language Flash Loaden
proQMming to examine the i n t e d architecture of AVRTimerProgwnminginAsserdyandC
rt# AVR. AVR Interrupt Rognmming in AcssmMy
chrp.n7-18u~bothAswmblyadCt0thowth and C
AVR pmiphab and 1
10interfacing to real-world
d.rriorsuchrLCDs,maton,dmmcm. AVR Serial Port Prognmming in Arsambly
and C
Th.AVR Microcootrdler and E m k d k d Systems is the LCD and Keybod Interfacing
ADC,DAC, and Sensor Interfacing
Relay, ~~ddicdator, and Stepper Motor
lnt+ yith AVR
lt-&C&mndWve~ammtionin~VR
m l E ~ S y s t w PWM Programmiog dDC Motor
Control in AVR
.
(2nd d.1,:;b
~PK:Mbrrconbdo.rndbnbsdd.dsystm SPI Protocol and MAX7221 Display
Th.-12 McmamtdJer and Embsddsd Systems Interfacing
12C Protocol and DS1307 RTC Interfacing
Tabctoconwhducb.
Th.ARM M&mcon* and Embedded Systems
PmItk0H.u
is an imprint of
PEARSON
, THE AVR MICROCONTROLLER
AND EMBEDDED SYSTEMS
Using Assembly and C
Muhammad Ali Mazidi
Sarmad Naimi
Sepehr Naimi
Prentice Hall
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
Amsterdam CapeTown Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
, Editor in Chief: Vernon Anthony Project Manager: Rex Davidson
Acquisitions Editor: Wyatt Morris Senior Operations Supervisor: Pat Tonneman
Editorial Assistant: Chris Reed Operations Specialist: Laura Weaver
Director of Marketing: David Gesell Art Director: Dianne Emsberger
Marketing Manager: Kara Clark Cover Designer: Jeff Vanik
Senior Managing Coordinator: Alicia Cover Art: Antonis Papantoniou, Fotolia.com
Wozniak Printerminder: CourierKendallville
Marketing Assistant: Les Roberts Cover Printer: Demand Production Center
Senior Managing Editor: JoEllen G o h Text Font: Times Roman
Copyright O 201 1 Pearson Education, Inc., publishing as Prentice Hall, 1 Lake Street, Upper Saddle
River, New Jersey, 07458. All rights reserved. Manufactured in the United States of America. This
publication is protected by Copyright, and permission should be obtained from the publisher prior to
any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any
means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use
material from this work, please submit a written request to Pearson Education, Inc., Permissions
Department, 1 Lake Street, Upper Saddle River, New Jersey, 07458.
Library of Congress Cataloging in Publication Data
Mazidi, Muhammad Ali.
The AVR microcontroller and embedded systems: using Assembly and C I
Muhammad Ali Mazidi, Sarmad Naimi, Sepehr Naimi.
p. cm.
ISBN-13: 978-0-13-800331-9 (alk. paper)
ISBN-10: 0-13-800331-9 (alk. paper)
1. Atmel AVR microcontroller. 2. Embedded computer systems. 3. Assembler language
(Computer program language) 4. C (Computer program language) I. Naimi, Sarrnad. 11. Naimi,
Sepehr. 111. Title.
TJ223.P76M378136 2009
004.16--dc22
2009039790
10987654321
Prentice Hall
ISBN 10: 0-13-800331-9
ISBN 13: 978-0-13-800331-9