0 ratings0% found this document useful (0 votes) 723 views328 pagesMicro Controller Systems Engineering.o
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
a
45 projects for PIC, AVR and ARM
Bert van Dam
r= lektorMicrocontroller Systems Engineering
Thus book ls about estate oF the art tool, HOWeads, and how youcan use Howdade to.
Hevelop microcontroller applicators. The book starts very simply wii 4 tutsrial proeet
and step-by-step instructions. As you go along the projects increase ini difficulty and the
new concepts are explained Each project has a clea’ des=riptiar) of buth hardware and
software with pictures a’id diagrams, which exp/ain not lust hiaw things are done but als
whiy All sources are available for free down oad
Since Flowcod> is aig level language the intricacies of microcontroller programming are
hidden from view For that reason it doesnt make much dliflererice whether the program
1s tant for a PIC. AVR or ARM/nicrocortroller, On a high level the programs for these
inicrocontiollers, although vastly dfferepit(h internal stYucture, are identical For that
reasol th's bool |s on microcontroller appillcation design ingeneral not ust for one type
of microcortraller If you dont own the microcontroller described in a project you can
Usually convert [t to aniether micracontialler quite easily.
Exblocks will be used as hardware for the projects in thus book. This way the hardware
cary be pur torether quickly and reliably. Fully tested units simply connect together using
Eonnectors oF short Flat riblom Cables to form completed proiects.
This book Covers 45 exciting and fun project: for beginiie’s and experts such a
mer persistence of vision
ret doorbell sound activated switch
| phone remote contol CAN bus
ith deterrent Intemet webserver
tracking and much more
e witith modislated motor corrtrol
You Ean use It as a projects baok, atid build the projects for your own llsé Or you cai ue
it aga stiidy guide to learn) more about microcattrolier syste'Ns engineering atid the PIC,
AVR and ARM microcontrollers.
Pc hase antaea
} Dea eed
'9°780905) 705750 annetteMicrocontroller Systems Engineering
45 projects for PIC, AVR and ARM
Bert van Dam
Elektor International Media BV
Postbus 11
6114 ZG Susteren
The NetherlandsAll rights reserved. No part of this book may be reproduced in any material form,
including photocopying, or storing in any medium by electronic means and whether or
not transiently or incidentally to some other use of this publication, without the written
permission of the copyright holder except in accordance with the provisions of the
Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the
Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London, England W1P
HE. Applications for the copyright holder’s written permission to reproduce any part of
this publication should be addressed to the publishers.
The publishers have used their best efforts in ensuring the correctness of the information
contained in this book, They do not assume, and hereby disclaim, any liability to any
party for any loss or damage caused by errors or omissions in this book, whether such
errors or omissions result from negligence, accident or any other cause.
British Library Cataloguing in Publication Data
A catalogue record for this book is available from the British Library
ISBN 978-0-905708-75-0
Prepress production: Autronic, Blaricum
First published in the United Kingdom 2008
Printed in the Netherlands by Wilco, Amersfoort
© Elektor International Media BV 2008
039023/U0KContent
Prologue
1 What you will need
2 Tutorial
2.1 Concept
2.2 Hardware
23 Software
24 Simulation
2.5 Downloading
2.6 Operational
3 Basic
3.1 LCD display
3.2 Running light
33 Secret doorbell
34 Serial communication
34.1 RS232
3.4.2 USB
35 Analog to Digital Conversion
3.6 Dark activated switch
37 Youth deterrent
3.8 Sound activated switch
39 Air to fuel ratio
3.10 Digital clock
3.11 Debugging
3.11.1 Simulation
3.11.2 Serial connection
3.12 Bootloader
4 Advanced.
41 Vref+
42 Record short sounds
43 Cricket
43.1 High quality version
43.2 Low cost version
44 ‘Custom Characters
45 Animation
17
7
17
22
29
31
32
33
33
39
45
5
31
58
62
66
70
7
80
87
91
93
94
100
100
105
VW
li
116
119
12346
47
48
49
4.10
4.11
4.12
4.13
4.14
5.1
5.2
5.3
54
5.5
5.6
5.7
5.8
6.1
6.2
63
10.1
10.2
10.3
Random
A fan on PWM
Persistence of vision
Flash memory
USART connection
GPS tracking
Use PPP to access EEPROM
Poetry box
Voice command
Sensors
Infrared object detection
Photometer
Ultrasonic range finder
Digital thermometer
Data sampling the fridge
Heat loss in a residential building
Capture sound frequency
Tow away alarm
Cell phone
Send a text message
Receive a text message
Remote control
CAN bus
Remote LEDs
Monitor
Internet
Ping (Are you there?)
Webserver
Send an alarm e-mail
UDP remote control
Design your own E-block
Analog test signal
Microphone pre-amplifier
Migration between PIC, AVR and ARM
Software
Hardware
Example
124
128
135
139
144
149
155
159
163
169
169
172
178
184
189
197
202
212
217
217
221
225
232
232
240
248
248
258
265
276
282
282
284
288
288
289
293lL
111
12
12.1
12.2
12.3
12.4
12.5
Going into production
Youth deterrent (continued)
‘Appendix
ASCII table
Visual Basic communications
Tips and tricks
Microcontroller Mathematics
E-block connections
Index
296
296
302
302
303
305
314
320
327Prologue
Prologue
You have to do what others won't,
to achieve what others don't.
(Anonymous)
When I was young my dad taught me how to program a large mainframe computer. First
you need to think through what you want the program to do. Then draw a flowchart,
which is a graphical representation of the program flow. It consists of symbols connected
by lines with arrows. The program will flow from symbol to symbol following the
arrows. Each symbol of the flowchart has a specific meaning. The rectangle for example
is an operation, the diamond is a decision, the circle a connector to a different part of the
program.
Figure 1. Flowchart template.
Flowcharting is an ideal way to develop a program, because it allows anyone, not just
programmers, to understand what the program will do. Once everyone involved is
satisfied that this is indeed the program they want, the flowchart must be transformed into
lines of code. Then each line is copied onto a cardboard card with a kind of typewriter
that punches holes in the card. The stack of cards is fed into a punchcardreader because
that was the only way to get the program into the computer. The computer itself was in a
different room, in fact it filled an entire room, and controlled by people in white lab coats.
No one was allowed to get near it, let alone touch it. The results of the program would be
printed on large sheets of tractorfed paper. And often there would only be one sheet with
one line, such as: Error in line 2816, execution aborted.
We have come a long way. State of the art tools allow you to draw a flowchart directly on
your computer screen, and enter in each symbol details of what you want the program to
do at that location. With a press on a button the program is simulated allowing for very
easy debugging. And with another button the whole program is compiled and downloaded
jnto a microcontroller, a computer the size of a fingernail. You can get a program up and
running in a matter of minutes,Prologue
290 G20:
lo
lar
le
lo
lo
ES
Ie
ey
ob
a
leo
HHMI OTONSOR xs
Figure 2. Flowcode state of the ort software design.
This book is about such a state of the art tool, Flowcode®, and how you can use Flowcode
to develop microcontroller applications. The book starts very simply with a tutorial
Project and step-by-step instructions. As you go along the projects increase in difficulty
and only the new concepts are explained. Each project has a clear description of both
hardware and software with pictures and diagrams, which explain not just how things are
done but also why. All sources are available for free download, including the support
software'.
E-blocks® will be used as hardware for the projects in this book. This way hardware can
be put together quickly and reliably. Fully tested units simply connect together using
connectors or short flat ribbon cables to form completed projects. No soldering is
required.
Since Flowcode is a high level language the intricacies of microcontroller programming
are hidden from view. For that reason it doesn't make much difference whether the
program is meant for a PIC, AVR or ARM microcontroller. On a high level the programs
for these microcontrollers, although vastly different in internal structure, are identical. For
that reason this book is on microcontroller systems engineering in general, not just for
one type of microcontroller. If you don't own the microcontroller described in a project
you can usually convert it to another microcontroller quite easily, as explained in chapter
10.
' Flowcode is not included and must be purchased separately.
10