PIC Projects and Applications using C
eBook - ePub

PIC Projects and Applications using C

A Project-based Approach

  1. 204 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

PIC Projects and Applications using C

A Project-based Approach

About this book

PIC Projects and Applications Using C details how to program the PIC microcontroller in the C language. The book takes a learn-by-doing approach, with applications covering topics such as inputs, outputs, keypads, alphanumeric displays, analogue-to-digital conversion, radio transmitters and receivers, data EEPROM, interrupts and timing. To aid debugging, the book provides a section detailing the use of the simulator and in-circuit debugger.With this book you will learn: - How to program the PIC microcontroller in C- Techniques for using the simulator and debuggers to find faults on your code- The ins and outs of interfacing circuits, such as radio modules and liquid crystal displays- How to use the PIC on-board functions, such as interrupts and timing modules, and make analogue measurements- Relevant parts of the language are introduced and explained when required for those new to the subject- Core principles are introduced gradually for self-paced learning- Explains how and why a software program works, and how to alter and expand the code

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access PIC Projects and Applications using C by David W Smith in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Lenguajes de programación. We have over one million books available in our catalogue for you to explore.
Chapter 1

Introduction to the Microcontroller and C

This chapter is an introduction to the microcontroller memory, in the latest 18F series of devices and how it can be written to using the C programming language.
Keywords
Memory
PIC18F1220
register
Port
C language
Bit
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.
image

Figure 1.1 A microcontroller memory location.
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 output a logic 1 to turn the LED on or output a logic 0 to turn it off.
image

Figure 1.2 A basic microcontroller circuit.
The microcontroller we will use in this book is a PIC18F1220 manufactured 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.
image

Figure 1.3 The TRIS register.
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 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).
image

Figure 1.4 Writing to PORTB.
There are several ways in which we can give the microcontroller instructions, 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 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

This chapter explains how to install and use the two current Microchip Integrated Development Environments, MPLAB and MPLABX. The explanation is centred around a basic program, flashing a light emitting diode on and off. The chapter explains how to install the IDE, how the program is written, compiled and then programmed into the microcon...

Table of contents

  1. Cover image
  2. Title page
  3. Table of Contents
  4. Copyright
  5. Preface
  6. Chapter 1: Introduction to the Microcontroller and C
  7. Chapter 2: First C Program
  8. Chapter 3: Using Eight Outputs
  9. Chapter 4: Inputs
  10. Chapter 5: Keypad Scanning
  11. Chapter 6: Analogue to Digital Conversion
  12. Chapter 7: Alpha Numeric Display
  13. Chapter 8: Porting Code to Other Microcontrollers
  14. Chapter 9: Timer/Counter Modules
  15. Chapter 10: Interrupts
  16. Chapter 11: Fault Finding, Using the Simulator, and the In-Circuit Debugger
  17. Chapter 12: Radio Transmitters and Receivers
  18. Chapter 13: EEPROM Data Memory
  19. Chapter 14: Projects
  20. Chapter 15: C Extra
  21. Appendix A: Data Sheets
  22. Appendix B: Useful Contacts
  23. Index