PIC Microcontroller Projects in C -  Dogan Ibrahim

PIC Microcontroller Projects in C (eBook)

Basic to Advanced
eBook Download: PDF | EPUB
2014 | 2. Auflage
660 Seiten
Elsevier Science (Verlag)
978-0-08-099967-8 (ISBN)
Systemvoraussetzungen
Systemvoraussetzungen
38,95 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Extensively revised and updated to encompass the latest developments in the PIC 18FXXX series, this book demonstrates how to develop a range of microcontroller applications through a project-based approach. After giving an introduction to programming in C using the popular mikroC Pro for PIC and MPLAB XC8 languages, this book describes the project development cycle in full. The book walks you through fully tried and tested hands-on projects, including many new, advanced topics such as Ethernet programming, digital signal processing, and RFid technology. This book is ideal for engineers, technicians, hobbyists and students who have knowledge of the basic principles of PIC microcontrollers and want to develop more advanced applications using the PIC18F series.

This book Includes over fifty projects which are divided into three categories: Basic, Intermediate, and Advanced.

New projects in this edition:

    Logic probe Custom LCD font design Hi/Lo game Generating various waveforms in real-time Ultrasonic height measurement Frequency counter Reaction timer GPS projects Closed-loop ON/OFF temperature control Bluetooth projects (master and slave) RFid projects Clock using Real-time-clock (RTC) chip RTC alarm project Graphics LCD (GLCD) projects Barometer+thermometer+altimeter project Plotting temperature on GLCD Ethernet web browser based control Ethernet UDP based control Digital signal processing (Low Pass Filter design) Automotive LIN bus project Automotive CAN bus project Multitasking projects (using both cooperative and Round-robin scheduling) Unipolar stepper motor projects Bipolar stepper motor projects Closed-loop ON/OFF DC motor control


    • A clear introduction to the PIC 18FXXX microcontroller's architecture
    • Covers developing wireless and sensor network applications, SD card projects, and multi-tasking; all demonstrated with the block and circuit diagram, program description in PDL, program listing, and program description
    • Includes more than 50 basic, intermediate, and advanced projects


    Prof Dogan Ibrahim graduated from the University of Salford with First Class Honours in Electronic Engineering. He then completed an MSc course in Automatic Control Engineering at the University of Manchester, and PhD in Digital Signal Processing at the City University in London. Prof Ibrahim worked at several companies before returning to the academic life. He is currently a lecturer at the Department of Computer Information Systems at the Near East University. Prof Ibrahim is a Fellow of the IET, and a Chartered Electrical Engineer. His interests are in the fields of microcontroller based automatic control, digital signal processing, and computer aided design.
    Extensively revised and updated to encompass the latest developments in the PIC 18FXXX series, this book demonstrates how to develop a range of microcontroller applications through a project-based approach. After giving an introduction to programming in C using the popular mikroC Pro for PIC and MPLAB XC8 languages, this book describes the project development cycle in full. The book walks you through fully tried and tested hands-on projects, including many new, advanced topics such as Ethernet programming, digital signal processing, and RFid technology. This book is ideal for engineers, technicians, hobbyists and students who have knowledge of the basic principles of PIC microcontrollers and want to develop more advanced applications using the PIC18F series. This book Includes over fifty projects which are divided into three categories: Basic, Intermediate, and Advanced. New projects in this edition: Logic probeCustom LCD font designHi/Lo gameGenerating various waveforms in real-timeUltrasonic height measurementFrequency counterReaction timerGPS projectsClosed-loop ON/OFF temperature controlBluetooth projects (master and slave)RFid projectsClock using Real-time-clock (RTC) chipRTC alarm projectGraphics LCD (GLCD) projectsBarometer+thermometer+altimeter projectPlotting temperature on GLCDEthernet web browser based controlEthernet UDP based controlDigital signal processing (Low Pass Filter design)Automotive LIN bus projectAutomotive CAN bus projectMultitasking projects (using both cooperative and Round-robin scheduling)Unipolar stepper motor projectsBipolar stepper motor projectsClosed-loop ON/OFF DC motor control A clear introduction to the PIC 18FXXX microcontroller's architecture Covers developing wireless and sensor network applications, SD card projects, and multi-tasking; all demonstrated with the block and circuit diagram, program description in PDL, program listing, and program description Includes more than 50 basic, intermediate, and advanced projects

    Front Cover 1
    PIC Microcontroller Projects in C: Basic to Advanced 4
    Copyright 5
    Contents 6
    Preface 18
    Acknowledgments 20
    Chapter 1 - Microcomputer Systems 22
    1.1 Introduction 22
    1.2 Microcontroller Systems 22
    1.3 Summary 27
    1.4 Exercises 27
    Chapter 2 - mikroC Pro for PIC Programming Language 30
    2.1 Structure of a mikroC Pro for PIC Program 31
    2.2 Arrays 33
    2.3 Pointers 34
    2.4 Structures 35
    2.5 Operators in C 36
    2.6 Modifying the Flow of Control 36
    2.7 mikroC Pro for PIC Functions 41
    2.8 mikroC Pro for PIC Library Functions 41
    2.9 Summary 41
    2.10 Exercises 43
    Chapter 3 - MPLAB X IDE and MPLAB XC8 C Programming Language 46
    3.1 The PICDEM PIC18 Explorer Development Board 47
    3.2 MPLAB X IDE 50
    3.3 MPLAB XC8 Compiler 50
    3.4 Summary 71
    3.5 Exercises 71
    Chapter 4 - Microcontroller Program Development 72
    4.1 Using the PDL and Flow Charts 73
    4.2 Examples 78
    4.3 Representing for Loops in Flow Charts 84
    4.4 Summary 85
    4.5 Exercises 86
    Chapter 5 - Simple PIC18 Projects 88
    Project 5.1—Chasing LEDs 91
    Project 5.2—Complex Flashing LED 97
    Project 5.3—Random Flashing LEDs 99
    Project 5.4—Logic Probe 102
    Project 5.5—LED Dice 106
    Project 5.6—Two-Dice Project 115
    Project 5.7—Two-Dice Project Using Fewer I/O Pins 119
    Project 5.8—7-Segment LED Counter 130
    Project 5.9—Two-Digit Multiplexed 7-Segment LED 141
    Project 5.10—Four-Digit Multiplexed 7-Segment LED 146
    Project 5.11—LED Voltmeter 150
    Project 5.12—LCD Voltmeter 161
    Project 5.13—Generating Sound 177
    Project 5.14—Generating Custom LCD Fonts 181
    Project 5.15—Digital Thermometer 189
    Chapter 6 - Intermediate PIC18 Projects 194
    Project 6.1—Four-Digit Multiplexed Seven-Segment Light Emitting Diode Event Counter Using an External Interrupt 196
    Project 6.2—Calculator with a Keypad and Liquid Crystal Display 211
    Project 6.3—The High/Low Game 227
    Project 6.4—Generating Waveforms 235
    Project 6.5—Ultrasonic Human Height Measurement 269
    Project 6.6—Minielectronic Organ 279
    Project 6.7—Frequency Counter with an LCD Display 283
    Project 6.8—Reaction Timer 289
    Project 6.9—Temperature and Relative Humidity Measurement 298
    Project 6.10—Thermometer with an RS232 Serial Output 311
    Project 6.11—Microcontroller and a PC-Based Calculator 325
    Project 6.12—GPS with an LCD Output 327
    Project 6.13—ON–OFF Temperature Control 338
    Chapter 7 - Advanced PIC18 Projects 348
    Project 7.1—Bluetooth Serial Communication—Slave Mode 354
    Project 7.2—Bluetooth Serial Communication—Master Mode 382
    Project 7.3—Using the RFID 390
    Project 7.4—RFID Lock 408
    Project 7.5—Complex SPI Bus Project 410
    Project 7.6—Real-Time Clock Using an RTC Chip 435
    Project 7.7—Real-Time Alarm Clock 457
    Project 7.8—SD Card Projects—Write Text To a File 460
    Project 7.9—SD Card-Based Temperature Data Logger 487
    Project 7.10—Using Graphics LCD—Displaying Various Shapes 498
    Project 7.11—Barometer, Thermometer and Altimeter Display on a GLCD 511
    Project 7.12—Plotting the Temperature Variation on the GLCD 522
    Project 7.13—Using the Ethernet—Web Browser-Based Control 529
    Project 7.14—Using the Ethernet—UDP-Based Control 542
    Project 7.15—Digital Signal Processing—Low Pass FIR Digital Filter Project 543
    Project 7.16—Automotive Project—Local Interconnect Network Bus Project 556
    Project 7.17—Automotive Project—Can Bus Project 571
    Project 7.18 Multitasking 599
    Project 1—Using Cooperative Multitasking 602
    Project 2—Using Round-Robin Multitasking With Variable CPU Time Allocation 611
    Project 7.19—Stepper Motor Control Projects—Simple Unipolar Motor Drive 619
    Project 7.20—Stepper Motor Control Projects—Complex Control Of A Unipolar Motor 625
    Project 7.21—Stepper Motor Control Project—Simple Bipolar Motor Drive 629
    Project 7.22—DC Motor Control Projects—Simple Motor Drive 634
    Project 7.23—A Homemade Optical Encoder For Motor Speed Measurement 640
    Project 7.24—Closed-Loop DC Motor Speed Control—On/Off Control 645
    Index 652

    Chapter 1

    Microcomputer Systems


    Abstract


    This chapter is an introduction to microcontrollers. The basic features of the microcontrollers are described briefly with some typical application areas of microcontrollers.

    Keywords


    Microcontrollersmicroprocessorsmicrocontroller featuresmicrocontroller applications

    Chapter Outline

    Introduction


    The term microcomputer is used to describe a system that includes a minimum of a microprocessor, program memory, data memory, and input–output (I/O) module. Some microcomputer systems include additional components such as timers, counters, interrupt processing modules, analog-to-digital converters, serial communication modules, USB modules, and so on. Thus, a microcomputer system can be anything from a large system having hard disks, keyboard, monitor, floppy disks, and printers to a single chip embedded controller.
    In this book, we are going to consider only the type of microcomputers that consists of a single silicon chip. Such microcomputer systems are also called microcontrollers and they are used in many everyday household goods such as personal computers, digital watches, microwave ovens, digital TV sets, TV remote control units (CUs), cookers, hi-fi equipment, CD players, personal computers, fridges, etc.
    There are a large number of different types of microcontrollers available in the market, developed and manufactured by many companies. In this book, we shall be looking at the programming and system design using the highly popular 8-bit programmable interface controller (PIC) series of microcontrollers manufactured by Microchip Technology Inc (www.microchip.com).

    Microcontroller Systems


    A microcontroller is a single chip computer. Micro suggests that the device is small, and controller suggests that the device can be used in control applications. Another term used for microcontrollers is embedded controller, since most of the microcontrollers in industrial, commercial, and domestic applications are built into (or embedded in) the devices they control.
    A microprocessor differs from a microcontroller in many ways. The main difference is that a microprocessor requires several other external components for its operation as a computer, such as program memory and data memory, I/O module, and external clock module. A microcontroller on the other hand has all these support chips incorporated inside the same chip. In addition, because of the multiple chip concept, microprocessor-based systems consume considerably more power than the microcontroller-based systems. Another advantage of microcontroller-based systems is that their overall cost is much less than microprocessor-based systems.
    All microcontrollers (and microprocessors) operate on a set of instructions (or the user program) stored in their program memories. A microcontroller fetches these instructions from its program memory one by one, decodes these instructions, and then carries out the required operations.
    Microcontrollers have traditionally been programmed using the assembly language of the target device. Although the assembly language is fast, it has several disadvantages. An assembly program consists of mnemonics and in general it is difficult to learn and maintain a program written using the assembly language. Also, microcontrollers manufactured by different firms have different assembly languages and the user is required to learn a new language every time a new microcontroller is to be used.
    Microcontrollers can also be programmed using high-level languages, such as BASIC, PASCAL, and C. High-level languages have the advantage that it is much easier to learn a high-level language than an assembler language. Also, very large and complex programs can easily be developed using a high-level language. In this book, we shall be learning the programming of high-end 8-bit PIC microcontrollers using two popular C programming languages: the mikroC Pro for PIC, developed by mikroElektronika (www.mikroe.com), and the MPLAB X IDE, developed by Microchip (www.microchip.com).
    In general, a single chip is all that is required to have a running microcontroller-based computer system. In practical applications, additional components may be required to allow a microcomputer to interface to its environment. With the advent of the PIC family of microcontrollers, the development time of an electronic project has reduced to several months, weeks, or even hours.
    Basically, a microcontroller (or a microprocessor) executes a user program that is loaded in its program memory. Under the control of this program, data are received from external devices (inputs), manipulated, and then sent to external devices (outputs).
    For example, in a microcontroller-based fluid level control system, the aim is to control the level of the fluid at a given point. Here, the fluid level is read by the microcomputer via a level sensor device. The program running inside the microcontroller then actuates the pump and the valve and attempts to control the fluid level at the required value. If the fluid level is low, the microcomputer operates the pump to draw more fluid from the reservoir. In practice, the pump is controlled continuously in order to keep the fluid at the required level. Figure 1.1 shows the block diagram of our simple fluid level control system.
    The system shown in Figure 1.1 is a very simplified fluid level control system. In a more sophisticated system we may have a keypad to set the required fluid level, and an LCD to display the current fluid level in the tank. Figure 1.2 shows the block diagram of this more sophisticated fluid level control system.
    We can make our design even more sophisticated (see Figure 1.3) by adding an audible alarm to inform us if the fluid level is outside the required point. Also, the actual level at any time can be sent to a PC every second for archiving and further processing. For example, a graph of the daily fluid level changes can be plotted on the PC. Wireless interface (e.g. Bluetooth or RF) or internet connectivity can be added to the system so that the fluid level can be monitored or controlled remotely. Figure 1.4 shows the block diagram with a Bluetooth module attached to the microcontroller.
    As you can see, because the microcontrollers are programmable, it is very easy to make the final system as simple or as complicated as we like.
    Another example of a microcontroller-based system is the speed control of a direct current (DC) motor. Figure 1.5 shows the block diagram of such a system. Here, a speed sensor device reads current speed of the motor and this is compared with the desired speed (which is assumed to be analog). The error signal between the desired and the actual speed is converted into digital and fed to a microcontroller. A control algorithm running on the microcontroller generates control signals that are converted into analog form and are fed to a power amplifier. The output of the power amplifier drives the motor to achieve the desired speed.

    Figure 1.1Microcontroller-Based Fluid Level Control System.

    Figure 1.2Fluid Level Control System with a Keypad and LCD.
    Depending upon the nature of the signals the block diagram given in Figure 1.5 can take different shapes. For example, if the output of the speed sensor is digital (e.g. optical encoder) and the set speed is also digital, then there is no need to use the A/D converter at the input of the microcontroller. Also, the D/A converter can be eliminated if the power amplifier can be driven by digital signals.
    A microcontroller is a very powerful tool that allows a designer to create sophisticated I/O data manipulation under program control. Microcontrollers are classified by the number of bits they process. The 8-bit devices are the most popular ones and are currently used in most low-cost low-speed microcontroller-based applications. The 16- and 32-bit microcontrollers are much more powerful, but usually more expensive and their use may not be justified in many small to medium-size general purpose applications. In this book, we will be using 8-bit PIC18F series of microcontrollers.

    Figure 1.3More Sophisticated Fluid Level Controller.

    Figure 1.4Using Bluetooth for Remote Monitoring and Control.

    Figure 1.5DC Motor Control System.
    The simplest microcontroller architecture consists of a microprocessor, memory, and I/O. The microprocessor consists of a central processing unit (CPU) and the CU. The CPU is the brain of the microcontroller and this is where all the arithmetic and logic operations are performed. The CU is where the instructions are decoded and this unit controls the internal operations of the microcontroller and sends out control signals to other parts of the microcontroller to carry out the required operations.
    Memory is an important part of a microcontroller system. Depending upon their usage, we can in general classify...

    Erscheint lt. Verlag 8.4.2014
    Sprache englisch
    Themenwelt Technik Elektrotechnik / Energietechnik
    ISBN-10 0-08-099967-0 / 0080999670
    ISBN-13 978-0-08-099967-8 / 9780080999678
    Haben Sie eine Frage zum Produkt?
    PDFPDF (Adobe DRM)
    Größe: 28,7 MB

    Kopierschutz: Adobe-DRM
    Adobe-DRM ist ein Kopierschutz, der das eBook vor Mißbrauch schützen soll. Dabei wird das eBook bereits beim Download auf Ihre persönliche Adobe-ID autorisiert. Lesen können Sie das eBook dann nur auf den Geräten, welche ebenfalls auf Ihre Adobe-ID registriert sind.
    Details zum Adobe-DRM

    Dateiformat: PDF (Portable Document Format)
    Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

    Systemvoraussetzungen:
    PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen eine Adobe-ID und die Software Adobe Digital Editions (kostenlos). Von der Benutzung der OverDrive Media Console raten wir Ihnen ab. Erfahrungsgemäß treten hier gehäuft Probleme mit dem Adobe DRM auf.
    eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
    Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen eine Adobe-ID sowie eine kostenlose App.
    Geräteliste und zusätzliche Hinweise

    Zusätzliches Feature: Online Lesen
    Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

    Buying eBooks from abroad
    For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

    EPUBEPUB (Adobe DRM)
    Größe: 43,8 MB

    Kopierschutz: Adobe-DRM
    Adobe-DRM ist ein Kopierschutz, der das eBook vor Mißbrauch schützen soll. Dabei wird das eBook bereits beim Download auf Ihre persönliche Adobe-ID autorisiert. Lesen können Sie das eBook dann nur auf den Geräten, welche ebenfalls auf Ihre Adobe-ID registriert sind.
    Details zum Adobe-DRM

    Dateiformat: EPUB (Electronic Publication)
    EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

    Systemvoraussetzungen:
    PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen eine Adobe-ID und die Software Adobe Digital Editions (kostenlos). Von der Benutzung der OverDrive Media Console raten wir Ihnen ab. Erfahrungsgemäß treten hier gehäuft Probleme mit dem Adobe DRM auf.
    eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
    Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen eine Adobe-ID sowie eine kostenlose App.
    Geräteliste und zusätzliche Hinweise

    Zusätzliches Feature: Online Lesen
    Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

    Buying eBooks from abroad
    For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

    Mehr entdecken
    aus dem Bereich
    Lehrbuch zu Grundlagen, Technologie und Praxis

    von Konrad Mertens

    eBook Download (2022)
    Carl Hanser Verlag GmbH & Co. KG
    34,99
    Ressourcen und Bereitstellung

    von Martin Kaltschmitt; Karl Stampfer

    eBook Download (2023)
    Springer Fachmedien Wiesbaden (Verlag)
    66,99
    200 Aufgaben zum sicheren Umgang mit Quellen ionisierender Strahlung

    von Jan-Willem Vahlbruch; Hans-Gerrit Vogt

    eBook Download (2023)
    Carl Hanser Verlag GmbH & Co. KG
    34,99