100% found this document useful (2 votes)
35 views

Instant Access to (Ebook) Pic Projects and Applications Using C. A Project-based Approach by David W. Smith (Auth.) ISBN 9780080971513, 0080971512 ebook Full Chapters

The document provides information on downloading the ebook 'PIC Projects and Applications Using C' by David W. Smith, which focuses on programming PIC microcontrollers using the C language. It includes details about the book's content, such as practical applications and programming techniques, along with links to additional related ebooks. The book is designed for readers with varying levels of experience in C programming, emphasizing hands-on project development and understanding of microcontroller functionalities.

Uploaded by

chuanubaydim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
35 views

Instant Access to (Ebook) Pic Projects and Applications Using C. A Project-based Approach by David W. Smith (Auth.) ISBN 9780080971513, 0080971512 ebook Full Chapters

The document provides information on downloading the ebook 'PIC Projects and Applications Using C' by David W. Smith, which focuses on programming PIC microcontrollers using the C language. It includes details about the book's content, such as practical applications and programming techniques, along with links to additional related ebooks. The book is designed for readers with varying levels of experience in C programming, emphasizing hands-on project development and understanding of microcontroller functionalities.

Uploaded by

chuanubaydim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Pic Projects and Applications Using C. A


Project-based Approach by David W. Smith (Auth.)
ISBN 9780080971513, 0080971512

_____ Click the link below to download _____


https://ebooknice.com/product/pic-projects-and-
applications-using-c-a-project-based-approach-4434370

Explore and download more ebooks at ebooknice.com


Here are some recommended products that might interest you.
You can download now and explore!

(Ebook) PIC in Practice, Second Edition: A Project -based


Approach by David W Smith ISBN 9780080464985,
9780750668262, 008046498X, 0750668261
https://ebooknice.com/product/pic-in-practice-second-edition-a-
project-based-approach-1948576

ebooknice.com

(Ebook) Batik Gems: 29 Dazzling Quilt Projects by Laurie


J. Shifrin ISBN 9781571205605, 1571205608

https://ebooknice.com/product/batik-gems-29-dazzling-quilt-
projects-4447316

ebooknice.com

(Ebook) Vagabond, Vol. 29 (29) by Inoue, Takehiko ISBN


9781421531489, 1421531488

https://ebooknice.com/product/vagabond-vol-29-29-37511002

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) Classical Hopf Algebras and Their Applications
(Algebra and Applications, 29) by Pierre Cartier, Frédéric
Patras ISBN 9783030778446, 3030778444
https://ebooknice.com/product/classical-hopf-algebras-and-their-
applications-algebra-and-applications-29-34794516

ebooknice.com

(Ebook) Information & Software Technology: A project-based


approach by David Grover, Heather Knights, Eamon Gormley
ISBN 9781442539129, 1442539127
https://ebooknice.com/product/information-software-technology-a-
project-based-approach-49191184

ebooknice.com

(Ebook) PIC Microcontroller Projects in C. Basic to


Advanced by Dogan Ibrahim (Auth.) ISBN 9780080999241,
0080999247
https://ebooknice.com/product/pic-microcontroller-projects-in-c-basic-
to-advanced-4674732

ebooknice.com

(Ebook) Embedded C Programming: Techniques and


Applications of C and PIC MCUS by Mark Siegesmund ISBN
9780128013144, 0128013141
https://ebooknice.com/product/embedded-c-programming-techniques-and-
applications-of-c-and-pic-mcus-4913034

ebooknice.com

(Ebook) Business statistics: a decision-making approach by


Groebner, David F;Shannon, Patrick W;Smith, Kent D;Fry,
Phillip C ISBN 9780136121015, 9787320105196, 0136121012,
7320105195
https://ebooknice.com/product/business-statistics-a-decision-making-
approach-22041288

ebooknice.com
Pic Projects and Applications Using C A Project based
Approach 3rd ed Edition David W. Smith (Auth.) Digital
Instant Download
Author(s): David W. Smith (Auth.)
ISBN(s): 9780080971513, 0080971512
Edition: 3rd ed
File Details: PDF, 20.36 MB
Year: 2013
Language: english
PIC Projects and
Applications using C
PIC Projects and
Applications using C
A Project-based Approach
Third edition

David W. Smith

AMSTERDAM • BOSTON • HEIDELBERG • LONDON


NEW YORK • OXFORD • PARIS • SAN DIEGO
SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO
Newnes is an imprint of Elsevier
Newnes is an imprint of Elsevier
The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, UK
225 Wyman Street, Waltham, MA 02451, USA
First edition 2002
Second edition 2006
Third edition 2013
Copyright © 2013 Elsevier Ltd. All rights reserved
No part of this publication may be reproduced or transmitted in any form or by
any means, electronic or mechanical, including photocopying, recording, or any
information storage and retrieval system, without permission in writing from the
publisher. Details on how to seek permission, further information about the Publisher’s
permissions policies and our arrangement with organizations such as the Copyright
Clearance Center and the Copyright Licensing Agency, can be found at our website:
www.elsevier.com/permissions.
This book and the individual contributions contained in it are protected under
copyright by the Publisher (other than as may be noted herein).
Notice
Knowledge and best practice in this field are constantly changing. As new research
and experience broaden our understanding, changes in research methods, professional
practices, or medical treatment may become necessary.
Practitioners and researchers must always rely on their own experience and
knowledge in evaluating and using any information, methods, compounds, or
experiments described herein. In using such information or methods they should be
mindful of their own safety and the safety of others, including parties for whom they
have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or
editors, assume any liability for any injury and/or damage to persons or property as a
matter of products liability, negligence or otherwise, or from any use or operation of
any methods, products, instructions, or ideas contained in the material herein.
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library
Library of Congress Cataloging-in-Publication Data
A catalog record for this book is available from the Library of Congress
ISBN: 978-0-08-097151-3

For information on all Newnes publications


visit our website at www.books.elsevier.com

13 14 15 16  10 9 8 7 6 5 4 3 2 1

Printed in the United States of America


Preface

The aim of this book is to enable the reader to program the 18F series of
PIC Microcontrollers in the C language using Microchip’s MPLAB C18 com-
piler. The program examples demonstrate the power of the C language, yet the
reader does not have to be a C programmer in order to benefit from this tech-
nology as the C language is added and explained as required.
The chapters show numerous applications starting with switching out-
puts on, then using digital inputs such as switches and keypads. This book
continues with making measurements from analogue inputs, writing to alpha
numeric displays, using timers and interrupts, and transmitting data via radio
links.
There is a section on fault finding using the MPLAB simulator and in-
circuit debugger. So that faults can be located easier.
All of the chapters show applications on how to use the program examples.
The programs are complete and are clearly explained.
My aim has been to show the reader how to use the Microcontroller to
develop programs for projects. I have tried to keep the technical detail down to
a minimum and have not gone into a deeper understanding of how the micro-
controller is working inside. An understanding of the electronics inside the
microcontroller is not necessary to enable the reader to program it.
The reader is encouraged to build the programs, see how they work, and
then modify the code to enable a clearer understanding of the principles
involved; a development kit is available to do this. My own students have been
ingenious in developing faults in code and I have used their efforts, hopefully,
to produce an easy-to-understand guide to programming the PIC micro in C.
The programs listed in this book and the details of the development kit
are available from the book’s companion website: http://booksite.elsevier.
com/9780080971513.
DW Smith BSc., MSc.
Lecturer in Electronics, Manchester Metropolitan University
April 2013

ix
Chapter 1

Introduction to the
Microcontroller and C
A microcontroller is an integrated circuit that has a number of memory
locations embedded inside it which are used to store instructions that are to be
executed. These locations are called registers, and instructions are written to
these registers to enable the microcontroller to perform an operation.
The memory location is 8 bits wide which means it can store 8 bits of
information (Figure 1.1). The 8 bits in the memory are identified by numbers
starting on the right with the least significant bit, bit 0, and moving to the left
to the most significant bit, bit 7.
Suppose we wish to turn on an LED connected to an output pin, as shown
in Figure 1.2. An instruction has to be written to the output port register to out-
put a logic 1 to turn the LED on or output a logic 0 to turn it off.
The microcontroller we will use in this book is a PIC18F1220 manu-
factured by Microchip, although the codes can easily be adapted for other
Microchip microcontrollers. The PIC18F1220 has 16 inputs/outputs (I/O)
which means it has 16 inputs or outputs which can be configured as inputs
or outputs by instructing the microcontroller via a register, the tristate (TRIS)
register (Figure 1.3). TRIS means the port pin can be (i) an input, or an output
which is switched (ii) high or (iii) low, three states.
The memory locations in the microcontroller are 8 bits wide so 16 I/O will
require two 8 bit registers called PORTA and PORTB.
Suppose we wish to turn on an LED which we are going to connect to bit
4 on PORTB. We first of all have to instruct the microcontroller to ensure that
PORTB bit 4 is an output. At the moment it does not matter what the rest of

Memory location

Bits 7 6 5 4 3 2 1 0
MSB LSB
FIGURE 1.1 A microcontroller memory location.

PIC Projects and Applications using C.


© 2013 David W. Smith. Published by Elsevier Ltd. All rights reserved. 1
2 PIC Projects and Applications using C

B4 10

470R

18F1220 LED1

0v

5v
14
V+

5 0.1 µ
0v
0v

FIGURE 1.2 A basic microcontroller circuit.

TRISB

1 1 1 0 1 1 1 1
Bits 7 6 5 4 3 2 1 0
FIGURE 1.3 The TRIS register.

PORTB

1
Bits 7 6 5 4 3 2 1 0
FIGURE 1.4 Writing to PORTB.

PORTB is doing, so now let’s make bit 4 an output and the other 7 bits inputs.
We do this with the following instruction:
TRISB = 0b11101111;
0b means the number is a binary one.
Note a 1 sets the pin as an input, a 0 sets the pin as an output.
Now that PORTB bit 4 is an output, we can write a logic1 to it with:
PORTBbits.RB4 = 1; (Figure 1.4).
There are several ways in which we can give the microcontroller instruc-
tions, called programming. These program languages are assembly, basic, C,
or a number of flowchart languages. The language that we are going to use in
this book is the C programming language, which is a high-level language that
Chapter | 1 Introduction to the Microcontroller and C 3

is very versatile. The previous book “PIC in Practice” written by the author,
DW Smith, used the assembly language to program the microcontroller.
C is a very comprehensive and versatile language, which usually means
there is a lot to learn. Throughout this book I will introduce the C language as
and when required and only those instructions that are needed to perform the
control. So you will not need to become a C programmer in order to program
the micro in C!
Chapter 2

First C Program

In order to program the microcontroller we are going to:


l Write the code in C.
l Convert the code to a hex file using a compiler.
l Program the hex file into the microcontroller.
The code which we are going to write in the C language can be written on
any text editor such as WORD. Any suitable C compiler can be used to convert
the code to a hex file and there are numerous programmers on the market that
will blow your hex file into the microcontroller.
Throughout this book I am going to use a dedicated piece of software
called MPLAB integrated development environment (IDE) written by the PIC
microcontroller manufacturer, Microchip. This acts as a text editor, compiler,
and driver for the Microchip programmer. MPLAB IDE is free and can be
downloaded from the Microchip Web site at Microchip.com
At the time of writing Microchip have upgraded MPLAB v8 and have
called it MPLABX. I have discussed both IDEs here and left it up to the reader
to decide which one they prefer to use.
MPLAB and MPLABX also include a simulator that help to debug your
code. I use Microchips own programmer/in-circuit debugger (ICD) called
Microchip MPLAB ICD3 and PICkit3. The ICDs allow you to connect your
circuit to the computer so that you can view the registers inside the micro
when the program is running. But we can see more of the simulator and
debugger later.

MPLAB AND MPLABX INSTALLATION


Install the latest version of MPLAB, as of 7/1/2011 that is MPLAB v8.73a.,
and the C compiler is MPLAB C v3.40 LITE. NB. MPLAB and the LITE ver-
sion of the C compiler are free from Microchip.com
Or install MPLABX IDE and the C compiler XC8.
Make a new folder to keep your programs in, say PicProgs on your
desktop.

PIC Projects and Applications using C.


© 2013 David W. Smith. Published by Elsevier Ltd. All rights reserved. 5
6 PIC Projects and Applications using C

RA0/AN0 1 18 RB3/CCP1/P1A

RA1/AN1/LVDIN 2 17 RB2/P1B/INT2

RA4/T0CK1 3 16 OSC1/CLKI/RA7

PIC18F1X20
MCLR/VPP/RA5 OSC2/CLKO/RA6
4 15

VSS/AVss 5 14 VDD/AVDD

RA2/AN2/VREF- RB7/PGD/T1OSI/
6 13
P1D/KBI3
RA3/AN3/VREF+ 7 12 RB6/PGC/T1OSO/
T13CKI/P1C/KBI2
RB0/AN4/INT0 8 11 RB5/PGM/KBI1
RB1/AN5/TX/ 9 10 RB4/AN6/RX/
CK/INT1 DT/KBI0
FIGURE 2.1 The 18F1220 pin diagram.

For our first program we are going to flash an LED on and off at 1 s inter-
vals on the output pin, PORTB,4.
The pin connection for the 18F1220 is shown in Figure 2.1.
But before we program our device we need to understand a little of the C
language.

A BRIEF INTRODUCTION TO C FOR THE MICROCONTROLLER


Turning an output on/off
If we wish to turn an LED on PORTB bit4 on, the C code is:
PORTBbits.RB4 = 1;
This is called a statement. NB all C statements end in ;
If we wish to turn the LED off the code is:
PORTBbits.RB4 = 0;

Delays
In the C language suite we have installed a file called Delay.h. As its name sug-
gests there are a number of routines in this file which can create a delay in our
program. The address for this file if you want to read it is “C:\Program Files\
Microchip\mplabc18\v3.40\h” after installing MPLAB from Microchip.com
The subroutines are:
Delay1TCY()
Delay10TCYx()
Delay100TCYx()
Delay1KTCYx()
Chapter | 2 First C Program 7

Delay10KTCYx()
If you wish to call a subroutine in C you just state its name, i.e.,
Delay1KTCYx();
These delays are multiples of timing cycles, i.e., 1, 10, 100, 1000, and
10,000.
A timing cycle is the time taken to execute an instruction and it is the basis
of the timing in the microcontroller system. The timing comes from the oscil-
lator which can be an external clock source, an external crystal, or an internal
oscillator. For now we are going to use the internal oscillator set at 31.25 kHz.
The timing cycle runs at one-fourth of this frequency, i.e., at 7.8125 kHz.
This means the period of the timing cycle is 0.128 ms.
So the Delay100TCYx() subroutine will have a time of 100×0.128 ms
= 12.8 ms.
In order to achieve a delay of 1 s we would need 78 of these 12.8 ms.
78 × 12.8 ms = 0.9984 s, not quite 1 s but near enough for this application.
To do this the C code is:
Delay100TCYx(78);
Note the number of times the subroutine is executed is written in the
brackets (78) in this case. NB. 255 is the maximum value that can be entered.

Loops
In order to make the program execute some code a number of times or indefi-
nitely, we use a loop.
The WHILE LOOP as it is called looks like this:
while ( )
{
}
The code to be executed is written between the brackets { } while the con-
dition for executing the code is written between the brackets ( )
Suppose we wish to turn an alarm on if the temperature goes above 60°C,
the code would look like:
while (Temperature>60)
{
PORTBbits.RB0 = 1; // turn on PORTB bit0
}
If we wish to execute a piece of code indefinitely such as flashing our LED
on PORTB bit 4 on and off continuously, the loop is:
while (1)
{
PORTBbits.RB4 = 1;      // turn on PORTB bit4
8 PIC Projects and Applications using C

Delay100TCYx(78);     // wait 1 s
PORTBbits.RB4 = 0;     // turn off PORTB bit4
Delay100TCYx(78);    // wait 1 s
}
The function while (1) means while 1 is true! But 1 is always 1, so the loop is
always executing. Note the function while (1) does not end with a ;
The // code means ignore what follows on the line; it is for our reference
not for the compiler.
A useful while loop involves just 1 line of code, i.e.,
while (PORTBbits.RB4==1);
This means continue the loop (just 1 line) until PORTBbits.RB4==1 is
no longer true, i.e., wait until PORTBbits.RB4==0 before moving on in the
program.
Note: == means is equal to,=means equals. One is a question and the other
a statement.

Entering Numbers in the Program


Numbers can be entered in the program as hexadecimal, binary or decimal.
A hexadecimal number 7 F is written as 0 × 7 F.
A binary number 1111 0101 is written as 0b11110101.
A decimal number 45 is just written as 45.
We are now ready to write our C program.
NOTE
In the remainder of this book we will be writing C files and putting them
into projects. You can choose to do this with MPLAB or MPLABX.

WRITING THE CODE USING MPLAB IDE


Run MPLAB and the screen shown in Figure 2.2 will open.
For our first program we are going to flash an LED on and off at 1 s inter-
vals on the output pin, PORTB,4. We will call this, flash.c
Under the file menu select New (or if you have the code Open flash.c)
(Figure 2.3).
The screen shown in Figure 2.4 showing the file editor will open.
If the line numbers are not visible on the left hand side turn them on with
Edit/Properties as shown in Figure 2.5.
Select File Type/Line Numbers.
Click Apply then.
Click OK as shown in Figure 2.6.
We need to open a project to store our code in. The project will contain our
code flash.c and also when we have compiled it a new file, flash.hex which is
the machine code file which will be blown into our microcontroller with the
Chapter | 2 First C Program 9

FIGURE 2.2 MPLAB workspace.

aid of a programmer. The project also contains the workspace which is the
user screen that would show the registers and the watch window. We will use
these later when we look at the simulator.
To make the project, select Project/Project Wizard as shown in Figure 2.7.
Click Next on the dialogue box of Figure 2.8.
Step 1: select the microcontroller you require, the PIC18F1220, from the
Project Wizard as shown in Figure 2.9.
Step 2: select the language toolsuite to use, i.e., the C18 compiler.
If not already selected choose Microchip C18 Toolsuite as your Active
Toolsuite as shown in Figure 2.10.
Then click, Next.
10 PIC Projects and Applications using C

FIGURE 2.3 Creating the file flash.c.

FIGURE 2.4 File editor screen.


FIGURE 2.5 Editor properties.

FIGURE 2.6 Turning on line numbers.


12 PIC Projects and Applications using C

FIGURE 2.7 Selecting the Project Wizard.

FIGURE 2.8 Project Wizard dialogue box.


Chapter | 2 First C Program 13

FIGURE 2.9 Selecting the device.

FIGURE 2.10 Selecting the Microchip C18 Toolsuite.


14 PIC Projects and Applications using C

FIGURE 2.11 Creating a project file.

Step 3: create the project, browse for the directory you have created, i.e.,
PICProgs, and create a new project file, flash, or open it if it is already created,
as shown in Figure 2.11.
Click Save, then.
Click Next.
Step 4: add existing files to your project (Figure 2.12).
At the moment we do not have any existing files. If you have a copy of
flash.c you can add it now. If not just click Next.
That’s the project made.
Chapter | 2 First C Program 15

FIGURE 2.12 Adding a file to your project.

FIGURE 2.13 Finish making the project.

Click Finish (Figure 2.13) to finish making the project and return to the
workspace.
We now have a project called flash saved in the PICProgs folder. Now we
can write our C program called flash.c.
We have already discussed the steps involved in the program.
16 PIC Projects and Applications using C

Flashing an LED On and Off


The LED is connected to PORTB pin 4 and is to be flashed on and off every
second. The circuit for this is shown in Figure 1.2.
The code is:
#include <p18f1220.h>
#pragma config WDT=OFF, OSC=INTIO2, PWRT=ON, LVP=OFF, MCLRE = OFF
#include <delays.h>

void main (void)


{
//SET UP
// OSCCON defaults to 31 kHz. So no need to alter it.
ADCON1 = 0×7 F; //all IO are digital or 0b01111111 in binary
TRISA = 0b11111111;  //sets PORTA as all inputs
PORTA = 0b00000000;  //turns off PORTA outputs, not required, no outputs
TRISB = 0b00000000;  //sets PORTB as all outputs
PORTB = 0b00000000;  //turns off PORTB outputs, good start position
while (1)
{
PORTBbits.RB4 = 1;  // turn on PORTB bit4
Delay100TCYx(78);  // wait 1 s
PORTBbits.RB4 = 0;  // turn off PORTB bit4
Delay100TCYx(78);  // wait 1 s
}
}
If you do not have this file saved click File New as shown in Figure 2.14 and
copy/paste it into the untitled space and then save it in your folder as flash.c.
If you already have the file saved then select Open—PicProg/flash.c
(Figure 2.14).

FIGURE 2.14 Creating a new file.


Chapter | 2 First C Program 17

FIGURE 2.15 Flash.c code entered in MPLAB.

Your screen should look like Figure 2.15 with the code entered.

Explanation of the Code


l Line 1. include, adds the file p18f1220.h to your code. This file has the
names of all the registers and their locations, i.e., ADCON1, TRISA,
18 PIC Projects and Applications using C

PORTA, TRISB, and PORTB. Make sure you use the correct register and
pin names in your code. You can view p18f1220.h to see what the registers
and pins are called.
l Line 2. Pragma describes a task which is performed before the code is
run. Here in the configuration register we are turning the watch dog timer
(WDT) off. The WDT is a timer which will cause the program to reset if
the WDT is not reset. We will not be using this, so do not worry about it,
but turn it off. The oscillator is configured to run internally with OSC =
INT02. The power up timer, PWRT, is turned on by PWRT = ON. This
waits 20 ms after the power is applied before running the program, to give
the voltages time to settle. The low voltage programming, LVP, is turned
off, LVP = OFF because it conflicts with RB5 and the Master Clear is
disabled, MCLRE = OFF because a low on RA5 would clear the program.
We will be adding other pragmas in future programs.
If any of these pragma configs need changing then the codes can be
found in the MPLAB HELP menu under Topics/ PIC18 Config Settings.
l Line 3. We are adding the delays.h file which of course has the delay code
as described earlier.
The header files can be viewed by right clicking on the name in the pro-
gram. To view the delays.h file right click on the #include line and Open
File “delays.h” as shown in Figure 2.15.
l Line 4. It is blank, blank lines make the program easier to read.
l Line 5. Void main (void) is a function or method in C. Void means the
function does not return anything. A function Sum (answer) would return
the answer to an addition. The main function is the point at which the
C code starts running. The main function executes the code between the
brackets { } on lines 6 and 23. Of course more about functions later.
l Line 7. It is a comment explaining that the following code paragraph pro-
vides the initial configuration for our micro.
l Line 8. Another comment explaining the register OSCCON, oscillator con-
trol register, defaults to 31 kHz. This is what we require for this program.
l Line 9. The 18f1220 has seven of its pins that can be used as analogue
inputs when performing an A–D conversion. If we are not using the A–D
then we need to configure the inputs as digital. The default is they are ana-
logue. A 1 in ADCON1, Analogue to digital conversion register 1, sets the
input as digital, a 0 sets the input as analogue.
l Line 10. Sets up the PORTA pins as inputs, a 1 in a TRISA bit sets the cor-
responding pin as an input, a 0 sets the pin as an output.
l Line 11. Sets the PORTA output pins to 0. Not required since the pins are
all inputs.
l Line 12. Configures PORTB pins as all outputs.
l Line 13. Sets all PORTB outputs to 0. A good starting point, all outputs off.
l Line 16. Calls the ‘while function’ which runs continually. The code exe-
cuted by the while function is between the brackets { } line 17 and line 22.
l Line 18. Turns PORTB bit 4 on.
Chapter | 2 First C Program 19

l Line 19 and 21. Call the Delay100TCYx function 78 times, (78).


Delay100TCYx is 100 clock cycles as mentioned previously, giving a total
time of 0.998 s.
l Line 20. Turns PORTB bit 4 off.
Lines 1–13 can be used as a header for all of your programs, modify it to
suit your application.

Add the File to Your Project


If the file hasn’t been added to your project then do it now with File—Add
New File to Project (Figure 2.16).

Compiling the C code


Now that the flash.c file has been added to the project we are ready to convert
it to a format that we can program into the microcontroller.
All we need to do is click on the Build All icon as shown in Figure 2.17.
The Output box shown in Figure 2.18 will be shown and should have
BUILD SUCCEEDED at the bottom. If not the errors will be indicated in the
output box.

Fixing Errors
In my code, line 18, I have introduced a syntax error. I have changed
PORTBbits.RB4 to PORTBbits.4
The error is shown in the output box (Figure 2.19) which ends with the
statement in red, BUILD FAILED.
Clicking on the error in the output box will highlight the error in the code
as indicated.
Fix all of the errors and save your changed code and Build All again. You
should then see BUILD SUCCEEDED in the output box. Once the build has
been successful you have automatically created the HEX file to program in the
microcontroller—in this case flash.hex.

TYPES OF ERRORS
When your program compiles the errors indicated are syntax errors. The com-
piler will not tell you if your program is going to work correctly.
The types of mistakes you could make are:
l Not spelling the Register name correctly.
l Not spelling the Bit name correctly.
l Adding a ; when it is not required.
l Missing a ; when it is required.
l Misspelling a C command.
20 PIC Projects and Applications using C

FIGURE 2.16 Adding a New File to Project.


Chapter | 2 First C Program 21

FIGURE 2.17 Build All.

FIGURE 2.18 Compiling the C code.

PROGRAMMING THE MICROCONTROLLER


Once the code has been compiled (built) correctly you can then program the
hex code into the microcontroller.
There are many programmers on the market, they will require the hex file and
to follow the manufacturer’s instructions. In this book I am going to outline the use
of Microchip’s own programmer the ICD3 shown in Figure 2.20A and the PICkit3
shown in Figure 2.20B. They can program and debug the microcontroller.
Connect the ICD3 or the PICkit3 and the chip holder to the PC according
to the manufacturer’s instructions.
Click “Debugger—Select Tool—None” as shown in Figure 2.21.
Click “Programmer—Select Programmer—MPLAB ICD3” as shown in
Figure 2.22 (or PICkit3).
And finally to program the microcontroller, click the Program target device

icon as shown in Figure 2.23.

The output box should then indicate “Programming succeeded” as indi-


cated in Figure 2.24.
22 PIC Projects and Applications using C

FIGURE 2.19 Indicating errors.

If the programming is not successful check:


l You are using the correct microcontroller.
l The correct microcontroller has been selected on MPLAB.
l The microcontroller is the correct way round in the socket.
l The microcontroller is a good one.
Connect the microcontroller to your circuit and observe the LED flashing.
Now that we have written our first program let us consider switching all
eight outputs on PORTB.
Chapter | 2 First C Program 23

(A)

(B)

FIGURE 2.20 (A) The Microchip ICD3 and (B) The PICkit3.

FIGURE 2.21 Switching off the Debugger.

NOTE
In the remainder of this book we will be writing C files and putting them
into projects. You can choose to do this with MPLAB or MPLABX.
24 PIC Projects and Applications using C

FIGURE 2.22 Selecting the programmer.

FIGURE 2.23 Programming the target device.

FIGURE 2.24 Output box showing a successful programming of the Microcontroller.

WRITING THE CODE USING MPLABX


MPLAB IDE reached version 8 and has recently had a makeover rather than
become version 9; Microchip have called it MPLABX. Version 1.30 is used
here.
Chapter | 2 First C Program 25

Install MPLABX IDE and the C compiler XC8 available from Microchip.
com.
While following this section please also refer to MPLABX IDE User
Guide available from Microchip.
In order to program our code into the microcontroller we will need to build
a project.
Every embedded project contains the following items.
1. Group of files to build a final embedded image.
2. Device the resultant image will be built for, e.g., 18F1220.
3. Compiler to use to build the image; we will be using the XC8.
4. Hardware Tool to be used for debugging/programming the target device.

CREATING A NEW PROJECT


Create a new project in one of two ways:
Select “Create New Project” from the “Learn & Discover” tab of the
MPLAB X Start Page (Figure 2.25)
or
Select File>New Project from the menu bar (Figure 2.26)
1. A project wizard will open to help walk you through the creation of your
project. Select “Microchip Embedded” from Categories and “Standalone
Project” from Projects. Click Next (Figure 2.27).

FIGURE 2.25 Creating a new project.


26 PIC Projects and Applications using C

FIGURE 2.26 Selecting a new project.

FIGURE 2.27 Choosing the project.


Chapter | 2 First C Program 27

FIGURE 2.28 Selecting the device.

2. Select the device you want to use in your project, PIC18F1220. Click Next
(Figure 2.28).
3. Select the Hardware Tool you want to use to either debug your
application or program your target device, e.g., PICkit3. Click Next
(Figure 2.29).
4. Select the compiler toolchain (toolsuite) you want to use to build the output
image of your project, e.g., XC8, Click Next (Figure 2.30).
5. Provide a project name and directory where you want the project to
reside. Click Finish. I have used the Flash program to produce the project
(Figure 2.31).
Your project should now be visible in the “Project” window (Figure
2.32).
You have now created a new embedded project. The next step is to add
your code (C file) to the project.

Adding Source Code to the Project


Now that you have created the project you can add existing or create new
source files within the project. We will add the program flash.C discussed in
the MPLAB section (Figure 2.15).
28 PIC Projects and Applications using C

FIGURE 2.29 Selecting the programming tool.

FIGURE 2.30 Selecting the XC8 compiler.


Chapter | 2 First C Program 29

FIGURE 2.31 Selecting the project name and directory.

FIGURE 2.32 The project window.

Select File>New File to launch a File wizard (Figure 2.33).


1. The project to which the new file will be added is listed in the Project field.
Select the file type (C and C Source File) and click Next (Figure 2.34).
2. Name the file and the location at which to store the file. Click Finish
(Figure 2.35).
A new file will be created, opened in the editor, and placed into the project
identified. Drag and drop the file to place it in the Source Files virtual folder
(if needed) (Figure 2.36).
You can also add existing source files or create new files from the right
click (context) menu (Figure 2.37).
Double click on the source file, in this example flash.C, and the file will
open in the window as shown in Figure 2.38.
30 PIC Projects and Applications using C

FIGURE 2.33 Creating a new file.

FIGURE 2.34 Selecting the file type.

The line numbers can be turned on and off by right clicking the line num-
bers column.
The project is now ready to build, i.e., to convert the C code to hex code
for the chip.
Chapter | 2 First C Program 31

FIGURE 2.35 Locating the file in a folder.

FIGURE 2.36 Adding the file to a folder.

Click the build program icon, the hammer, shown.

The output should show “Build Successful” (Figure 2.39).


32 PIC Projects and Applications using C

FIGURE 2.37 Adding a file to a project.

FIGURE 2.38 Opening a source file in the project window.


Chapter | 2 First C Program 33

FIGURE 2.39 Building the project.

FIGURE 2.40 Programming the code into the Microcontroller.

The program should have built successfully. If not double click the error
statement and correct the errors.
The project hex file is now ready to be programmed into the chip.
Connect the PICkit3 (or any other programmer) to the chip following the
manufacturer’s instructions. Click the program icon as shown in Figure 2.40.
The output box (Figure 2.41) should indicate that the Programming has
been verified and is complete.
Connect the microcontroller to your circuit and observe the LED flashing.
Now that we have written our first program let us consider switching all 8
outputs on PORTB.
34 PIC Projects and Applications using C

FIGURE 2.41 Indicating programming has been completed successfully.


Chapter 3

Using Eight Outputs

FLASHING 8 LEDs.
For this program we are going to flash all eight outputs on PORTB.
Consider the circuit as shown in Figure 3.1.
In order to achieve our objective we will be using the following steps:
l Open MPLAB.
l Create the C file (see Figure 2.3). Call it flash8.c.

13 8680 R
B7
12
B6
11 0V
B5
10 0V
B4
0V
0V
18
B3
17
B2
9 0V
B1
0V
8
B0
0V

0V

5V
V+ 14

0.1 µ

0V 5

0V

FIGURE 3.1 Eight outputs on PORTB.

PIC Projects and Applications using C.


© 2013 David W. Smith. Published by Elsevier Ltd. All rights reserved. 35
36 PIC Projects and Applications using C

l Create a project called flash8, using the Project Wizard (see Figures
2.7–2.13).
l Add flash8.c to your project (see Figure 2.16).
l Compile your project (see Figure 2.18).
l Program your target device (see Figure 2.23).
To create the C file flash8.c copy and paste lines 1–13 of flash.c onto the
file editor screen (see Figure 2.15) and add the following lines of code shown
in Figure 3.2.
NB. The line numbers are not required in the program; they are only
included as a guide.

EXPLANATION OF THE CODE


l Line 17 has written to all 8 bits of PORTB with the instruction
PORTB = 0b11111111.
l Line 18 waits for 1 s.
l Line 19 turns all PORTB outputs off and so on.
In order to compile (build) the code a new project called flash8 must be
made and the file flash8.c added to it.

1. #include <p18f1220.h>
2. #pragma config WDT=OFF , OSC=INTIO2 , PWRT = ON, LVP=OFF, MCLRE = OFF
3. #include <delays.h>
4.
5. void main (void)
6. {
7. //SET UP
8. // OSCCON defaults to 31kHz. So no need to alter it.
9. ADCON1 = 0x7F; //all IO are digital or 0b01111111 in binary
10. TRISA = 0b11111111; //sets PORTA as all inputs
11. PORTA = 0b00000000; //turns off PORTA outputs, not required, no outputs
12. TRISB = 0b00000000; //sets PORTB as all outputs
13. PORTB = 0b00000000; //turns off PORTB outputs, good start position
14.
15. while (1)
16. {
17. PORTB = 0b11111111; // all outputs on
18. Delay100TCYx(78); // wait 1s
19. PORTB = 0b00000000; // all outputs off
20. Delay100TCYx(78); // wait 1s
21.
22. PORTB = 0b10101010; // alternate outputs on
23. Delay100TCYx(78); // wait 1s
24. PORTB = 0b01010101; // alternate outputs on
25. Delay100TCYx(78); // wait 1s
26. }
27. }
FIGURE 3.2 Flash8.c code.
Chapter | 3 Using Eight Outputs 37

If you are confident with what you are doing then you can use the short cut
instead of using the Project Wizard, as follows:
l Select Project—New as shown in Figure 3.3.
l In the New Project box that opens up enter the project name, flash8, and
the directory location, PIC Progs.
l Now add your file to the project with Project—Add files to project as
shown in Figure 3.4.
In the Add files project box enter the file name flash8 and the directory PIC
Progs in the Look in box and click Open.
l Now build your project (see Figure 2.17)
l Program the target device (see Figure 2.23)
l Try out your Microcontroller in your circuit

FIGURE 3.3 Making a new project.


Exploring the Variety of Random
Documents with Different Content
464 Diosma ovata Oval-leaved G. Shrub. May.
Diosma H.
Straddling-leaved G.
465 Protea divaricata Shrub. July.
Protea H.
G.
466 Goodenia tenella Slender Goodenia Shrub. June.
H.
Lythrum G. All
467 Shrubby Lythrum Shrub.
fruticosum H. Summer.
H.
468 Aloe arborescens Tree Aloe Shrub. June.
H.
Crown-flowered G.
469 Protea coronata Shrub. July.
Protea H.
G.
470 Ophrys arachnoides Spider-like Ophrys Shrub. July.
H.
G.
471 Ophrys myodes Fly-like Ophrys Shrub. July.
H.
Scolloped-leaved G.
472 Hibbertia crenata Shrub. July.
Hibbertia H.
473 Yucca gloriosa Superb Yucca Har. Shrub. July.
Winged-leaved G.
474 Psoralea pinnata Shrub. July.
Psoralea H.
Heart-bearing H.
475 Serapias cordigera Shrub. June.
Serapias H.
Melaleuca Diosma-leaved G.
476 Shrub. July.
diosmæfolia Melaleuca H.
477 Linum venustum Graceful Linum Har. Shrub. July.
Broad-leaved H.
478 Crinum latifolium Bulb. August.
Crinum H.
479 Fragaria indica Indian Strawberry Har. Herb. July.
Shining-leaved
480 Vaccinium nitidum Har. Shrub. June.
Whortle-berry
West India Bark- H.
481 Cinchona caribæa Shrub. August.
tree H.
482 Dianthus alpinus Alpine Pink G. Shrub. July.
H.
Dwarf winged- G.
483 Dahlia pinnata nana Herb. September.
leaved Dahlia H.
G.
484 Nicotiana glutinosa Clammy Tobacco Herb. August.
H.
Melaleuca Willow-leaved G.
485 Shrub. July.
salicifolia Melaleuca H.
486 Pæonia Daurica Dauric Pæony Har. Herb. June.
Xeranthemum Herbaceous Eternal G. All
487 Herb.
herbaceum Flower H. Summer.
Broussonetia
488 Paper Mulberry Har. Shrub. June.
papyrifera
Gnaphalium Large-flowered G.
489 Shrub. August.
grandiflorum Gnaphalium H.
H.
490 Pontederia dilatata Dilated Pontederia Aquatic. September.
H.
H.
491 Gardenia radicans Rooting Gardenia Shrub. August.
H.
Oxylobium Heart-leaved G.
492 Shrub. July.
cordifolium Oxylobium H.
ERRATA.
Plate 438 read 433.
467 instead of Lythrum of Linnæus, read Lythrum fruticosum of Linnæus.
468 line 4 from the bottom, instead of height read size.
*** END OF THE PROJECT GUTENBERG EBOOK THE
BOTANIST'S REPOSITORY FOR NEW AND RARE PLANTS; VOL.
07 [OF 10] ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying copyright
royalties. Special rules, set forth in the General Terms of Use part of
this license, apply to copying and distributing Project Gutenberg™
electronic works to protect the PROJECT GUTENBERG™ concept
and trademark. Project Gutenberg is a registered trademark, and
may not be used if you charge for an eBook, except by following the
terms of the trademark license, including paying royalties for use of
the Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is very
easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund from
the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law in
the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms of
this agreement by keeping this work in the same format with its
attached full Project Gutenberg™ License when you share it without
charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears, or
with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning of
this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1 with
active links or immediate access to the full terms of the Project
Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or expense
to the user, provide a copy, a means of exporting a copy, or a means
of obtaining a copy upon request, of the work in its original “Plain
Vanilla ASCII” or other form. Any alternate format must include the
full Project Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in paragraph
1.F.3, the Project Gutenberg Literary Archive Foundation, the owner
of the Project Gutenberg™ trademark, and any other party
distributing a Project Gutenberg™ electronic work under this
agreement, disclaim all liability to you for damages, costs and
expenses, including legal fees. YOU AGREE THAT YOU HAVE NO
REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF
WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE
PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE
FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving it,
you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or entity
that provided you with the defective work may elect to provide a
replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.
1.F.6. INDEMNITY - You agree to indemnify and hold the
Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and distribution
of Project Gutenberg™ electronic works, harmless from all liability,
costs and expenses, including legal fees, that arise directly or
indirectly from any of the following which you do or cause to occur:
(a) distribution of this or any Project Gutenberg™ work, (b)
alteration, modification, or additions or deletions to any Project
Gutenberg™ work, and (c) any Defect you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many small
donations ($1 to $5,000) are particularly important to maintaining tax
exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.

Project Gutenberg™ eBooks are often created from several printed


editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
back
back
back
back
back
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