Profitez de ce titre dès maintenant, et de millions d'autres, avec un essai gratuit

Gratuit pendant 30 jours, puis $9.99/mois. Annulez à tout moment.

PIC Projects and Applications using C: A Project-based Approach

PIC Projects and Applications using C: A Project-based Approach

Lire l'aperçu

PIC Projects and Applications using C: A Project-based Approach

évaluations:
3/5 (1 évaluation)
Longueur:
340 pages
2 heures
Sortie:
Dec 2, 2012
ISBN:
9780080999548
Format:
Livre

Description

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
Sortie:
Dec 2, 2012
ISBN:
9780080999548
Format:
Livre

À propos de l'auteur

David Smith has had 30 years experience in the Electronics Industry. Before arriving at MMU he worked as an Electronics Design Engineer for ICL and Marconi. His teaching interests are focused on enabling Design and Technology students to implement microcontroller designs into their projects.


Lié à PIC Projects and Applications using C

Livres associé

Articles associés

Aperçu du livre

PIC Projects and Applications using C - David W Smith

Preface

DW Smith, BSc., MSc.,     Lecturer in Electronics, Manchester Metropolitan University, April 2013

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 compiler. 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 technology as the C language is added and explained as required.

The chapters show numerous applications starting with switching outputs 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 microcontroller 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.

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.

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.

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.

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).

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 microcontroller using the development tools and C8 compiler. The discussion of the integrated development environment shows how to write and develop the C source code file and how to attach it to a project and fix errors. An explanation of the operation of the code is given.

Keywords

C program

MPLAB

MPLABX

delays

loops

C18

outputs

Vous avez atteint la fin de cet aperçu. Inscrivez-vous pour en savoir plus !
Page 1 sur 1

Avis

Ce que les gens pensent de PIC Projects and Applications using C

3.0
1 évaluations / 0 Avis
Qu'avez-vous pensé ?
Évaluation : 0 sur 5 étoiles

Avis des lecteurs