Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (2 votes)
11 views

(Ebook) Programming Arduino Projects with the PIC Microcontroller: A Line-By Line Code Analysis and Complete Reference Guide for Embedded Programming in C by Hubert Henry Ward ISBN 9781484272299, 1484272293 - Quickly download the ebook to read anytime, anywhere

The document provides information about various ebooks available for download on ebooknice.com, focusing on programming the PIC microcontroller and Arduino projects. It includes titles by Hubert Henry Ward and others, along with their ISBNs and links for instant access. The content covers embedded programming in C, offering resources for beginners to advanced users in the field of microcontroller programming.

Uploaded by

clarapontac
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
11 views

(Ebook) Programming Arduino Projects with the PIC Microcontroller: A Line-By Line Code Analysis and Complete Reference Guide for Embedded Programming in C by Hubert Henry Ward ISBN 9781484272299, 1484272293 - Quickly download the ebook to read anytime, anywhere

The document provides information about various ebooks available for download on ebooknice.com, focusing on programming the PIC microcontroller and Arduino projects. It includes titles by Hubert Henry Ward and others, along with their ISBNs and links for instant access. The content covers embedded programming in C, offering resources for beginners to advanced users in the field of microcontroller programming.

Uploaded by

clarapontac
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Instant Ebook Access, One Click Away – Begin at ebooknice.

com

(Ebook) Programming Arduino Projects with the PIC


Microcontroller: A Line-By Line Code Analysis and
Complete Reference Guide for Embedded Programming
in C by Hubert Henry Ward ISBN 9781484272299,
1484272293
https://ebooknice.com/product/programming-arduino-projects-
with-the-pic-microcontroller-a-line-by-line-code-analysis-
and-complete-reference-guide-for-embedded-programming-
in-c-34873434

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) Introductory Programs with the 32-bit PIC Microcontroller: A Line-by-Line


Code Analysis and Reference Guide for Embedded Programming in C (Maker Innovations
Series) by Hubert Ward ISBN 9781484290514, 9781484290507, 1484290518, 148429050X

https://ebooknice.com/product/introductory-programs-with-the-32-bit-pic-
microcontroller-a-line-by-line-code-analysis-and-reference-guide-for-embedded-
programming-in-c-maker-innovations-series-50493086

ebooknice.com

(Ebook) Intermediate C Programming for the PIC Microcontroller: Simplifying Embedded


Programming by Hubert Henry Ward ISBN 9781484260678, 9781484260685, 1484260678,
1484260686

https://ebooknice.com/product/intermediate-c-programming-for-the-pic-
microcontroller-simplifying-embedded-programming-22417478

ebooknice.com

(Ebook) C Programming for the PIC Microcontroller. by kan

https://ebooknice.com/product/c-programming-for-the-pic-microcontroller-50195818

ebooknice.com

(Ebook) Introductory Programs with the 32-bit PIC Microcontroller by Hubert Ward
ISBN 9781484290514, 1484290518

https://ebooknice.com/product/introductory-programs-with-the-32-bit-pic-
microcontroller-50009494

ebooknice.com
(Ebook) The First Line of Code: Android Programming with Kotlin by Lin Guo ISBN
9789811917998, 981191799X

https://ebooknice.com/product/the-first-line-of-code-android-programming-with-
kotlin-43812082

ebooknice.com

(Ebook) Programming the PIC Microcontroller with MBASIC by Smith J. ISBN


9780080460741, 9780750679466, 0080460747, 0750679468

https://ebooknice.com/product/programming-the-pic-microcontroller-with-
mbasic-982686

ebooknice.com

(Ebook) Arduino: Arduino User Guide for Operating system, Programming, Projects and
More! by Robert Scott

https://ebooknice.com/product/arduino-arduino-user-guide-for-operating-system-
programming-projects-and-more-43890042

ebooknice.com

(Ebook) Advanced PIC Microcontroller Projects in C: From USB to ZIGBEE with the PIC
18F Series by Dogan Ibrahim ISBN 9780750689823, 075068982X

https://ebooknice.com/product/advanced-pic-microcontroller-projects-in-c-from-
usb-to-zigbee-with-the-pic-18f-series-1123344

ebooknice.com

(Ebook) Arduino Measurement Projects for Beginners: Arduino Programming basics and
Get started guide by Simone bales

https://ebooknice.com/product/arduino-measurement-projects-for-beginners-
arduino-programming-basics-and-get-started-guide-7431820

ebooknice.com
TECHNOLOGY IN AC TION™

Programming Arduino
Projects with the
PIC Microcontroller
A Line-by-Line Code Analysis and
Complete Reference Guide for
Embedded Programming in C

Hubert Henry Ward
Programming Arduino
Projects with the PIC
Microcontroller
A Line-by-Line Code Analysis
and Complete Reference
Guide for Embedded
Programming in C

Hubert Henry Ward


Programming Arduino Projects with the PIC Microcontroller: A Line-by-Line
Code Analysis and Complete Reference Guide for Embedded
Programming in C
Hubert Henry Ward
Leigh, UK

ISBN-13 (pbk): 978-1-4842-7232-9 ISBN-13 (electronic): 978-1-4842-7230-5


https://doi.org/10.1007/978-1-4842-7230-5

Copyright © 2022 by Hubert Henry Ward


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Susan McDermott
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 NY
Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and
the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for
reprint, paperback, or audio rights, please email bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book’s product page, located at www.apress.com/ 978-1-4842-7232-9.
For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author�������������������������������������������������������������������������������xiii

About the Technical Reviewer������������������������������������������������������������xv


Introduction��������������������������������������������������������������������������������������xvii

Chapter 1: Introducing MPLABX�����������������������������������������������������������1


MPLABX: The IDE from Microchip�������������������������������������������������������������������������1
Creating a Project in MPLABX�������������������������������������������������������������������������������3
The Configuration Words���������������������������������������������������������������������������������������9
Creating a Header File����������������������������������������������������������������������������������������14
Changing the Fonts and Colors���������������������������������������������������������������������������21
The PIC Microcontroller���������������������������������������������������������������������������������������22
The PIC16F88 and the PIC8F4525�����������������������������������������������������������������������24
Summary������������������������������������������������������������������������������������������������������������25

Chapter 2: Programming Basics���������������������������������������������������������27


Good Programming Practice�������������������������������������������������������������������������������28
Algorithms�����������������������������������������������������������������������������������������������������28
Flowcharts�����������������������������������������������������������������������������������������������������29
Program Listings�������������������������������������������������������������������������������������������30
Program 2.1: Turning On and Off an LED�������������������������������������������������������������30
Algorithm for Program 2.1�����������������������������������������������������������������������������31
Flowchart for Program 2.1�����������������������������������������������������������������������������32

iii
Table of Contents

The Program Listing��������������������������������������������������������������������������������������������34


Creating a Source File�����������������������������������������������������������������������������������34
Adding the Header File����������������������������������������������������������������������������������39
Program 2.1��������������������������������������������������������������������������������������������������������43
Analysis of Listing 2-1�����������������������������������������������������������������������������������45
Running Program 2.1������������������������������������������������������������������������������������������61
The PIC16F88 Development Board����������������������������������������������������������������������64
The ICSP Circuit��������������������������������������������������������������������������������������������������66
Testing Program 2.1��������������������������������������������������������������������������������������������71
Downloading Our Program����������������������������������������������������������������������������������76
Summary������������������������������������������������������������������������������������������������������������80

Chapter 3: The Seven-­Segment Display and the Stepper Motor ��������81


Program 3.1: Controlling a Seven-Segment Display�������������������������������������������81
Seven-Segment Displays������������������������������������������������������������������������������������82
Common Anode Seven-Segment Display������������������������������������������������������������82
Common Cathode Seven-Segment Display��������������������������������������������������������84
Arrangement for a Common Anode Seven-­Segment Display������������������������������84
Controlling the Display with the PIC��������������������������������������������������������������������85
Seven-Segment Display Program�����������������������������������������������������������������������87
Algorithm for Program 3.1����������������������������������������������������������������������������������87
Flowchart for Program 3.1����������������������������������������������������������������������������������89
Program Listing for the Common Cathode Seven-Segment Display�������������������91
Analysis of Listing 3-1����������������������������������������������������������������������������������������94
Program 3.2: 3461BS Common Anode Four Seven-Segment
Display Module�������������������������������������������������������������������������������������������������108

iv
Table of Contents

Analysis of Listing 3-2��������������������������������������������������������������������������������������113


The Stepper Motor��������������������������������������������������������������������������������������������114
Analysis of Listing 3-3��������������������������������������������������������������������������������������123
Summary����������������������������������������������������������������������������������������������������������128

Chapter 4: The Joystick and the Stepper Motor�������������������������������129


Using the Joystick���������������������������������������������������������������������������������������������129
The Principal Operation of the Joystick�������������������������������������������������������130
The ADCON0 Control Register����������������������������������������������������������������������132
The ADCON1 Register����������������������������������������������������������������������������������134
The ADCON2 Register����������������������������������������������������������������������������������136
Changing the ADC Input Channels���������������������������������������������������������������144
Left or Right Justification����������������������������������������������������������������������������144
The Joystick Program���������������������������������������������������������������������������������������144
The LCD�������������������������������������������������������������������������������������������������������151
Instruction or Command Mode��������������������������������������������������������������������153
Data Mode���������������������������������������������������������������������������������������������������153
Bytes and Nibbles����������������������������������������������������������������������������������������154
The Control Pins of the LCD�������������������������������������������������������������������������155
Analysis of Listing 4-1��������������������������������������������������������������������������������������156
One-Dimensional Array�������������������������������������������������������������������������������������158
Accessing Data in the Array������������������������������������������������������������������������159
Using Pointers���������������������������������������������������������������������������������������������159
Joystick and Stepper Motor������������������������������������������������������������������������������176
Analysis of Listing 4-2���������������������������������������������������������������������������������186
Homemade Prototype Board for the PIC18F4525���������������������������������������������190
Summary����������������������������������������������������������������������������������������������������������193

v
Table of Contents

Chapter 5: DC Motors������������������������������������������������������������������������195


The Speed of the Simple DC Motor�������������������������������������������������������������������195
PWM������������������������������������������������������������������������������������������������������������196
Creating a Square Wave with the PWM Mode���������������������������������������������197
Creating a 1kHz Square Wave���������������������������������������������������������������������201
The Mark Time or Duty Cycle�����������������������������������������������������������������������202
The TMR2 Preset Value��������������������������������������������������������������������������������203
Storing a Ten-Bit Number����������������������������������������������������������������������������204
Analysis of Listing 5-1���������������������������������������������������������������������������������205
The Variable-Speed DC Motor Program������������������������������������������������������������208
Analysis of Listing 5-2���������������������������������������������������������������������������������211
A Two-Directional DC Motor Program����������������������������������������������������������211
Using the L293D Driver IC����������������������������������������������������������������������������214
Controlling a Two-Wheel Drive System�������������������������������������������������������219
Analysis of Listing 5-3���������������������������������������������������������������������������������222
Controlling a Servo Motor���������������������������������������������������������������������������������224
Analysis of Listing 5-4���������������������������������������������������������������������������������228
Summary����������������������������������������������������������������������������������������������������������234

Chapter 6: Ultrasonic Distance, and Humidity and Temperature


Sensors���������������������������������������������������������������������������������������������237
Using the Ultrasonic Sensor������������������������������������������������������������������������������237
The Basic Principle of Operation�����������������������������������������������������������������238
The Principal Operation of the Program������������������������������������������������������240
Analysis of Listing 6-1���������������������������������������������������������������������������������243
The DHT11 Humidity and Temperature Sensor�������������������������������������������������248
Communicating with the DHT11������������������������������������������������������������������249
The Use of a Pull Up Resistor����������������������������������������������������������������������253

vi
Table of Contents

Checking the Timing of the Pulses��������������������������������������������������������������253


Analysis of Listing 6-3���������������������������������������������������������������������������������262
Summary����������������������������������������������������������������������������������������������������������269

Chapter 7: Working with Keypads����������������������������������������������������271


Traditional 3 × 4 Keypad Entry��������������������������������������������������������������������������273
The Need for Pull Up or Pull Down��������������������������������������������������������������274
Pull Down Resistors�������������������������������������������������������������������������������������276
Pull Up Resistors�����������������������������������������������������������������������������������������277
Traditional Keypad Program������������������������������������������������������������������������279
Analysis of Listing 7-1���������������������������������������������������������������������������������293
Switch Bounce���������������������������������������������������������������������������������������������294
The Membrane 4 × 4 Keypad����������������������������������������������������������������������������299
The 8 × 8 Dot Matrix Board�������������������������������������������������������������������������������321
Analysis of Listing 7-3���������������������������������������������������������������������������������331
Creating the Data for Each Row in the Two-­Dimensional Array�������������������332
Summary����������������������������������������������������������������������������������������������������������341

Chapter 8: Using Bluetooth with PIR Motion Sensors����������������������343


The HC-06 Module��������������������������������������������������������������������������������������������343
Matching 5V to 3.3V������������������������������������������������������������������������������������344
The Default Settings of the HC-06���������������������������������������������������������������345
The HC-05 Bluetooth Module�����������������������������������������������������������������������346
Connecting the PIC to a Mobile Phone via the HC-06����������������������������������348
The UART�����������������������������������������������������������������������������������������������������������353
Analysis of Listing 8-1���������������������������������������������������������������������������������353
An Important Distinction������������������������������������������������������������������������������358

vii
Table of Contents

Using the Mobile APP Bluetooth Terminal���������������������������������������������������������359


Changing the PIN on the HC-06�������������������������������������������������������������������360
Using AT Commands������������������������������������������������������������������������������������362
Using PuTTY to Program the HC-06�������������������������������������������������������������369
Programming the HC-06 with AT Command from the PIC Micro�����������������������371
Analysis of Listing 8-2���������������������������������������������������������������������������������376
The HC-SR501 PIR Motion Sensor��������������������������������������������������������������������380
Analysis of Listing 8-3���������������������������������������������������������������������������������385
Summary����������������������������������������������������������������������������������������������������������387

Chapter 9: Communication���������������������������������������������������������������389
Getting the PIC to Communicate with Other Devices���������������������������������������390
The SPI Mode�����������������������������������������������������������������������������������������������390
The Buffer Full (BF) Flag in the SSPSTAT Register��������������������������������������393
Synchronizing the Sequence�����������������������������������������������������������������������394
SSPSTAT Register����������������������������������������������������������������������������������������396
The SSPCON1 Register��������������������������������������������������������������������������������397
Using the SPI to Read from the TC72����������������������������������������������������������������400
Operating Modes for the TC72���������������������������������������������������������������������400
The Registers of the TC72���������������������������������������������������������������������������401
The Algorithm for Using the TC72����������������������������������������������������������������402
Displaying the Temperature Reading�����������������������������������������������������������403
Binary Numbers�������������������������������������������������������������������������������������������411
Analysis of Listing 9-1���������������������������������������������������������������������������������415
Reading the Temperature from the TC72�����������������������������������������������������416
Examples of the 2’s Complement Process��������������������������������������������������418
Using the Sprintf Function��������������������������������������������������������������������������������431
Analysis of Listing 9-2���������������������������������������������������������������������������������435
Comparing the Two Approaches������������������������������������������������������������������438

viii
Table of Contents

Using the PIC18f4525 as the Slave�������������������������������������������������������������������440


Analysis of Listing 9-3���������������������������������������������������������������������������������443
Analysis of Listing 9-4���������������������������������������������������������������������������������447
Summary����������������������������������������������������������������������������������������������������������449

Chapter 10: Using the I2C Protocol���������������������������������������������������451


I2C Communication Protocol������������������������������������������������������������������������������451
EEPROM������������������������������������������������������������������������������������������������������������452
24LC256 EEPROM����������������������������������������������������������������������������������������453
Writing to the EEPROM��������������������������������������������������������������������������������455
Reading from the EEPROM��������������������������������������������������������������������������456
TC74 Temperature Sensor���������������������������������������������������������������������������������457
Reading the Temperature����������������������������������������������������������������������������458
Using I2C with 24LC256 and TC74���������������������������������������������������������������������459
Analysis of Listing 10-1�������������������������������������������������������������������������������466
That Little Thought���������������������������������������������������������������������������������������483
Summary����������������������������������������������������������������������������������������������������������483

Chapter 11: Using the UART��������������������������������������������������������������485


UART at a Glance�����������������������������������������������������������������������������������������������485
Interrupts and How They Work��������������������������������������������������������������������491
Analysis of Listing 11-1�������������������������������������������������������������������������������494
The Baud Rate���������������������������������������������������������������������������������������������������499
Using Tera Term�������������������������������������������������������������������������������������������������502
Using Handshaking�������������������������������������������������������������������������������������������509
Analysis of Listing 11-2�������������������������������������������������������������������������������513
Two PICs Communicate via the UART���������������������������������������������������������������517
Analysis of Listing 11-3�������������������������������������������������������������������������������523
Summary����������������������������������������������������������������������������������������������������������527

ix
Table of Contents

Chapter 12: Real-Time Clock and Interrupts������������������������������������529


The RTC Program����������������������������������������������������������������������������������������������530
Analysis of Listing 12-1�������������������������������������������������������������������������������537
The DS1307 RTC Module�����������������������������������������������������������������������������������542
Setting Up and Reading from the DS1307���������������������������������������������������543
Writing to the Slave�������������������������������������������������������������������������������������544
Reading from the Slave�������������������������������������������������������������������������������546
The NACK or Not Acknowledgment Bit��������������������������������������������������������547
Analysis of Listing 12-2�������������������������������������������������������������������������������555
TM1637 and the Four Seven-Segment Display�������������������������������������������������565
The TM1367 Driver IC����������������������������������������������������������������������������������566
Analysis of Listing 12-3�������������������������������������������������������������������������������582
Summary����������������������������������������������������������������������������������������������������������598

Chapter 13: Working with LCDs��������������������������������������������������������601


Creating Your Own Characters on an LCD���������������������������������������������������������601
The Pixel Maps��������������������������������������������������������������������������������������������602
A Simple Exercise����������������������������������������������������������������������������������������605
Analysis of Listing 13-1�������������������������������������������������������������������������������611
The CCP Module������������������������������������������������������������������������������������������������615
Algorithm for the Bike Speed Program��������������������������������������������������������617
The Speed of a Bicycle��������������������������������������������������������������������������������617
Analysis of Listing 13-2�������������������������������������������������������������������������������623
Finding the Program Instructions����������������������������������������������������������������������628
Program Counter and the Stack������������������������������������������������������������������628
The Stack�����������������������������������������������������������������������������������������������������629
The Vector Table and the ISR�����������������������������������������������������������������������630
Summary����������������������������������������������������������������������������������������������������������633

x
Table of Contents

Chapter 14: Analyzing Obscure Instructions and Logic


Operators in C�����������������������������������������������������������������������������������635
Obscure C Instructions��������������������������������������������������������������������������������������635
Analysis of Listing 14-1�������������������������������������������������������������������������������639
Some Logic Operators���������������������������������������������������������������������������������������647
& Symbol�����������������������������������������������������������������������������������������������������649
Testing the Programs in MPLABX����������������������������������������������������������������650
Analysis of Listing 14-3�������������������������������������������������������������������������������657
The && Operator������������������������������������������������������������������������������������������660
The ‘|’ Operator��������������������������������������������������������������������������������������������663
The ‘||’ Operator������������������������������������������������������������������������������������������������666
The ^ EXOR or Exclusive OR������������������������������������������������������������������������670
The &= Function������������������������������������������������������������������������������������������672
The |= Function�������������������������������������������������������������������������������������������674
The ‘%’ or Modulus or Remainder Operator������������������������������������������������675
The ‘~’ Or 1’s Complement��������������������������������������������������������������������������677
The ‘<<n’ or ‘>>n’ Operator������������������������������������������������������������������������679
Summary����������������������������������������������������������������������������������������������������������682

Appendix: Additional Insights�����������������������������������������������������������683


Data Types and Memory������������������������������������������������������������������������������������683
The Program Memory Area�������������������������������������������������������������������������������683
The Data RAM���������������������������������������������������������������������������������������������������684
The Data EEPROM���������������������������������������������������������������������������������������������684
Variables������������������������������������������������������������������������������������������������������684
Appendix A: Data Types�������������������������������������������������������������������������������������685
Appendix B: Some Useful Definitions����������������������������������������������������������������686
Appendix C: Mathematical and Logic Operators�����������������������������������������������687

xi
Table of Contents

Appendix D: Keywords��������������������������������������������������������������������������������������688
Appendix E: Numbering Systems Within Microprocessor-Based Systems�������688
Introduction�������������������������������������������������������������������������������������������������688
Binary Numbers�������������������������������������������������������������������������������������������689
Adding and Subtracting Binary Numbers����������������������������������������������������692
The Hexadecimal Number System��������������������������������������������������������������695
Appendix F: Building Circuit Boards������������������������������������������������������������������697
Preparation��������������������������������������������������������������������������������������������������697
Appendix G: The LCD Header File for Eight-­Bit Mode����������������������������������������703
Appendix H: The ASCII Character Set����������������������������������������������������������������710
Appendix I: The LCD Instruction Set������������������������������������������������������������������712

Index�������������������������������������������������������������������������������������������������715

xii
About the Author
Hubert Henry Ward has nearly 25 years of
experience as a college lecturer delivering the
BTEC, and now Pearson’s, Higher National
Certificate and Higher Diploma in Electrical &
Electronic Engineering. Hubert has a 2.1
Honors Bachelor’s Degree in Electrical &
Electronic Engineering. Hubert has also
worked as a consultant in embedded
programming. His work has established his
expertise in the assembler and C programming
languages, within the MPLABX IDE from
Microchip, as well as designing electronic circuits, and PCBs, using ECAD
software. Hubert was also the UK technical expert in Mechatronics for
three years, training the UK team and taking them to enter in the Skills
Olympics in Seoul 2001, resulting in one of the best outcomes to date for
the UK in Mechatronics.

xiii
About the Technical Reviewer
Massimo Nardone has more than 22 years
of experiences in Security, Web/Mobile
development, Cloud, and IT Architecture. His
true IT passions are Security and Android.
He has been programming and teaching
how to program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more than
20 years.
He holds a Master of Science degree in
Computing Science from the University of
Salerno, Italy.
He has worked as a Project Manager, Software Engineer, Research
Engineer, Chief Security Architect, Information Security Manager, PCI/
SCADA Auditor, and Senior Lead IT Security/Cloud/SCADA Architect for
many years.

xv
Introduction
This book looks at using some useful aspects of the PIC microcontroller. It
explains how to write programs in C so that you can use the PIC micro to
control a variety of electronics devices and DC motors. After reading this
book, you will be well on your way to becoming an embedded programmer
using the C program language.
I have two main aims in writing this book. First and foremost, I have
a real passion for writing programs in that I am enthralled by the way
we can use simple ‘1’s and ‘0’s, really ‘5V’ and ‘0V’, to make a circuit do
almost anything we want it to do. The extent of what we can get these
microcontrollers to do is limited only by our imagination and experience. In
my youth, we thought the flip phone used by Captain James T. Kirk in Star
Trek was just a gimmick and we would never get there. Well, our mobile
phones do a lot more than just video calls. All of what we do with our phones
is done with just ‘1’s and ‘0’s. In writing this book, my primary goal is to
hopefully inspire you guys into wanting to understand how we make the ‘1’s
and ‘0’s work for us. That is why I will explain how all the instructions in my
programs actually work and how they achieve the outcomes we want.
The second aim in writing this book is to transfer all those Arduino
Sketches, which use a range of useful peripheral devices, and show you
how to get them to work on a PIC microcontroller. In doing so, I hope
to show you that the world of PIC controllers is not complicated and
really anyone can work with them. It does not matter what experience
you have with PICs, as I will assume you know nothing. This book will
take the complete novice and not only allow them to run those Arduino
Sketches on the PIC, but it will explain in detail every aspect of how the
programs work. After reading this book, you will hopefully not only enjoy

xvii
Introduction

programming PIC micros in the ‘C’ programming language, but should be


well prepared to take on a new career as an embedded programmer.
In addition to getting to know how to program in ‘C’, I will show you
how to build a range of circuits so that you end up using the peripherals in
a practical environment. I will show you how, if you so wish, you can make
your own prototype boards to program your PICs and run the programs
you write. We will learn about the electronic principles of the components
we use to interface the PIC to a wide range of useful peripherals.

Goals of the Book


After reading through this book, you should be able to program the PIC to
use all the following peripherals:

• The seven-segment display

• The eight-by-eight matrix display

• The joystick controller

• The HC-04 ultrasonic sensor

• The stepper motor

• THE SERVO MOTOR

• The DS1307 real-time clock module

• The DHT11 humidity and temperature sensor

• The DC motor and fan

• The membrane keypad module


You should also gain a good understanding of some of the basic and
advanced programming techniques for PIC micros, such as the following:

• The configuration words

• The TRIS registers and PORTS

xviii
Introduction

• The timer registers

• The ADC (analog-to-digital converter) module

• The CCPM (capture, compare, and pulse width


modulation) module.

• The MSSP (master synchronous serial port) module


using SPI (serial peripheral interface) and I2C (inter-­
integrated circuit) communication protocols.

• The EUSART (enhanced universal synchronous/


asynchronous, receive and transmit) module

• Interrupts

You will be able to use an industrial IDE to write your programs in C,


compile and download your programs using a variety of tools, and use the
simulator in MPLABX, the IDE, to debug your programs.
You should be able to download your programs to your PIC in a
practical situation where you have the ability to design and build some
useful projects.
You will have learned the basic principles of a range of electronic
components such as resistors, capacitors, transistors and the Darlington
array, diodes, and light-emitting diodes.

The Prerequisites
There are none really, but if you understand ‘C’ programming it would be
useful. However, I will explain how each of the programs work as we go
through them.
Also, if you understand the binary and hexadecimal number systems, it
would be an advantage, but there is a section in the appendix that will help
you with that and I will explain the important aspects as we need them.

xix
Introduction

However, to get the full use out of this book, you will need to have
installed the following software:

• MPLABX, which is the IDE from Microchip. The version


in the book is MPLABX version 5.25. However, any
version later than 2.20 will be OK.

• A ‘C’ compiler for the eight-bit micro. I use XC8 (V2.10),


but with some programs I use XC8 (V1.35) compiler
software. However, you should be aware that some of
the later compilers have some useful libraries missing.
That is why I sometimes use version 1.35.

All these programs are freely available from the Microchip website.
Another useful piece of software would be a suitable ECAD (electronic
computer-aided design) software that supports eight-bit micros. The
ECAD software that I have used in the past is PROTEUS. However, this is
not free and so I will show you how to use a suitable prototype board to run
the programs in a practical situation.
If you want to go down the practical route, you will need to purchase a
programming tool and you may need to buy a prototype board. However,
I do have a chapter where I show you how to make your own prototype
board using vero board.
The programming tools I use are either the ICD3 can; now Microchip
has moved on to the ICD4 can, or the PICkit3 programmer, to download
the programs from MPLABX to the PIC.
The off-the-shelf prototype board that I may use is the PICdem2 plus
demo board.
This book has been written based around using MPLABX V5.25.
However, the principles of how to create projects and write programs are
transferable to earlier and later versions of MPLABX. There may be some
slight differences in the detail; however, these shouldn’t cause you too
much of a problem.

xx
Introduction

I will base the book around the following two PICs:

• The PIC16f88: This is a very versatile eight-bit micro


that comes in an 18-pin or 20-pin dual inline package.

• The PIC18F4525: This is a very versatile eight-bit micro


that comes in a 40-pin dual inline package.

As long as the PIC you want to use has the same firmware modules,
then the programs in the book can easily be used on other PIC micros with
some minor modifications. However, you should always refer to the data
sheet for the particular PIC you use, as some of the SFRs (special function
registers) may differ. For example, the PIC18F4525 uses the ADCON0,
ADCON1, and ADCON2 special function registers to control the ADC
module, but the 16F88 uses the ANSEL, ADCON0, and ADCON1 registers. I
will show you how to use the datasheets, as it is important that an engineer
can obtain the relevant information from datasheets.
Throughout the book, I will be including some program listings. I
will then go through an analysis of any new instructions that the listings
introduce. With respect to the first listing, I will assume all the instructions
are new to you the reader.
I hope you will enjoy reading and learning from my book and that it
will ignite that spark in you that motivates you to move into a career as an
embedded programmer. Good luck and happy reading.

xxi
CHAPTER 1

Introducing MPLABX
In this chapter we are going to learn about the MPLABX, an industrial
integrated development environment (IDE) from Microchip. We will learn
what an IDE is and how to create a project with MPLABX. We will also learn
about the configuration bits for programmable interrupt controller (PIC)
micros. Finally, we will learn about header files: why we use them and how
to create one in MPLABX.

MPLABX: The IDE from Microchip


An IDE is actually a collection of the different programs needed to write
program instructions in our chosen language, and then convert them to
the actual machine code that the micro understands and also link together
any bits of program we may want to use.
The programs we need in the IDE are as follows:

• A text editor to write the instructions for the program.


Note that the simple text editor Notepad could be
used, but the text editor in MPLABX is by far a more
advanced text editor.

• A compiler to change the instructions into a format the


micro can understand.

• A linker to combine any files the programmer wants


to use.

© Hubert Henry Ward 2022 1


H. H. Ward, Programming Arduino Projects with the PIC Microcontroller,
https://doi.org/10.1007/978-1-4842-7230-5_1
Chapter 1 Introducing MPLABX

• A driver that will allow the programming tool we use to


load the program into the micro.

• A variety of debug tools to allow the programmer to test


the program live within the micro.

All these are in, or should be in, the IDE we choose to use. Microsoft
has Visual Studio, Microchip has MPLABX, and Freescale uses
CodeWarrior. The Arduino has its own IDE. There is also CODEBLOCK,
which is an IDE for writing generic ‘C’ programs that will run on your
PC. As this book is based on the PIC micro, we will concentrate on
MPLABX. MPLABX has an improved text editor to give the text different
color codes when we save the file as an .asm or .c for c program file, such
as light blue for keywords, light gray for comments, and so on.
There are some other organization programs within MPLABX, such as
those that support the ability to write to the configuration registers for the
PIC. There is also the ability to debug your programs within the IDE. All
this makes MPLABX a useful tool for programming PICs.
There is also a program called MCC (Microchip Code Configurator).
This will actually produce a lot of the code you need to use various
aspects of the PIC. However, I firmly believe that you should produce
the code you use yourself so that you fully understand it. I will not cover
the use of MCC. Also, Microchip has not written the MCC for all its PICs,
and the 18F4525 is one it has missed so far. Really, when asked who
the programmer is, you should be able to say that you are and not the
MCC. When you take the time to study how to write your own code, you
will find it is not as hard as you first thought. Also you will get a better self-­
reward if you write it all yourself.
The only aspect of the programs that I let Microchip do for me is to
write the code configuration bits that set up the PIC. This is only because
it is so simple to do this and it covers all the #pragma statements that we
used to write ourselves.

2
Chapter 1 Introducing MPLABX

Creating a Project in MPLABX


Once you have downloaded both the MPLABX software and the XC8
(V2.10) compiler software or XC8 (V1.35), when you open the software the
opening screen will be as shown in Figure 1-1.

Figure 1-1. The opening screen in MPLABX

The project window on the left-hand side may not be shown. If you
want it shown, then you should select the word “window” from the top
menu bar. You should then click the mouse on the word “projects”, with the
orange boxes in front of it, and the window should appear. You may have to
move the window about to get it in the position shown.
Now, assuming you are ready to create a project, you should either
click the mouse on the word “file”, in the main menu bar, and select new
project, or click the mouse on the orange box, with the small green cross,
on the second menu bar. This is the second symbol from the left-hand side
of the second menu bar.
When you have selected the create project option, you should now see
the window shown in Figure 1-2.

3
Chapter 1 Introducing MPLABX

Figure 1-2. The new project window

Most of the projects we will create are Microchip Embedded and


Standalone. Therefore, make sure these two options are highlighted and
then click “Next”. The select device window should now be visible as
shown in Figure 1-3.

Figure 1-3. The select device window

4
Chapter 1 Introducing MPLABX

In this window, we can choose which PIC we want to use. For our first
project, we are going to use the PIC16F88 micro. You need to select the
midrange eight-bit MCUs (PIC10, 12, 16/MCP) in the small box alongside
Family, as shown in Figure 1-3. Then, in the device window, you need
to select the PIC16F88. The result is shown in Figure 1-3. To make these
options visible, you need to click the small downward-pointing arrows in
the respective boxes. The different options should then become visible. If
the device window is highlighted in blue, you could simply type in the PIC
number you want (i.e., PIC16F88). Your selected device should appear in
the window shown in Figure 1-3.
If you are using a different PIC then you should select it here.
Once you are happy with your selection, you need to click the next box
in the window.
The next window to appear is the select tool window. This is shown
in Figure 1-4. With this window, you can select the programming tool
you want to use to download the program to your prototype board.
There are a range of tools you can use. I mainly use the ICD3 CAN or
the PICkit3 tool. We will select the PICkit3 as shown in Figure 1-4. If you
are using a different tool to download your program, simply select it
here. Do not worry if you don’t see the serial number of your device, as
shown in Figure 1-4. This would be because you have not yet connected
it to your laptop.

5
Chapter 1 Introducing MPLABX

Figure 1-4. The select tool window


Having selected the tool you want, simply click “Next” to move on to
the next window, where you can select the compiler software you want to
use, assuming you have downloaded the appropriate compiler software.

Figure 1-5. The select compiler window

6
Chapter 1 Introducing MPLABX

You should select the XC8 (V2.20) compiler software, although with
some later projects we will use V1.35, as shown in Figure 1-5. Then click
“Next” to move to the select project name and folder window, as shown in
Figure 1-6.

Figure 1-6. The select project name and folder window

In this window, you will specify the name of the project and where
you want to save it. The software will create a new directory on your
computer with the project name you create here. It is not recommended
to use long-­winded complicated path names to the new folder, so I
normally save all my projects on the root directory of my laptop.
I have suggested a project name for this new project as ourFirst16F88.
Note that I am using camel case, in which two words, or more, are
combined together. The first letter of the first word is in lowercase and the
first letters of any subsequent words are in uppercase. In this way, multiple
words can be combined together to make one long word.

7
Chapter 1 Introducing MPLABX

As you type the name for your project you should see that the folder is
created on the root drive, or wherever you have specified it should be. The
folder name will have a .X added to it.
It will be in this new folder that all the files associated with the project
will be saved as well as some important subdirectories that are created.
Once you are happy with the naming of the project, simply click
“Finish” and the project will be created. The window will now go back to
the main window as shown in Figure 1-7.

Figure 1-7. The main window with the project created

You should now see the project window at the left-hand side of your
screen as shown in Figure 1-7. Note that you may need to move the
window around to get it the same in Figure 1-7.

8
Chapter 1 Introducing MPLABX

The Configuration Words


This section discusses one of the major differences between the PIC
microcontrollers and the Arduino. It may seem rather cumbersome, but
it reflects the versatility of PICs. It will also give me an opportunity to
introduce you to header files and show you how we can create them.
With the Arduino, it is most likely that the configuration work has
been done for you; this may make it seem that the Arduino is easier to use.
However, I think it has removed the versatility of the device and restricts
your understanding of the microcontroller. Certainly, MPLABX, the
industrial IDE developed by Microchip, does not have any preconfigured
setups for their PICs. This does give you the full range of their versatility,
but it does mean you have an extra bit of studying to do before you can
program the PICs. Thankfully, it is not a lot to study and Microchip has
made it very easy for you to configure the PICs as you want.
The configuration words actually configure, or set up, certain aspects
of the PIC and how we want to use them. The most important of these
aspects is the source of the oscillator we will be using. The oscillator
produces the clocking signal that synchronizes all the actions of the
PIC. Microchip allows us to choose from a very wide range of sources
from the simple RC (resistor capacitor) oscillator, for low frequencies that
don’t need to be very accurate, to the more accurate crystal oscillators
with frequencies above 20Mhz. These are external devices that can be
connected to the PIC. However, Microchip also gives us the choice of
using oscillators that are internal (i.e., already set up inside the PIC). This
can save the cost of buying an oscillator and save the use of two pins that
would have to be used to connect an external oscillator to the PIC. When
you use the Arduino, you don’t have to worry about which oscillator source
you are using because you have had that choice done for you.
There are other aspects of the PIC you need to configure, such as the
WDT (watch dog timer) and the Low Voltage Programming (LVP); we will
look at them now.

9
Chapter 1 Introducing MPLABX

I have tried to explain the use of the configuration words; now let’s
see how we can configure them. As this is something you have to do for all
your projects and for all the different PICs you might use, Microchip has
tried to make it easier for you. I know when I first started writing programs
for PICs it wasn’t quite as easy as it is now.
To write the code for the configuration words, we use a special
window in the MPLABX IDE. To open this window, click the word
“window” on the main menu bar and then select “Target Memory
Views” from the drop-­down menu that appears. Then select
“configuration bits” from the slide-­out menu that appears. This process
is shown in Figure 1-8.

Figure 1-8. Opening up the configuration bits

Once you have selected the configuration bits option, your main
window will change to that shown in Figure 1-9.

10
Chapter 1 Introducing MPLABX

Figure 1-9. The configuration bits

As this is the PIC16F88, there are not that many settings for us to
consider. The first one listed is the main one we need to change. It is
labeled FOSC (for frequency of oscillator). The default setting is usually
the external RC oscillator. You should see under the “setting” label that it
indicates that it is connected to RA6. This means that the pin RA6 (i.e., bit6
of PORTA) cannot be used for anything else, as it is used to take the signal
from the external RC oscillator into the PIC.
I always prefer to use the internal oscillator block because it saves the
cost of the external oscillator and it frees up pin RA6 and more, as we will
see. To change this setting, we must click the mouse on the small arrow
at the side of the phrase “EXTRCCLK” and select the option “INTOSCIO”,
which means the internal oscillator with input/output function on pins
RA6 and RA7. You should see that the comments under the label “setting”
have changed to show this and they are shown in blue.

11
Chapter 1 Introducing MPLABX

We will make two other changes:

• WDTE: We will turn it off. The WDTE is a watch dog


timer enable that, if enabled, will stop the program
if nothing happens for a set period of time (usually
a short period of time). This is really a safety factor
that is used in industry, whereby on a production
line if nothing happens for any length of time, it
means something has gone wrong so we should stop
production and find out what has gone wrong. Well,
most of our programs won’t need that safeguard so we
should turn it off. I think this aspect of the WDT shows
that the Arduino is not really meant for industry, as
again this option has already been taken out of your
hands.

• The third item to change is the LVP. We should turn


it off so that bit3 of PORTB is left as a normal input
output pin.

• Those are the changes that we need to make for this


PIC, and these changes are shown in Figure 1-10.

12
Chapter 1 Introducing MPLABX

Figure 1-10. The changes to the configuration words

All we need to do now is generate the source code and use it in our
program. This process is a lot easier than it has been, because all we need
to do now is click the tab “Generate Source Code to Output” and MPLABX
will do it for us. This tab is at the bottom of the screen as shown in
Figure 1-­9 and Figure 1-10. Once you generate the code, it should appear
as shown in Figure 1-11. You may have to minimize the configuration bits
window to show the source code better.

13
Chapter 1 Introducing MPLABX

Figure 1-11. The config bits source

What we are going to do is copy these instructions and paste them into
a header file. We could paste them into the program listing that we will use
for the first program. However, we will not start writing that program until
we get to chapter 2. Also I want you to understand that when we write our
other programs for the 16F88, we will use the same configuration words.
There may be times when we want to use a different set of configuration
words, but that won’t happen in the programs in this book. Therefore, to
remove the need to repeat the process of writing the same configuration
words in all our other PIC16F88 projects, we will save these instructions to
a header file: first a local header file and then a global header file.

Creating a Header File


The process of creating a header file is quite simple and yet very useful.
First, in the main editing window, you need to right-click the mouse on the
phrase “Header Files” in the project tree. Then select “New” and then the
“xc8_header,h..” option from the fly-out menu that appears. This is shown
in Figure 1-12.

14
Chapter 1 Introducing MPLABX

Figure 1-12. Creating the new header file

You will be asked to give the file a name. I have suggested


“pic16F88ConfigSettings” as shown in Figure 1-13.

15
Chapter 1 Introducing MPLABX

Figure 1-13. Naming the new header file

Once you are happy with the name of the file, click “Finish”, and the
main editing window should change to show the new file open and ready
for editing. This is shown in Figure 1-14.

16
Chapter 1 Introducing MPLABX

Figure 1-14. The header file in the main editing window

You will see that Microchip automatically inserts an awful lot of text
into the file. I have never used any of it and I simply delete it all. To ensure
that your windows look exactly as I expect them to, I would like you to
delete all that text; thank you.
Before we copy the instructions for the configuration words into
this file, we should add some comments. It is good practice to include
comments in all your programs. You know what you are doing now but
in six months or less, you will wonder why you did what you have done;
therefore, always add comments.
There are two types of comments in ‘C’ programs:

• Single-line comments, which start with two forward


slashes as shown here //. Anything on the same line
after the two forward slashes is ignored by the compiler,
as they are simply comments. For example: //these
words are just comments.

17
Chapter 1 Introducing MPLABX

• Multiple lines of comments or a paragraph of


comments. These are text inserted between the
following symbols /* */. For example:

• /* Your comments are written in here */

• Your comments should have the following


content at least:

• Who wrote it (i.e., you)

• What PIC you wrote it for and when you wrote it

• What you are trying to do with it

As a suggestion you should add the following paragraph of comments:

/*Configuration words for the PIC16F88

Using the internal oscillator block

Turning the WDT off and the LVP off.

Written by Mr. H. H. Ward dated 22/02/2021*/

These should go at the top of the empty file.

Obviously you should insert your name and the


appropriate date.

Now we need to get back the configuration bits we created before.


There should be a tab on the bottom left of the screen with the words
“configuration bits”. If you click the mouse on that tab, the window
should appear in the editing screen. You now need to click the mouse on
“Generate Source Code to Output” to create the source code. The source
code may not automatically appear and you may have to click the mouse
on an empty area of the header file to bring them into view. When you
have them in view, I want you to copy everything EXCEPT the last phrase,
which is #include <xc.h>; I want to discuss the importance of this include

18
Chapter 1 Introducing MPLABX

statement in chapter 2. Once you have copied the source code, you should
paste it into the header file starting on the next line after your initial
comments.
Your editing window should now look like that shown in Figure 1-15.

Figure 1-15. The source code pasted into the header file

All we have to do now is save the file using the save option under the
word “file” on the main menu bar.
So now we have created a “local header file”. We will look at how we
can use this and other header files in chapter 2. I want to explain why I am
calling it a local header file and why we need to make it a “global header
file”. A local header file is one that can only be used in the current project
you have created it in. It is used to split your project up into small sections
so that a group of programmers may work on the different sections.
However, it does not fit our purpose as it stands at present. We want to
create a header file that we can use in all our projects that used the same
configuration words. To do that, we must change this local header file
into a global header file, which is one we can use in all our projects that
use the same configuration words. At present, this header file is saved

19
Chapter 1 Introducing MPLABX

in the directory for this project, and therefore only this project will find
the file. What we need to do is save a copy of this file in a place where all
projects will find it. This will be the “include” folder of the XC8 compiler
software we are using within MPLABX. If you are using more than one
compiler version, then you must save a copy in the “include” folder for all
the compiler versions you may use. This folder will most likely be in the
Microchip directory that was created when you installed MPLABX. The
path to the “include” folder I will copy this file into is shown here:

C:\Program Files (x86)\Microchip\xc8\v1.35\include

You will have to find the header file you have just created and the path
to find it on my laptop (Figure 1-16).

Figure 1-16. The first16F88Sim folder and header file

You should remember that I said when you create a project in


MPLABX, the software will create a folder on your system where it will
store all the files for your project.
Once you have found the “include” folder of the compiler software you
use, you can paste a copy of the header file you have just created into the
folder. By creating a copy of the header file, you will get a global header
file that will be available for all our future projects that use the same

20
Chapter 1 Introducing MPLABX

configuration settings. What happens in the other projects, where you have
asked to have the header file included, is that the linker program will go
to the include folder in the compiler software and find the header file you
want to use.
We will look at this more closely when we write our first program in
chapter 2.

Changing the Fonts and Colors


You will notice that I have changed the color of my comments to black
and bold, size 14. This is to try and make them more visible than the
default gray.
If you want to change the color, you can do so by selecting the word
“options” from the drop-down menu that appears when you select the
“tools” and the options choice from the main menu bar. You will get the
window shown in Figure 1-17.

Figure 1-17. Changing the font and colors

21
Chapter 1 Introducing MPLABX

You should click the tag for fonts and colors. Then select what you want
to change. Once you are happy with your choice, click “OK”. I have selected
the fonts and colors and then changed the color of the comments to black,
as shown in Figure 1-17.

The PIC Microcontroller


Just before we finish this first chapter, I think it might be useful to discuss
what a PIC is. Some people say it stands for programmable industrial
controllers, or programmable intelligent controller, or programmable
interface controller. However, some say it is really just a trademark for
the microcontrollers produced by Microchip. The term PIC is used by
Microchip to cover an extremely wide range of microcontrollers produced
by them. I will simply refer to the microcontroller as the PIC.
Each PIC will have all the components of a microprocessor-based
system as shown in Figure 1-18, such as the following:

• a microprocessor

• ROM, RAM

• an I/O chip

• the associated address, data, and control buses.

However, all these parts are all on a single chip, not several chips, as
with older microprocessor-based systems. This means it is really a single-­
chip computer.
As well as all that, the PIC has much more circuitry on the single chip.
This extra circuitry is used to make it into a control system with a micro
at the heart of it. The extra circuit may include an ADC (analog-to-digital
converter), opamp circuits for compare and capture, a PWM module, and
a UART module. These extra circuits may not be on all PICs as PICs vary in
their makeup for different applications.

22
Chapter 1 Introducing MPLABX

Figure 1-18. The basic microprocessor system

One more thing before we move on is that the PIC is a RISC chip as
opposed to a CISC chip. RISC stands for reduced instruction set chip,
whereas CISC stands for complex instruction set chip. Indeed, the
instruction sets for PIC micros range from 35 to 75 core instructions.
However, the 18F4525 has an extended instruction set at your disposal.
The Intel processor, which is a CISC chip, uses hundreds of instructions, so
the PIC is pretty efficient.

23
Chapter 1 Introducing MPLABX

The PIC16F88 and the PIC8F4525


This book is based around using these two PICs. They are both eight-bit
micros, which basically means they have an eight-bit data bus and so take
data in chunks of eight bits, which is referred to as a byte. Microchip also
produces PICs that are 16 bits, 24 bits, and 32 bits. Modern PCs use 64-bit
processors now. However, you shouldn’t think that these two PICs are
old hat and that what you will learn in this book is out of date. First, these
two PICs, especially the PIC18F4525, can perform a wide range of control
functions, as you will find out. It is quite easy to build control boards with
them on simple vero boards, as they come in 18-pin, 20-pin, and 40-pin
dual inline (DIL) chips. I have used the 32-bit PICs from Microchip and
they are 100-pin surface mount devices. The fact that these two eight-­
bit PICs come in DIL packages does make them easy to use and to make
prototype boards with them. When I build my circuit boards, I use the 18
pin, 20-pin, or 40-pin IC sockets so that I don’t have to solder the actual
PICs to my circuits. Also, the ‘C’ language you will learn in this book is the
same ‘C’ language you will use on the 32-bit PICs.
Figures 1-19 and 1-20 show the two PICs we are using. As you grow
in confidence with using these PICs, it will be useful if you downloaded a
copy of the data sheets for the PICs. These can be found on the Microchip
web site. Indeed, as you develop your experience in electronics, you will
need to keep a copy of the datasheet for any device you use. I must have
hundreds of datasheets that I use in all my work.

Figure 1-19. The PIC16F88

24
Chapter 1 Introducing MPLABX

Figure 1-20. The PIC18F4525

Summary
In this chapter, we have learned what an IDE is and how to create a
project within MPLABX, the IDE from Microchip. We have looked at the
importance of header files, and the difference between local and global
header files. We will go on to create our own header files for functions that
we will use in exactly the same way in most of our programs as the book
progresses. We have also looked at what a PIC is and the two PICs we will
be using in this book.
In the next chapter, we will create our first program and learn how to
use the header file we have just created, and other header files, in it. We
will also start our analysis of ‘C’ programs as to how a ‘C’ program works
and how the instructions of the ‘C’ program operate. I hope you will enjoy
reading this book and learn a lot from it. Good luck and happy reading.

25
Another Random Scribd Document
with Unrelated Content
Collation und ihme, Tambour, wegen seines Dolmetschens ein
Trinkgeld. Indessen wurden die begehrte Zugehörungen
herbeigeschafft, nach solchen Springinsfeld in Keller verschlossen,
woraus unmüglich schiene, einen Kerl zu entrinnen[160], dann das
Fenster oder Tagelicht, so auf die Gasse oder den Platz gieng, war
hoch und noch darzu mit gedachtem eisernen Gegitter wohl
verwahret. Der Dolmetsch aber ward fortgelassen, welcher gleich zu
mir kam und mich allen Verlauf berichtete.
Weder ich noch Springinsfeld verschliefen die rechte Zeit, darin die
Leute am härtesten zu schlafen pflegen, sondern nachdem ich das
Gegitter so leicht als einen Rübschnitz hinweg gebrochen, ließe ich
ein Seil hinunter zu meinem Springinsfeld in Keller und zoge ihn
daran samt aller Zugehör zu mir herauf, da ich dann auch den
verlangten schönen Smaragd fande.
Die Beut erfreuete mich bei weitem nicht so sehr als das
Schelmstück, welches mir so wol abgangen war. Der Tambour hatte
sich bereits den Abend zuvor schon aus der Stadt gemacht, mein
Springinsfeld aber spazierte den Tag nach vollbrachter
Schatzerhebung mit andern in der Stadt herum, die sich über den
listigen Dieb verwunderten, eben als man unter den Thoren Anstalt
machte, solchen zu erhaschen. Und nun sihe, Simplice, solcher
Gestalt ist deines Springinsfelds Dexterität durch mich zuwegen
gebracht und ausgeübet worden. Ich erzähle dir auch dieses nur
zum Exempel, dann wann ich dir alle Buben- und Schelmenstück
sagen solte, die er mir zu Gefallen werkstellig machen müssen, so
dorfte ich wetten, es würde mir und dir, wiewol es lustige
Schosen[161] seind, die Zeit zu lang werden; ja wann man alles
beschreiben solte, wie du deine Narrenpossen beschrieben hast, so
würde es ein größer und lustiger Buch abgeben als deine ganze
Lebensbeschreibung. Doch will ich dich noch ein kleines lassen
hören.
Fußnoten:
[147] C y p r i a n i s c h e J u n g f r a u . Justin., H i s t . X V I I I . cap.
5, erzählt, Elissa (Dido) habe nach ihrer Flucht auf Kypros achtzig
Jungfrauen geraubt, die nach der Sitte des Landes an das Ufer
des Meeres geschickt worden waren, um sich dort ihre Aussteuer
zu verdienen.
[148] J e s e b e l, die Gemahlin Ahab's. Jehu, der das Haus Ahab's
ausrottete. 2 Könige 10.
[149] z u F a d e n s c h l a g e n, vom Schneiderhandwerk, ein
Stück mit losen und weiten Stichen zusammennähen, in
Norddeutschland r e i h e n, dann von dem Beginn jeder Arbeit
gebraucht, der Gegensatz ist a u s w i r k e n, die Arbeit fertig
machen. Beide Ausdrücke gebraucht Grimmelshausen im
übertragenen Sinne, selbst z. B. vom Essen.
[150] e i f e r n m i t, eifersüchtig sein auf.
[151] d a e s l a n g h e r u m g i e n g, nachdem die Sache länger
besprochen worden war.
[152] L u t z e r, Blutzer, schweizerische Scheidemünze.
[153] B e z i r k, Umfang.
[154] s t e u e r n, stützen.
[155] d ü n s t e r, düster, dumpf.
[156] d i e G l o c k g e g o s s e n, sprichwörtlich: die Sache
abgemacht.
[157] m e s s e n e, von m ë s s e, mhd., Bronze; diese alte Form
steht hier für messingene, welche Metallmischung um die Mitte
des 16. Jahrh. erfunden wurde.
[158] A . R . A q u a R e g i s, Königswasser, Goldscheidewasser.
[159] v e r b l ü h t, ausgeblüht, gezeitigt zur Hebung.
[160] Wunderliche Construction, jedoch in allen Ausgaben,
A c c u s . c . i n f i n . daß ein Kerl entrinne.
[161] S c h o s e n, c h o s e s, Sachen.
Das zwanzigste Capitel.
Welcher Gestalt Springinsfeld und Courage zween
Italiäner bestohlen.

Als wir uns versahen, wir würden noch lang vor Casal liegen bleiben
müssen, lagen wir nit nur in Zelten, sondern ihrer viel baueten ihnen
auch sonst Hütten aus andern Materialien, sich desto besser in die
Länge zu behelfen. Unter anderen Schacherern befanden sich zween
Mailänder im Lager, die hatten ihnen eine Hütte von Brettern
zugerichtet, ihre Kaufmannswaare desto sicherer darin zu
verwahren, welche da bestunde in Schuhen, Stiefeln, Kollern,
Hemdern und sonst allerhand Kleidungen, beides vor Officierer und
gemeine Soldaten zu Roß und Fuß. Diese thäten mir meines
Bedunkens viel Abtrag[162] und Schaden, indem sie nämlich von den
Kriegsleuten allerhand Beuten von Silbergeschmeid und Juweln um
den halben, ja den vierten Theil ihres Werths erhandelten, welcher
Gewinn mir zum Theil zukommen wäre, wann sie nit vorhanden
gewesen. Solches nun gedachte ich an ihnen aufs wenigst zu
wuchern[163], weil in meiner Macht nit stunde, ihnen das Handwerk
gar niederzulegen.
Unten in der Hütten war die Behaltnus ihrer Waar, und dasselbige
war auch zugleich ihr Gaden[164]; oben auf dem Boden aber unter
dem Dach war ihr Liegerstatt, allwo sie schliefen, wohinauf ungefähr
sieben oder acht Staffeln giengen; und durch den Boden hatten sie
ein offenes Loch gelassen, um dadurch nicht allein desto besser zu
hören, wann etwan Mauser einbrächen, sie zu bestehlen, sondern
auch solche Diebe mit Pistolen zu bewillkommen, mit welchen sie
trefflich versehen waren. Als ich nun selbst wahrgenommen, wie die
Thür ohne sonderlichen Rumor aufzumachen wäre, machte ich
meinen Anschlag gar gering[165]. Mein Springinsfeld muste mir eine
Welle scharfer Dörner in Mannslänge zuwegen bringen, woran auch
beinahe ein Mann zu tragen hatte, und ich füllete eine messene
Spritze mit scharfem Essig. Also versehen, giengen wir beide an die
gedachte Hütte, als jedermann im besten Schlaf war. Die Thür in der
Stille zu öffnen, war mir gar keine Kunst, weil ich zuvor alles fleißig
abgesehen; und da solches vollbracht und geschehen, stackte
Springinsfeld die Dornwell vor die Stiegen, als welche vor sich selbst
keine Thür hatte, von welchem Geräusch beide Italiäner erwachten
und zu rumpeln anfiengen. Wir konten uns wol einbilden, daß sie
zum ersten zu obigen Loch herunter schauen würden, als dann auch
geschahe; ich aber spritzte dem einen die Augen alsobald so voller
Essig, daß ihm seine Vorsichtigkeit in einem Augenblick vergieng;
der ander aber liefe im Hemd und Schlafhosen die Stiegen hinunter
und wurde von der Dornwell so unfreundlich empfangen, daß er
gleichwie auch sein Camerad in solcher unversehenen Begebenheit
und großem Schrecken sich nichts anders einbilden konten, also es
wäre eitel Zauberei und Teufelsgespenst vorhanden. Indessen hatte
Springinsfeld ein Dutzet zusammen gebundene Reuterkoller erwischt
und sich damit fort gemacht, ich aber ließe mich mit einem Stück
Leinwat genügen, drehete mich damit aus und schlug die Thür
hinter mir wieder zu, die beide Welsche also in ihrer Anfechtung
hinterlassend, wovon der eine ohne Zweifel die Augen noch
gewischt, der ander aber noch mit seiner Dornwell zu handeln
gehabt haben wird.
Schaue, Simplice, so konnte ichs, und also habe ich den
Springinsfeld nach und nach abgerichtet. Ich stahle, wie gehöret,
nicht aus Noth oder Mangel, sondern mehrentheils darum, damit ich
mich an meinen Widerwärtigen[166] revangiren möchte.
Springinsfeld aber lernete indessen die Kunst und kam so meisterlich
in die Griff, daß er sich unterstanden hätte, alles zu mausen, es wäre
dann gar mit Ketten an das Firmament geheftet gewesen, und ich
ließe ihn solches auch treulich genießen, dann ich gönnete ihm, daß
er einen eigenen Säckel haben und mit dem halben gestohlenen
Gut, maßen wir solche Eroberungen miteinander theilten, thun und
handeln dörfte, was er wolte. Weil er aber trefflich auf das Spielen
verpicht war, so kam er selten zu großem Geld; und wann er gleich
zu Zeiten den Anfang zu einer ziemlichen Summa zuwegen brachte,
so verblieb er jedoch die Länge nicht in Possession, sintemal ihm
sein unbeständig Glück das Fundament zum Reichthum durch den
unbeständigen Würfel jederzeit wieder hinweg zwackte. Im übrigen
verblieb er mir ganz getreu und gehorsam, also daß ich mir auch
keinen bessern Sclaven in der ganzen Welt zu finden getrauet hätte.
Jetzt höre auch, was er damit verdienet, wie ich ihm gelohnet, und
wie ich mich endlich wieder von ihm geschieden.
Fußnoten:
[162] A b t r a g, Abbruch.
[163] w u c h e r n, reichlich vergelten.
[164] G a d e n, Laden.
[165] g e r i n g, leicht, anstellig, schlau.
[166] W i d e r w ä r t i g e, Gegner, Feinde.
Das einundzwanzigste Capitel.
Erzählung eines Treffens, welches im Schlaf vorgangen.

Kurz zuvor, ehe Mantua von den Unserigen eingenommen wurde,


muste unser Regiment von Casal hinweg und auch in die
Mantuanische Belägerung. Daselbsten liefe mir mehr Wasser auf
meine Mühl als in dem vorigen Läger, dann gleich wie alldorten mehr
Volk war, sonderlich Teutsche, also bekame ich auch mehr Kunden
und Kundenarbeit, davon sich mein Geldhaufen wieder ein
merkliches geschwinder vergrößerte, so daß ich etlichmal Wechsel
nach Prag und anderswohin in die teutsche Reichsstädte
übermachte, bei welcher glücklichen Prosperität, großem täglichen
Gewinn und genugsamem Ueberfluß, dessen ich und mein Gesindel
genossen, da sonst mancher Hunger und Mangel leiden muste, mein
Springinsfeld anfienge allerdings das Junkernhandwerk zu treiben. Er
wolte eine tägliche Gewohnheit daraus machen, nur zu fressen und
zu saufen, zu spielen und spazieren zu gehen und zu faulenzen, und
ließe allerdings die Handelschaft der Marquetenterei und die
Gelegenheiten, sonsten irgends etwas zu erschnappen, ein gut Jahr
haben. Ueber das hatte er auch etliche ungerathene und
verschwenderische Cameraden an sich gehenkt, die ihn verführten
und zu allem demjenigen untüchtig machten, worzu ich ihn zu mir
genommen und auf allerlei Art und Weise abgeführet[167] hatte.
»Ha«, sagten sie, »bist du ein Mann, und läst deine Hur beides über
dich und das Deinige Meister sein? Es wäre noch genug, wann du
ein böses Eheweib hättest, von deren du dergleichen leiden müstest.
Wann ich in deinem Hemd verborgen stäke, so schlüg ich sie, biß sie
mir parirte, oder jagte sie vor alle Teufel hinweg.«
Solches alles vernahm ich bei Zeiten mit großem Unwillen und
Verdruß und gedacht auf Mittel und Weg, wie ich meinen
Springinsfeld möchte ins Feld springen machen, ohne daß ich mich
im geringsten etwas dergleichen gegen ihm oder seinem Anhang
hätte vermerken lassen. Mein Gesind, darunter ich auch vier starke
Tremel[168] zu Knechten hatte, war mir getreu und auf meiner
Seiten; alle Officierer des Regiments waren mir nicht übel gewogen;
der Obrist selbst wolte mir wol und die Obristin noch viel besser, und
ich verbande mir alles noch mehrers mit Verehrungen, wo ich
vermeinte, daß ich Hülf zu meinem künftigen Hauskrieg zu hoffen
hätte, dessen Ankündigung ich stündlich von meinem Springinsfeld
gewärtig war. Ich wuste wol, daß der Mann, welchen mir
Springinsfeld aber nur p r o f o r m a repräsentiren muste, das Haupt
meiner Marquetenterei darstellte, und daß ich unter dem Schatten
seiner Person in meiner Handelschaft agirte, auch daß ich bald
ausgemarquetentert haben würde, wann ein solches Haupt mir
mangelte. Derohalben gieng ich gar behutsam; ich gab ihm täglich
Geld, beides zu spielen und zu banquetieren, nicht daß ich die
Beständigkeit seiner vorigen Verhaltung bestätigen wollen, sondern
ihn desto kirrer, verwegener und ausgelassener gegen mir zu
machen, damit er sich dardurch verplumpen und durch ein
rechtschaffenes grobianisches Stückel dem Besitz meiner und des
Meinigen sich unwürdig machen, mit einem Wort, daß er mir Ursach
geben solte, mich von ihme zu scheiden; dann ich hatte allbereit
schon so viel zusammen geschunden und verdienet, zumalen auch
anderwärtshin in Sicherheit gebracht, daß ich mich weder um ihn
noch die Marquetenterei, ja um den ganzen Krieg, und was ich noch
darin kriegen und hinweg nehmen konte, wenig mehr bekümmerte.
Aber ich weiß nicht, ob Springinsfeld das Herz nicht hatte, seinen
Cameraden zu folgen, um die Oberherrschaft offentlich von mir zu
begehren, oder ob er sonst in erzähltem seinem liederlichen Leben
unachtsamer Weis fortfuhre, dann er stellte sich gar freundlich und
demüthig und gab mir niemalen kein sauern Blick, geschweige ein
böses Wort. Ich wuste sein Anliegen wol, worzu ihn seine
Cameraden verhetzt hatten; ich konte aber aus seinen Werken nicht
spüren, daß er etwas dergleichen wider mich zu unterstehen
bedacht gewesen wäre. Doch schickte sichs endlich wunderbarlich,
daß er mich offendirte, wessentwegen wir dann, es sei ihm nun
gleich lieb oder leid gewesen, von einander kamen.
Ich lag einsmals neben ihm und schlief ohne alle Sorg, als er eben
mit einem Rausch heimkommen war. Sihe, da schlug er mich mit der
Faust von allen Kräften ins Angesicht, daß ich nicht allein darvon
erwachte, sondern das Blut liefe mir auch häufig zum Maul und der
Nasen heraus, und wurde mir von selbigem Streich so törmisch[169]
im Kopf, daß mich noch Wunder gibt, daß er mir nit alle Zähn in Hals
geschlagen. Da kan man nun wol erachten und abnehmen, was ich
ihm vor eine andächtige Letenei[170] vorbetete. Ich hieße ihn einen
Mörder und was mir sonst noch mehr von dergleichen ehrbaren
Tituln ins Maul kommen. Er hingegen sagte: »Du Hundsfut, warum
läßest du mir mein Geld nicht? Ich hab es ja redlich gewonnen!«
Und wolte noch immer mehr Stöße hergeben, also daß ich zu
schaffen hatte, mich deren zu erwehren, maßen wir beede im Bette
aufrecht zu sitzen kamen und gleichsam anfiengen mit einander zu
ringen. Und weil er noch fort und fort Geld von mir haben wolte,
gabe ich ihm eine kräftige Ohrfeigen, die ihn wieder niederlegte; ich
aber wischt zum Zelt hinaus und hatte ein solches Lamentiren, daß
nit nur meine Mutter und übriges Gesind, sondern auch unsere
Nachbaren davon erwachten und aus ihren Hütten und Gezelten
hervorkrochen, um zu sehen, was da zu thun oder sonst vorgangen
wäre. Dasselbe waren lauter Personen vom Stab, als welche
gemeiniglich hinter die Regimenter zu den Marquetentern logirt
werden, nämlich der Caplan, Regimentsschultheiß,
Regimentsquartiermeister, Proviantmeister, Profos, Henker,
Hurenwaibel und dergleichen; denen erzählet ich ein langs und ein
breits, und der Augenschein gab auch, wie mich mein schöner Mann
ohne einige Schuld und Ursach tractirt. Mein angehender[171]
milchweißer Busem war überall mit Blut besprengt, und des
Springinsfelds unbarmherzige Faust hatte mein Angesicht, welches
man sonst niemalen ohne lustreizende Lieblichkeiten gesehen, mit
einem einzigen Streich so abscheulich zugerichtet, daß man die
Courage sonst nirgends bei als an ihrer erbärmlichen Stimme
kennete, ohnangesehen niemands vorhanden war, der sie
anderwärts jemalen hätte klagen hören. Man fragte mich um die
Ursach unserer Uneinigkeit und daraus erfolgten Schlacht. Weil ich
nun allen Verlauf erzählte, vermeinte der ganze Umstand,
Springinsfeld müste unsinnig worden sein; ich aber glaubte, er habe
dieses Spiel aus Anstiftung seiner Cameraden und Saufbrüder
angefangen, um mir erstlich hinter die Hosen, zweitens hinter die
Oberherrlichkeit und letzlich hinter mein vieles Geld zu kommen.
Indem wir nun so miteinander pappelten[172], und etliche Weiber
umgiengen, mir das Blut zu stellen[173], grabelte Springinsfeld auch
aus unserem Zelt. Er kam zu uns zum Wachtfeuer, das bei des
Oberisten Bagage brante, und wuste beinahe nicht Wort genug zu
ersinnen und vorzubringen, mich und jedermann wegen seines
begangenen Fehlers um Verzeihung zu bitten. Es mangelte wenig,
daß er nicht vor mir auf die Knie niederfiel, um Vergebung und die
vorige Huld und Gnad wieder von mir zu erlangen; aber ich
verstopfte die Ohren und wolte ihn weder wissen noch hören, biß
endlich unser Obristleutenant von der Rund darzu kam, gegen
welchen er sich erboten, einen leiblichen Eid zu schweren, daß ihm
geträumt hätte, er wäre auf dem Spielplatz gesessen, allwo ihm
einer um eine ziemliche Schanz[174] auf dem Spiel gestandenen
Gelds unrecht thun wollen, gegen welchem er deswegen geschlagen
und wider seinen Willen und Meinung seine liebe unschuldige Frau
im Schlaf getroffen. Der Obristleutenant war ein Cavalier, der mich
und alle Huren wie die Pest haßte, hingegen aber meinem
Springinsfeld nit ohngewogen war; derowegen sagte er zu mir, ich
solte mich wieder mit ihm alsobald in die Zelt packen und das Maul
halten, oder er wolte mich zum Profosen setzen und wol gar, wie ich
vorlängsten verdient, mit Ruthen aushauen lassen.
Potz Blech, das ist ein herber Sentenz, dieser Richter gibts[175] nicht
viel! gedachte ich bei mir selber; aber es schadet nichts; bist du
gleich Obristleutenant und beides vor meiner Schönheit und meinen
Verehrungen schußfrei, so seind doch andere, und zwar deren mehr
als einer, die sich gar gern dadurch berücken lassen, mir recht zu
geben.
Ich schwieg so still wie ein Mäusel; mein Springinsfeld aber auch, als
dem er sagte, wann er noch mehrmal so kommen würde, so wolte
er ihn bei Tag auf einmal dergestalt strafen um das, was er bei
Nacht zu zweien malen gegen mir gesündigt, daß er gewißlich das
dritte mal nicht wieder kommen würde; uns beiden zugleich aber
sagte er, wir solten den Frieden machen, ehe die Sonne aufgieng,
damit er den künftigen Morgen kein Ursach hätte, uns einen
Tädigsmann[176] zu geben, aber über dessen Procedere[177] wir uns
hinter den Ohren zu kratzen würden Ursachen haben. Also giengen
wir wieder mit einander zu Bette und hatten beiderseits unsere
Stöße, maßen ich dem Springinsfeld so wenig gefeiret als er mir. Er
bekräftigt nochmals seinen gehabten Traum mit großen Schwüren,
ich aber behauptete, daß alle Träume falsch wären, derentwegen ich
aber nichts desto weniger keine falsche Maulschelle bekommen. Er
wolte mit den Werken seine Liebe bezeugen, aber der empfangene
Streich, oder vielmehr daß ich seiner gern los gewest wäre,
entzogen ihm bei mir alle Willfährigkeit. Ja ich gab ihm auch den
andern Tag nicht allein kein Geld mehr zum Spielen, sondern auch
zum Saufen, und sonst wenig guter Wort; und damit er mir nicht
hinter die Batzen käme, die ich noch bei mir behalten, unser
Handelschaft damit zu treiben, verbarg ich solche hinter meine
Mutter, welche solche so Tags so Nachts wol eingenähet auf ihrem
bloßen Leib tragen muste.
Fußnoten:
[167] a b f ü h r e n, wie anführen, anleiten, namentlich zum
Schlechten.
[168] T r e m e l, Trämel, Prügel, Bengel.
[169] t ö r m i s c h, schwindlig.
[170] L e t e n e i, soll heißen Litanei.
[171] a n g e h e n d, sich hebend, schwellend.
[172] p a p p e l n, n s . babbeln, schwatzen.
[173] s t e l l e n, zum Stehen bringen, stillen.
[174] S c h a n z, c h a n c e, Einsatz.
[175] g i b t s, fehlt in allen Ausgaben.
[176] T ä d i g m a n n, (Theidungsmann) Vermittler in einem
Streit, Schiedsrichter.
[177] P r o c e d e r e, Vorgehen, Verfahren.
Das zweiundzwanzigste Capitel.
Aus was Ursachen Springinsfeld und Courage sich
gescheiden, und wormit sie ihn zur Letze[178] begabt.

Gleich nach dieser unserer nächtlichen Schlacht stunde es wenig Zeit


an, daß Mantua mit einem Kriegspossen[179] eingenommen wurde,
ja der Fried selbst zwischen den Römisch-Kaiserlichen und
Franzosen, zwischen den Herzogen von Savoia und Nivers[180] folgte
ohnlängst hernach, gleichsam als wann der welsche Krieg mit
unserm Treffen hätte geendigt werden müssen. Und eben deswegen
giengen die Franzosen aus Savoya und stürmeten wieder in
Frankreich, die kaiserliche Völker aber in Teutschland, zu sehen, was
der Schwed machte, mit denen ich dann so wol fortschlendern
muste, als wann ich auch ein Soldat gewesen wäre. Wir wurden, uns
entweder zu erfrischen, oder weil die rothe Ruhr und die Pest selbst
unter uns regierte, an einem Ort in den kaiserlichen Erblanden
etliche Wochen an die Donau ins freie Feld mit unserem Regiment
logirt, da es mir bei weitem nicht solche Bequemlichkeiten setzte wie
in dem edlen Italia. Doch behalfe ich mich, so gut als ich konte, und
hatte mit meinem Springinsfeld, weil er mehr als eine Hundsdemuth
gegen mir verspüren ließe, den Frieden wiederum, doch nur p r o
f o r m a, geschlossen; dann ich laurete täglich auf Gelegenheit,
vermittelst deren ich seiner los werden möchte.
Solcher mein inniglicher Wunsch widerfuhre mir folgender Gestalt,
welche Begebenheit genugsam bezeuget, daß ein vorsichtiger,
verständiger, ja unschuldiger Mann, dem wachend und nüchtern
weder Weib, Welt noch der Teufel selbst nicht zukommen kan, gar
leichtlich durch seine eigene blöde Gebrechlichkeit schlaf- und
weintrunkener Weis in alles Unheil und Unglück gestürzt und also
um alles sein Glück und Wolfahrt gebracht werden mag.
Gleichwie nun aber ich in meinem Gemüth auch um die
allergeringste Schmach und vermeinte zugefügte Unbillichkeit ganz
rachgierig und unversöhnlich war, als erzeigte sich auch mein Leib,
wann er im geringsten verletzt würde, gleichsam ganz unheilsam.
Nicht weiß ich, ob derselbe dem Gemüth nachähmte, oder ob die
Zärte meiner Haut und sonderbaren Complexion so grobe Stöße wie
ein Salzburger Holzbauer nicht ertragen konte; einmal ich hatte
meine blaue Fenster und von Springinsfelds Faust die Wahrzeichen
noch in meinem sonst zarten Angesicht, die er mir im Lager von
Mantua eingetränkt, da er mich in obbemeldten Lager an der Donau,
als ich abermal mitten im besten Schlaf lag, bei der Mitten kriegte,
auf die Achsel nahm, mit mir also im Hemd, wie er mich ertappt
gehabt, gegen des Obristen Wachtfeuer zuliefe und mich allem
Ansehen nach hinweg werfen wolte. Ich wuste, nachdem ich
erwachte, zwar nicht, wie mir geschahe, aber gleichwol merkte ich
meine Gefahr, da ich mich ganz nackend befande und den
Springinsfeld mit mir so schnell gegen dem Feuer zueilen sahe.
Derowegen fienge ich an zu schreien, als wann ich mitten unter die
Mörder gefallen wäre. Davon erwachte alles im Läger, ja der Obrist
selbst sprang mit seiner Partisan aus seiner Zelten, und andere
Officier mehr, welche kamen der Meinung, einen entstandenen
großen Lärmen zu stillen, dann wir hatten damals ganz keine
Feindsgefahr, sondern aber nichts anders als ein schönes lächerliches
Einsehen und närrisches Spectacul. Ich glaube auch, daß es recht
artlich und kurzweilig anzuschauen gewesen sein muß. Die Wacht
empfienge den Springinsfeld mit seiner unwilligen und schreienden
Last, ehe er dieselbige ins Feuer werfen konte; und als sie solche
nackend sahen und vor seine Courage erkanten, war der Corporal so
ehrliebend, mir einen Mantel um den Leib zu werfen. Indessen
kriegten wir einen Umstand von allerhand hohen und niedern
Officiern, der sich schier zu Tod lachen wolte und welchem nicht
allein der Obrist selbst, sondern auch der Obristeleutenant
gegenwärtig war, der allererst neulich den Frieden zwischen mir und
dem Springinsfeld durch Drohung gestiftet hatte.
Als indessen Springinsfeld sich wieder witzig stellte, oder, ich weiß
selbst schier nit, wie es ihm ums Herz war, als er wieder zu seinen
sieben Sinnen kommen, fragte ihn der Obriste, was er mit dieser
Gugelfuhr[181] gemeint hätte. Da antwortet er, ihm hätte geträumt,
seine Courage wäre überall mit giftigen Schlangen umgeben
gewesen, derowegen er sie seinem Einfall nach, sie zu erretten und
davon zu befreien, entweder in ein Feuer oder Wasser zu tragen vors
Beste gehalten, hätte sie auch zu solchem Ende aufgepackt und
wäre, wie sie alle vor andern sehen, also mit ihr daher kommen,
welches ihm mehr als von Grund seines Herzens leid seie. Aber
beides der Obrist selbst und der Obristleutenant, der ihm vor Mantua
beigestanden, schüttelten die Köpf darüber und ließen ihn, weil sich
schon jedermann satt genug gelacht hatte, vor die lange Weil zum
Profosen führen, mich aber in mein Gezelt gehen, vollends
auszuschlafen.
Den folgenden Morgen gieng unser Proceß an und solte auch gleich
ausgehen[182], weil sie im Krieg nicht so lang zu währen pflegen als
an einigen Orten im Frieden. Jederman wuste zuvor wol, daß ich
Springinsfelds Ehefrau nicht war, sondern nur seine Matreß, und
dessentwegen bedorften wir auch vor kein Consistorium zu kommen,
um uns scheiden zu lassen, welches ich begehrte, weil ich im Bette
meines Lebens bei ihm nicht sicher war; und eben dessentwegen
hatte ich einen Beifall schier von allen Assessoribus, die davor
hielten, daß ein solche Ursach auch eine rechte Ehe scheiden könte.
Der Obristleutenant, so vor Mantua ganz auf Springinsfelds Seiten
gewesen, war jetzt ganz wider ihn, und die übrige vom Regiment
schier alle auf meiner Seiten. Demnach ich aber mit meinem
Contract schriftlich hervorkam, was Gestalt wir beisammen zu
wohnen einander versprachen biß zur ehrlichen Copulation, zumalen
meine Lebensgefahr, die ich künftig bei einem solchen Ehegatten zu
sorgen hätte, trefflich aufzumutzen und vorzuschützen wuste, fiel
endlich der Bescheid, daß wir bei gewisser Strafe von einander
gescheiden und doch verbunden sein solten, uns um dasjenig, so wir
miteinander errungen und gewonnen, zu vergleichen. Ich replicirte
hingegen, daß solches Letzte wider den Accord unserer ersten
Zusammenfügung laufe, und daß Springinsfeld, seit er mich bei ihm
hätte, oder, teutscher zu reden, seit ich ihn zu mir genommen und
die Marquetenterei angefangen, mehr verthan als gewonnen hätte,
welches ich dann mit dem ganzen Regiment beweisen und darthun
könte. Endlich hieße es, wann der Vergleich nach Billichkeit solcher
Umstände zwischen uns beeden selbst nicht gütlich getroffen
werden könte, daß alsdann nach befindenden Dingen von dem
Regiment ein Urthel gesprochen werden solte.
Ich ließe mich mit diesem Bescheid mehr als gern genügen, und
Springinsfeld ließe sich auch gern mit einem Geringen
beschlagen[183]; dann weil ich ihn und mein Gesind nach dem
eingehenden Gewinn und also nit mehr wie in Italia tractirte, also
daß es schiene, als ob der Schmalhans bei uns anklopfen wolte,
vermeinte der Geck, es wäre mit meinem Geld auf der Neige und bei
weitem nicht mehr so viel vorhanden, als ich noch hatte und er nicht
wuste. Und es war billich, daß ers nicht wuste, dann er wuste ja
auch nicht, warum ich damit so halsstarrig zuruck hielte.
Eben damals, Simplice, wurde das Regiment Dragoner, darunter du
etwan zu Soest dein A-b-c gelernet hast, durch allerhand junge
Bursch, die sich hin und wieder bei den Officiern der Regimenter zu
Fuß befanden und nun erwachsen waren, aber keine Musquetierer
werden wolten, verstärkt, welches eine Gelegenheit vor den
Springinsfeld war, wessentwegen er sich auch mit mir in einen desto
leidenlichern[184] Accord einließe, den wir auch allein miteinander
getroffen, solcher Gestalt: Ich gab ihm das beste Pferd, das ich
hatte, samt Sattel und Zeug, item einhundert Ducaten baar Geld und
das Dutzet Reuterkoller, so er in Italia durch meine Anstalt[185]
gestohlen; dann wir hatten uns bißher damit nicht dörfen sehen
lassen. Damit wurde auch eingedingt, daß er mir zugleich meinen
Spiritus familiaris um eine Kron abkaufen solte, welches auch
geschahe. Und in solcher Maß habe ich den Springinsfeld
abgeschafft und ausgesteuret. Jetzt wirst du auch bald hören, mit
was vor einer seinen Gab ich dich selbst beseligt und deiner Thorheit
im Sauerbrunnen belohnet hab. Habe nur eine kleine Geduld und
vernimm zuvor, wie es dem Springinsfeld mit seinem Ding im Glas
gangen.
Sobald er solches hatte, bekam er Würm über Würm im Kopf. Wann
er nur einen Kerl ansahe, der ihme sein Tage niemal nichts Leids
gethan, so hätte er ihn gleich an Hals schlagen mögen; und er
spielte auch in allen seinen Duellen den Meister. Er wuste alle
verborgene Schätze zu finden und andere Heimlichkeiten mehr, hier
ohnnöthig zu melden. Demnach er aber erfuhre, was vor einen
gefährlichen Gast er herbergte, trachtete er seiner los zu werden. Er
konte ihn aber drum nicht wieder verkaufen, weil der Satz oder der
Schlag seines Kaufschillings aufs Ende kommen war. Ehe er nun
selbst Haar lassen wolte, gedachte er mir denselbigen wieder
anzuhenken und zuruck zu geben, wie er mir ihn dann auch auf dem
General-Rendezvous, als wir vor Regenspurg ziehen wolten, vor die
Füße warf. Ich aber lachte ihn nur aus, und solches zwar nicht
darum vergebens, dann ich hube ihn nicht allein nicht auf, sondern
da Springinsfeld wieder in sein Quartier kam, da fande er ihn wieder
in seinem Schubsack. Ich hab mir sagen lassen, er habe den Bettel
etlichmal in die Donau geworfen, ihn aber alleweg wieder in seinem
Sack gefunden, biß er endlich denselbigen in einen Bachofen
geworfen und also seiner los worden. Indessen er sich nun so
hiermit schleppte, wurde mir ganz ungeheuer[186] bei der Sach;
derowegen versilberte ich, was ich hatte, schaffte mein Gesind ab
und setzte mich mit meiner böhmischen Mutter nach Passau,
vermittelst meines vielen Gelds des Kriegs Ausgang zu erwarten,
sintemal ich zu sorgen hatte, wann Springinsfeld solches Kaufs und
Verkaufs halber über mich klagen würde, daß mir alsdann als einer
Zauberin der Proceß gemacht werden dörfte.
Fußnoten:
[178] L e t z e, Abschiedsmahl, Abschied.
[179] K r i e g s p o s s e n, Kriegslist.
[180] Vgl. die Einleitung.
[181] G u g e l f u h r, Kappenfahrt, Narrenaufzug.
[182] a u s g e h e n, zu Ende gelangen.
[183] b e s c h l a g e n, reichlich versehen, ausrüsten, vgl. gut
beschlagen sein, befriedigen, abfinden.
[184] l e i d e n l i c h, leidlich, erträglich.
[185] A n s t a l t, Veranstaltung.
[186] u n g e h e u e r, wie nicht geheuer, unheimlich.
Das dreiundzwanzigste Capitel.
Wie Courage abermal einen Mann verloren und sich
darnach gehalten habe.

Zu Passau schlug es mir bei weitem nicht so wol zu, als ich mich
versehen hatte. Es war mir gar zu pfäffisch und zu andächtig; ich
hätte lieber an Statt der Nonnen Soldaten oder an Statt der Mönche
einige Hofbursch dort sehen mögen, und gleichwol verharrete ich
daselbsten, weil damals nicht nur Böhmen, sondern auch fast alle
Provinzen des Teutschlandes mit Krieg überschwemmt waren. Indem
ich nun sahe, daß alles der Gottesforcht daselbst zugethan zu sein
schiene, accommodirte ich mich gleichfalls aufs wenigst äußerlich
nach ihrer Weis und Gewohnheit; und was mehr ist, so hatte meine
böhmische Mutter oder Kostfrau das Glück, daß sie an diesem
andächtigen Ort unter dem Glanz der angenommenen Gottseligkeit
den Weg aller Welt gieng, welche ich dann auch ansehenlicher
begraben ließe, als wann sie zu Prag bei S. Jacobs Thor gestorben
wäre. Ich hielte es vor ein Omen meiner künftigen Unglückseligkeit,
weil ich nunmehr niemanden auf der Welt mehr hatte, dem ich mich
und das Meinige rechtschaffen hätte vertrauen mögen, und
derentwegen haßte ich den unschuldigen Ort, darin ich meiner
besten Freundin, Säugammen und Auferzieherin war beraubt
worden. Doch patientirt ich mich daselbst, biß ich Zeitung bekam,
daß der Wallensteiner Prag, die Hauptstadt meines Vatterlands,
eingenommen und wiederum in des Römischen Kaisers Gewalt
gebracht; dann auf solche erlangte Zeitung und weil der Schwed zu
München und in ganz Baiern dominirt, zumalen in Passau
seinetwegen große Forcht war, machte ich mich wieder in besagtes
Prag, wo ich mein meistes Geld liegen hatte.
Ich war aber kaum dort eingenistelt, ja ich hatte mich noch nicht
recht daselbst gesetzt, mein zusammengeschundenes Geld und Gut
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like