Exploring C for Microcontrollers: Hands-on Project and Applications

Verified

Added on  2021/06/14

|25
|8365
|168
Project
AI Summary
This document presents a comprehensive exploration of C programming for microcontrollers, offering a hands-on approach to embedded systems development. It begins with an introduction to microcontrollers, their applications, and architectural trends. The project then delves into the Integrated Development Environment (IDE), specifically the Keil IDE, providing a step-by-step guide to the development process. The core of the document focuses on C programming for microcontrollers, differentiating it from ANSI C and highlighting memory and time constraints. It explores on-chip resources, including I/O ports, interrupts, and timers, with practical examples like LED interfacing and DIP switch interfacing. Furthermore, it covers Hyperterminal-based control schemes and various microcontroller applications such as podium timers, front desk notifiers, and energy-efficient lighting. The document also touches on measurement and control applications, including reading PWM waveforms and I2C interfaces. Finally, it discusses security challenges and potential solutions in embedded systems. This project aims to equip readers with the necessary knowledge and practical skills for designing and implementing microcontroller-based embedded systems.
Document Page
Copyright © 2007. Springer Netherlands. All rights reserved.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
EXPLORING C FOR MICROCONTROLLERS
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
Exploring C for Microcontrollers
A Hands on Approach
Goa University
India
VINOD G. SHELAKE
Kolhapur, India
RAJANISH K. KAMAT
Shivaji University
Kolhapur, India
Goa University
India
JIVAN S. PARAB
and
Shivaji University
GOURISH M. NAIK
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
A C.I.P. Catalogue record for this book is available from the Library of Congress.
Published by Springer,
P.O. Box 17, 3300 AA Dordrecht, The Netherlands.
www.springer.com
Printed on acid-free paper
All Rights Reserved
No part of this work may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means, electronic, mechanical, photocopying, microfilming, recording
or otherwise, without written permission from the Publisher, with the exception
of any material supplied specifically for the purpose of being entered
and executed on a computer system, for exclusive use by the purchaser of the work.
© 2007 Springer
ISBN 978-1-4020-6066-3 (HB)
ISBN 978-1-4020-6067-0 (e-book)
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Contents
Foreword ix
Preface xiii
Acknowledgments xvii
1
Microcontrollers: Yesterday, Today, and Tomorrow 1
1.1 Defining Microcontrollers 1
1.2 Eagle’s View: Microcontrollers and Other Competing Devices2
1.3 Vignettes: Microcontrollers 3
1.4 Microcontroller Applications 5
1.5 Growth Economics 7
1.6 The Major Players in the Microcontroller Chip Market 8
1.7 Architectural Trends 10
1.8 Jump Starting Your First Embedded System Project 14
1.9 Execution of Embedded System Project: Is it a
Gordian’s Knot? 16
2
Integrated Development Environment 19
2.1 Getting Familiar with the IDE 19
2.2 Working with Keil IDE 20
2.3 Development Flow for the Keil IDE 21
3
Art of C Programming for Microcontrollers 29
3.1 Familiarizing with Your Compiler Capabilities 29
3.2 Whether to Use Headers or Not? 30
3.3 Basic C Program Structure 34
3.4 Differences from ANSI C 34
v
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
vi Contents
4
Exploring the Capabilities of On-Chip Resources Programming
for I/O Ports, Interrupts and Timer/Counter
37
4.1 Importance of Ports 37
4.2 Simple Ideas for Port Expansion 46
4.3 LED Interfacing 46
4.4 Relevance of LEDs in Today’s Lightening Industry 48
4.5 Different Programs for LED Interfacing 48
4.6 More Projects on LED Interfacing to Microcontrollers 51
4.6.1 Running LEDs 51
4.6.2 Running Bicolor LED 51
4.6.3 Interfacing 6 LEDs
Using 3 Microcontroller Pins by 51
4.6.4 The LED Dimmer Demoboard 51
4.6.5 Fading RGB LED 52
4.6.6 LED Moving Font 52
4.7 DIP Switch Interfacing: Getting Input to Your
Embedded System 52
4.8 LCD Interfacing 54
4.9 Interrupts in Microcontrollers 57
4.9.1 Writing ISRs in C 58
4.9.2 A Word about Interrupt Latency 63
5
Hyperterminal-Based Control 69
5.1 Hyperterminal 69
5.2 Packet-based Control Scheme 69
5.3 Mechanism and Lots of Possibilities 70
5.4 Application 1: Packet-based Interface for LEDs 71
5.5 Application 2: Packet-based Interface for Stepper
Motor Control 74
5.6 Application 3: Home Automation from PC HyperTerminal 78
6
Embedding Microcontroller in Routine Applications 85
6.1 Application 1: Podium Timer 85
6.2 Application 2: Front Desk Notifier 90
6.3 Application 3: Cafeteria Food Alert/Microcontroller-based
Menu Card 94
6.4 Application 4: Chimney Sentinel 100
6.5 Application 5: Who’s First Timer 104
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
Contents vii
6.6 Application 6: Counting Cars 110
6.7 Application 7: Anonymous Voting 114
6.8 Energy Efficient Lighting Using Microcontroller 119
7
Microcontroller-based Measurement and Control Applications 123
7.1 Application 1: Reading a PWM Waveform Using
Microcontroller 123
7.2 Single Set-point On/Off Controller 127
7.3 Application 3:I2C Interface with Serial EPROM 133
8
Securing Your Embedded System Application 139
8.1 Security Challenges in Embedded Systems 139
8.2 Application 1: Authentication for Your Embedded
System Application 140
8.3 Application 2: Timeout Waiting for Input Data 144
References 151
Index 155
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Foreword
If we accept the premise that an embedded engineer is made rather
than born, then how does one go about making a good one? The autho
of this book Exploring C for Microcontrollers: A Hands-on Approach are
certainly “good ones”. Not only do they explore some of the influences
that shaped themselves but they also try to shape “would-be” embedd
engineers.Research and developmentalactivities in embedded systems
has grown in a significant proportion in the recent past. Embedded soft
ware design is not new to the world,but with the changing time,it
has gained considerable momentum in the recent past, and many youn
engineers are strongly inclined to pursue their future in this field.The
book is mainly targeted to these engineers who would like to understan
in great depth the synergetic combination of hardware and software.
The book is divided into eight chapters. Chapter 1 introduces a brief
background about micro-controllers and explains how they are embed-
ded into products commercially available in the market to emphasize th
importance of these in the daily life of mankind. It also gives an insight
into the architecturaldetails and embedded system concepts for stu-
dents’ projects to motivate them into this exciting field. The rest of the
book concentrates on software development. The integrated developm
environment (IDE) is introduced in Chapter 2.Again the screen shots
and step-by-step procedure willcertainly make the students and engi-
neers fully understand the development process.Chapter 3 differenti-
ates the embedded C paradigm from the conventionalANSI C. Again
the authors explain how to successfully overcome the memory and tim
constraints while developing an embedded C program.Chapter 4 gives
an overview ofprogram development for on-chip resources for MCS51
family of microcontrollers. Chapters 5–8 are devoted to live case studie
The book has come outwith an elegantpresentation to aspiring
studentsand engineersfrom the teaching experienceand technical
knowledge the authors have put over a long time in this field. I strongly
recommend this book for intermediate programmers, electronics, electr
cal, instrumentation engineers or any individual who is strongly inclined
ix
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
x Foreword
to take up his or her career in embedded C programming. I am sure the
reader will experience learning embedded programming by example an
learning by doing.Last but not the least,this book willcertainly be a
value addition to the world of embedded programming.
Dr. A. Senthil Kumar
Head
Data Quality Evaluation
National Remote Sensing Agency
Department of Space
Government of India
Dr. SenthilKumar is Head of DQE and PQCD sections of National
Remote Sensing Agency (NRSA)an autonomousoperationalcenter
under Department ofSpace (DOS),Government ofIndia. This is the
nodalagency in the country for receiving,processing,and distributing
the satellite and aerial remote sensing data and products. NRSA is also
responsible forproviding end-to-end solutionsfor utilization ofdata
for geospatialapplications and information services.NRSA has a huge
archive ofremote sensing data acquired through Indian and foreign
satellites and also has the capability to acquire data pertaining to any
part of the globe on demand.It is one of the important centers for
promotion ofremote sensing and geographic information system tech-
nologies in India.NRSA has set up satellite data processing facilities
starting from data reception to utilization atvariouscenterswithin
India and across the globe.
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
Preface
The past few decades have witnessed evolution ofmicrocontrollers.
They have revitalized a number of products or equipment in almost all
fields including telecommunications,medical,industrial,and consumer
products.These embedded microcontroller systems now resides at the
heart ofmodern life with a variety ofapplications in fields like con-
sumer electronics, automotive systems, domestic, and even in aerospa
products.Embedding a microcontroller in an electronics instrument or
product requires a specialized design skillwhich requires a synergy of
hardware and software skills.
In our day-to-day life we come across a number of embedded produc
When we switch on the washing machine or send an SMS on a cell phon
one cannot prevent without thinking the mechanism and the co-workin
of hardware and software in the background. The market for such smar
embedded products is occupying newer and newer applications seem-
ingly impossible few years back.Last year the IDC,a premier global
market intelligence firm,revealed that the embedded industry product
development was expected to be as high as $75 billion. This entails the
industry requirement oftrained human resource with mixed skillset
both in hardware and software.Unfortunately the synergetic demand
of hardware and software or sometimes even referred to as firmware
competency has led to a supply–demand gap ofHR in this field.This
gap expressed in numerical figures led to requirement of around 150,00
embedded engineers to serve the globalembedded industry.This book
is ideal for all those who would like to pursue their career in the exciting
world of microcontroller-based embedded systems. The approach is ped
agogical; first the hardware module is presented and then the associate
software code in Keil C.
The hardware designed is useful for engineering graduates and prac-
ticing professionals with the required knowledge and practical hands on
skills to design with embedded systems.However,the prerequisite for
the book is background of theoreticalaspects of architecture of micro-
controllers especially the MCS-51 family.The book starts with initial
xi
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
xii Preface
experiments, which provide familiarization with the capabilities and the
limitations of the basic 8051 microcontroller using a simulator. Once th
reader is comfortable with these primitive programs which covers almo
all the on-chip resources, he or she can switch to more advanced ones.
The Scope of the Book
We now review the topics covered in sequence, chapter by chapter.
Chapter 1 provides an overview ofmicrocontrollers and their appli-
cations in different domains.The architecturaltrends and the growth
economics emphasizes the importance of the subject. The photograph
the setup and the hints toward project execution will definitely boost th
confidence of the novice to kick-start the project with minimal resource
Chapter 2 is devoted to the IDE for the MCS-51 family. The simulation
and single stepping as described in this chapter will solve all the projec
intricacies ofthe readers.Chapter 3 illustrates the basic difference in
traditionalC programming and embedded C.Chapter 4 deals with the
programming ofon-chip resources ofMCS-51 family microcontrollers
in C. The theoreticaldetails ofthese on-chip resources such as ports,
timers,etc.,are completely eliminated.As the book aims at hands-on
approach,the programs for the on-chip resources have been developed
and their execution is illustrated in the Keil simulation environment.
The last four chapters,i.e.,5–8 dealwith various project case stud-
ies. Several case studies in various application domains such as lighting
measurement and control, security, and domestic applications are deve
oped from scratch. The hardware and software developed in the form o
case studies also caters to a set of mini projects, which are discussed in
detailfrom the design phase to the actualimplementation on a target
system. There are 17 case studies given in this book on various system
that you may encounter in day-to-day life.Overallthe hardware and
software developed in this book can be reused for any embedded sys-
tem project and is expected to act as a rapid prototyping unit for the
embedded systems industry.
Reasons for Proposing this Book
The market is flooded with a number of good books on embedded sy
tems designed especially with the most popular MCS-51 family.These
books are traditionalin nature,i.e., they start with the routine archi-
tectural features of 8051, description of registers, ports, interrupts, etc.
Most of these are already covered in the device data sheet and appli-
cation notes. In the present book all such routine features are skipped.
The focus is on programming microcontrollers to be specific MCS-51
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
Document Page
Preface xiii
family in ‘C’ using Keil IDE. The book presents 20 live case studies
apart from the many basic programs organized around every on-chip
resource like port, time/counter, interrupt, serial I/O, etc. Rather than
introducing the underpinning theory or reproducing lengthy data sheet
our approach is “learning-through-doing” and one that appeals to busy
electronics designers. The ‘C’ codes given are well supported by easy-t
understand comments wherever required.Mastering the basic modules
and hands-on working with the projects will enable the reader to grasp
the basic building blocks for most 8051 programs.Whether you are a
student using the MCS-51 family ofmicrocontrollers for your project
work or an embedded systems programmer,this book willgive you a
kick start in using and understanding the most popular microcontroller.
Authors through their interaction with the undergraduate and post-
graduate students as well as industry professionals have found that suc
a book is the need ofthe microcontroller community interested in C
programming. The book will bridge the gap between the microcontrolle
hardware experts and the C programmers.
Major Features
The objective of this book is to introduce the readers to the design
and implementation of an embedded system. It covers the unique requ
ments and limitations of operating in an embedded environment. It also
covers microcontrollers as the most widespread example ofembedded
systems.In particular,it focuses on the MCS-51 family ofmicrocon-
trollers, their programming in C language, and interfacing techniques.
Specialemphasis is to provide hands-on experience for the readers
using a hardware and interfacing modules described in this book.The
aim is to empower the reader to actually solve his or her problem with
a practical hands-on pedagogy through the hardware and software pre-
sented in this book. The principle of “Design Reuse” is explained effec-
tively.
Further, the readers will also learn how to follow the sequence of data
flow through the microcontroller when a program is executed.Addi-
tionally,the readers willlearn the operation ofthe microcontroller’s
I/O functions and the externaldevices driven by the microcontroller.
Hardware and software design issues are discussed for specific systems
implemented using MCS-51 as the embedded microcontroller.
Kamat, Rajanish K., et al. Exploring C for Microcontrollers : A Hands on Approach, Springer Netherlands, 2007. ProQuest Ebook
Central, http://ebookcentral.proquest.com/lib/sheffield/detail.action?docID=371803.
Created from sheffield on 2021-05-28 14:43:20.
Copyright © 2007. Springer Netherlands. All rights reserved.
chevron_up_icon
1 out of 25
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]