Programming 8-bit PIC Microcontrollers in C

with Interactive Hardware Simulation


  • Martin Bates, Lecturer in Microelectronics (retired), Sussex Coast College, UK Formerly Course Leader, Foundation Degree Engineering, University of Brighton & Course Tutor, PIC Microcontrollers Short Courses, Hastings Innovation Centre

PIC Microcontrollers are present in almost every new electronic application that is released from garage door openers to the iPhone. With the proliferation of this product more and more engineers and engineers-to-be (students) need to understand how to design, develop, and build with them. Martin Bates, best-selling author, has provided a step-by-step guide to programming these microcontrollers (MCUs) with the C programming language. With no previous knowledge of C necessary to read this book, it is the perfect for entry into this world for engineers who have not worked with PICs, new professionals, students, and hobbyists. As MCUs become more complex C is the most popular language due to its ability to process advanced processes and multitasking. RTOSs, that is a need to know for engineers, is also discussed as more advanced MCUs require timing and organization of programming and implementation of multitasking. The book includes lots of source code, circuit schematics, and hardware block diagrams. Microchip's PICDEM Mechatronics board is used to detail the examples throughout the book.
View full description


Engineers new to working with PICs, Students, Hobbyists


Book information

  • Published: July 2008
  • Imprint: NEWNES
  • ISBN: 978-0-7506-8960-1

Table of Contents

Part 1 PIC Microcontroller Systems 1.1 PIC16 Microcontrollers 1MCU Features Program Execution RAM File Registers Other PIC Chips 1.2 PIC16 MCU Configuration Clock Options Configuration Options Configuration in C 1.3 PIC16 MCU Peripherals Timers A/D Converter Comparator Parallel Slave Port Interrupts 1.4 PIC16 Serial Interfaces USART SPI Bus I2C Bus 1.5 PIC16 MPLAB Projects MPLAB C Project Project Files 1.6 PIC16 Program and Debug Programming Debugging Design Package Assessment 1 Assignments 1 Part 2 C Programming Essentials 2.1 PIC16 C Getting Started Simple Program Program Creation Program Testing Program Analysis 2.2 PIC16 C Program Basics Variables Looping Decision Making Loop Control FOR Loop SIREN Program Blank Program 2.3 PIC16 C Data Operations Variable Types Assignment Operations Conditional Operations 2.4 PIC16 C Sequence Control While Loops Break, Continue, and Goto If..Else and Switch..Case 2.5 PIC16 C Functions and Structure Basic Functions Global and Local Variables 2.6 PIC16 C Input and Output Serial LCD Keypad and Calculator 2.7 PIC16 C More Data Types Arrays Indirect Addressing Operators Enumeration 2.8 PIC16 C Compiler Directives Program Directives Header File 2.9 PIC16 C Assembler Routines Program Compilation Assembler Block PIC Assembly Language Assessment 2 Assignments 2 Part 3 C Peripheral Interfaces 3.1 PIC16 C Analog Input Analog Setup Voltage Measurement 3.2 PIC16 C Interrupts C Interrupts Interrupt Example Interrupt Statements 3.3 PIC16 C Hardware Timers Counter/Timer Operation PWM Mode Compare ModeCapture Mode 3.4 PIC16 C UART Serial Link 3.5 PIC16 C SPI Serial Bus 3.6 PIC16 C I 2 C Serial Bus 3.7 PIC16 C Parallel and Serial Interfaces Parallel Slave Port Comparison of Communication Links 3.8 PIC16 C EEPROM Interface 3.9 PIC16 C Analog Output Assessment 3 Assignments 3Part 4 C Mechatronics Applications 4.1 PICDEM Mechatronics Board Overview PICDEM Hardware Motor Drives Test Program Debugging 4.2 PICDEM Liquid Crystal Display LCD Connections LCD Test Program BCD Count Program 4.3 PICDEM DC Motor Test Programs Basic Control Rev Counter 4.4 PICDEM Stepper Motor Control Construction Stepper Motor Test Direction Control 4.5 PICDEM Analog Sensors Light Sensor Temperature Measurement 4.6 PICDEM Temperature Controller Specification I/O Allocation Implementation 4.7 PICDEM Board Simulation Circuit Description Demo Applications Assessment 4 Assignments 4 Part 5 PIC16 C Applications and Systems 5.1 PIC16 C Application Design Hardware Design Software Design Application Debugging and Testing 5.2 PIC16 C Temperature Controller System Operation Software Design and Implementation 5.3 PIC16 C Data Logger System BASE Board Program Outline 5.4 PIC16 C Operating Systems Polled I/O Interrupts PC Operating System Real-Time Operating System 5.5 PIC16 C System Design Hardware Selection Microcontrollers Hardware Design Software Design Assessment 5 Assignments 5 Appendix A Hardware Design Using ISIS Schematic Capture Design Specification Schematic Circuit Schematic Edit Appendix B Software Design Using CCS C BAR1 Source Code PIC Registers BAR1 List File Appendix C System Testing Using Proteus VSM Attaching the Program Program Debugging Typical Errors Appendix D C Compiler Comparison Microchip C18 Hi-Tech PIC C Mikro C Matrix C Summary of C Compilers Appendix E CCS C Programming Syntax Summary Compiler Directives Program Blocks Punctuation Basic I/O Functions Appendix F CCS C Programming Function Reference Answers