Interfacing.with.C.plus.plus-programing_communication_with_microcontrolers(1).pdf

(3106 KB) Pobierz
648873142 UNPDF
Interfacing with C++
Jayantha Katupitiya Kim Bentley
Interfacing with C++
Programming Real-World Applications
ABC
Dr. Jayantha Katupitiya
Senior Lecturer
School of Mechanical and
Manufacturing Engineering
The University of New South Wales
Sydney NSW 2052, Australia
Email: J.Katupitiya@unsw.edu.au
Mr. Kim Bentley
Library of Congress Control Number: 2005937895
ISBN-10 3-540-25378-5 Springer Berlin Heidelberg New York
ISBN-13 978-3-540-25378-5 Springer Berlin Heidelberg New York
This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on mi-
crofilm or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted
only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission
for use must always be obtained from Springer. Violations are liable for prosecution under the German Copyright
Law.
Springer is a part of Springer Science+Business Media
springer.com
c
Springer-Verlag Berlin Heidelberg 2006
Printed in The Netherlands
The use of general descriptive names, registered names, trademarks, etc. in this publication does not imply, even in
the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and
therefore free for general use.
Typesetting: by the authors and TechBooks using a Springer L A T E X macro package
Cover design: design & production GmbH, Heidelberg
Printed on acid-free paper SPIN: 11015543 89/TechBooks 543210
Table of Contents
1 GETTING STARTED .................................................................................... 1
1.1 I NTRODUCTION ................................................................................................ 2
1.2 P ROGRAM D EVELOPMENT S OFTWARE ............................................................ 2
1.3 A C++ P ROGRAM ............................................................................................ 6
1.4 U SE OF F UNCTIONS ....................................................................................... 10
1.5 F UNDAMENTAL D ATA T YPES ........................................................................ 15
1.6 F UNCTIONS WITH P ARAMETERS AND R ETURN V ALUES ............................... 18
1.7 S UMMARY ..................................................................................................... 21
1.8 B IBLIOGRAPHY .............................................................................................. 22
2 PARALLEL PORT BASICS AND INTERFACING ................................ 23
2.1 I NTRODUCTION .............................................................................................. 24
2.2 W HAT IS THE P ARALLEL P ORT ? .................................................................... 24
2.3 D ATA R EPRESENTATION ............................................................................... 30
2.4 P ROGRAM D EMONSTRATING H EXADECIMAL TO D ECIMAL ..................... 32
2.5 S UMMARY ..................................................................................................... 33
2.6 B IBLIOGRAPHY .............................................................................................. 33
3 TESTING THE PARALLEL PORT........................................................... 35
3.1 I NTRODUCTION .............................................................................................. 36
3.2 I NTERFACE B OARD P OWER S UPPLY .............................................................. 36
3.3 P ARALLEL P ORT I NTERFACE ......................................................................... 39
3.4 B ASIC O UTPUT U SING THE P ARALLEL P ORT ................................................ 43
3.5 B ASIC I NPUT U SING THE P ARALLEL P ORT .................................................... 46
3.6 C OMPENSATING FOR I NTERNAL I NVERSIONS ................................................ 50
3.7 S UMMARY ..................................................................................................... 55
3.8 B IBLIOGRAPHY .............................................................................................. 56
4 THE OBJECT-ORIENTED APPROACH ................................................. 57
4.1 I NTRODUCTION .............................................................................................. 58
4.2 C ONCEPTUAL AND P HYSICALLY R EALISABLE O BJECTS ............................... 58
4.3 R EAL O BJECTS .............................................................................................. 59
4.4 O BJECT C LASSES ........................................................................................... 61
4.5 E NCAPSULATION ........................................................................................... 63
4.6 A BSTRACT C LASSES ...................................................................................... 64
4.7 C LASS H IERARCHIES ..................................................................................... 64
4.8 I NHERITANCE ................................................................................................ 65
4.9 M ULTIPLE I NHERITANCE ............................................................................... 66
4.10 P OLYMORPHISM .......................................................................................... 66
4.11 A N E XAMPLE O BJECT H IERARCHY ............................................................. 67
4.12 A DVANTAGES OF O BJECT -O RIENTED P ROGRAMMING ............................... 72
4.13 D ISADVANTAGES OF O BJECT -O RIENTED P ROGRAMMING .......................... 72
4.14 S UMMARY ................................................................................................... 73
VI TABLE OF CONTENTS
4.15 B IBLIOGRAPHY ............................................................................................ 73
5 OBJECT-ORIENTED PROGRAMMING................................................. 75
5.1 I NTRODUCTION .............................................................................................. 76
5.2 N AMING C ONVENTION .................................................................................. 76
5.3 D EVELOPING AN O BJECT C LASS ................................................................... 77
5.4 P ARALLEL P ORT C LASS – S TAGE I................................................................ 82
5.5 U SING C LASS O BJECTS IN P ROGRAMS .......................................................... 87
5.6 P ARALLEL P ORT C LASS – S TAGE II .............................................................. 94
5.7 P ARALLEL P ORT C LASS – S TAGE III ............................................................. 99
5.8 S UMMARY ................................................................................................... 103
5.9 B IBLIOGRAPHY ............................................................................................ 103
6 DIGITAL-TO-ANALOG CONVERSION ............................................... 105
6.1 I NTRODUCTION ............................................................................................ 106
6.2 D IGITAL - TO -A NALOG C ONVERSION ........................................................... 106
6.3 P ROGRAMMING THE D IGITAL - TO -A NALOG C ONVERTER ........................... 117
6.4 D ERIVATION OF O BJECT C LASSES .............................................................. 121
6.5 A DDING M EMBERS TO D ERIVED C LASSES .................................................. 129
6.6 S UMMARY ................................................................................................... 145
6.7 B IBLIOGRAPHY ............................................................................................ 146
7 DRIVING LEDS ......................................................................................... 147
7.1 I NTRODUCTION ............................................................................................ 148
7.2 I TERATIVE L OOPS ........................................................................................ 148
7.3 B RANCHING ................................................................................................. 152
7.4 A RRAYS ....................................................................................................... 157
7.5 P OINTERS ..................................................................................................... 160
7.6 U SING P OINTERS ......................................................................................... 175
7.7 M ACROS ...................................................................................................... 184
7.8 D YNAMIC M EMORY A LLOCATION .............................................................. 185
7.9 E XCEPTION H ANDLING ............................................................................... 189
7.10 S UMMARY ................................................................................................. 194
7.11 B IBLIOGRAPHY .......................................................................................... 195
8 DRIVING MOTORS - DC & STEPPER.................................................. 197
8.1 I NTRODUCTION ............................................................................................ 198
8.2 DC M OTORS ................................................................................................ 198
8.3 S TEPPER M OTORS ....................................................................................... 202
8.4 A C LASS H IERARCHY FOR M OTORS ........................................................... 211
8.5 V IRTUAL F UNCTIONS – A N I NTRODUCTION ............................................... 212
8.6 V IRTUAL F UNCTIONS - A PPLICATION ......................................................... 233
8.7 K EYBOARD C ONTROLS ............................................................................... 256
8.8 S UMMARY ................................................................................................... 270
8.9 B IBLIOGRAPHY ............................................................................................ 271
 
Zgłoś jeśli naruszono regulamin