Programming Arduino Projects with the PIC Microcontroller: A Line-By Line Code Analysis and Complete Reference Guide for Embedded Programming in C

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Now that you’ve built a few Arduino projects, and reused some pre-written sketches, it’s time to move onto the next step and explore the world of embedded programming. To truly up-skill, you'll need to understand how your code works, and that's where this book comes in. 

You'll review and work with 13 Arduino projects plus two extra ones written for a PIC microcontroller. Each one is accompanied with a basic circuit diagram and photos of the program working

Ideal for the Arduino hobbyist and PIC programmers who want to merge their skills, this comprehensive book will go over every aspect of the 8-bit microcontroller, provide line-by-line analysis of the code, and in the end, show you how to bring your Arduino projects to the PIC microcontroller using C. You'll gain a full understanding of how the C instructions work and can be used with the PIC microcontroller.

Programming Arduino Projects with the PIC Microcontroller is a one-stop reference material for the would-be embedded programmer. 

What You’ll Learn
  • Examine how the code works 
  • Create code to perform any function
  • Build practical projects on vero boards with full vero plans and circuit diagrams
  • Understand how programs work by simulation with an ECAD package 
Who This Book Is For

Would-be embedded programmers, Arduino hobbyists, and PIC programmers. 

Author(s): Hubert Henry Ward
Edition: 1
Publisher: Apress
Year: 2021

Language: English
Pages: 325
Tags: Arduino; PIC Microcontroller; Embedded Programming;

Table of Contents
About the Author
About the Technical Reviewer
Introduction
Chapter 1: Introducing MPLABX
MPLABX: The IDE from Microchip
Creating a Project in MPLABX
The Configuration Words
Creating a Header File
Changing the Fonts and Colors
The PIC Microcontroller
The PIC16F88 and the PIC8F4525
Summary
Chapter 2: Programming Basics
Good Programming Practice
Algorithms
Flowcharts
Program Listings
Program 2.1: Turning On and Off an LED
Algorithm for Program 2.1
Flowchart for Program 2.1
The Program Listing
Creating a Source File
Adding the Header File
Program 2.1
Analysis of Listing 2-1
Running Program 2.1
The PIC16F88 Development Board
The ICSP Circuit
Testing Program 2.1
Downloading Our Program
Summary
Chapter 3: The Seven-Segment Display and the Stepper Motor
Program 3.1: Controlling a Seven-Segment Display
Seven-Segment Displays
Common Anode Seven-Segment Display
Common Cathode Seven-Segment Display
Arrangement for a Common Anode Seven-Segment Display
Controlling the Display with the PIC
Seven-Segment Display Program
Algorithm for Program 3.1
Flowchart for Program 3.1
Program Listing for the Common Cathode Seven-Segment Display
Analysis of Listing 3-1
Program 3.2: 3461BS Common Anode Four Seven-Segment Display Module
Analysis of Listing 3-2
The Stepper Motor
Analysis of Listing 3-3
Summary
Chapter 4: The Joystick and the Stepper Motor
Using the Joystick
The Principal Operation of the Joystick
The ADCON0 Control Register
The ADCON1 Register
The ADCON2 Register
Example 1: Creating the Required Acquisition Time
Example 2: TAD Time
Changing the ADC Input Channels
Left or Right Justification
The Joystick Program
The LCD
Instruction or Command Mode
Data Mode
Bytes and Nibbles
The Control Pins of the LCD
Analysis of Listing 4-1
One-Dimensional Array
Accessing Data in the Array
Using Pointers
Joystick and Stepper Motor
Analysis of Listing 4-2
Homemade Prototype Board for the PIC18F4525
Summary
Chapter 5: DC Motors
The Speed of the Simple DC Motor
PWM
Creating a Square Wave with the PWM Mode
Creating a 1kHz Square Wave
The Mark Time or Duty Cycle
The TMR2 Preset Value
Storing a Ten-Bit Number
Analysis of Listing 5-1
The Variable-Speed DC Motor Program
Analysis of Listing 5-2
A Two-Directional DC Motor Program
Using the L293D Driver IC
Controlling a Two-Wheel Drive System
Analysis of Listing 5-3
Controlling a Servo Motor
Analysis of Listing 5-4
Summary
Chapter 6: Ultrasonic Distance, and Humidity and Temperature Sensors
Using the Ultrasonic Sensor
The Basic Principle of Operation
The Principal Operation of the Program
Analysis of Listing 6-1
The DHT11 Humidity and Temperature Sensor
Communicating with the DHT11
The Use of a Pull Up Resistor
Checking the Timing of the Pulses
Analysis of Listing 6-3
Summary
Chapter 7: Working with Keypads
Traditional 3 × 4 Keypad Entry
The Need for Pull Up or Pull Down
Pull Down Resistors
Pull Up Resistors
Traditional Keypad Program
Analysis of Listing 7-1
Switch Bounce
The Membrane 4 × 4 Keypad
The 8 × 8 Dot Matrix Board
Analysis of Listing 7-3
Creating the Data for Each Row in the Two-Dimensional Array
Summary
Chapter 8: Using Bluetooth with PIR Motion Sensors
The HC-06 Module
Matching 5V to 3.3V
The Default Settings of the HC-06
The HC-05 Bluetooth Module
Connecting the PIC to a Mobile Phone via the HC-06
The UART
Analysis of Listing 8-1
An Important Distinction
Using the Mobile APP Bluetooth Terminal
Changing the PIN on the HC-06
Using AT Commands
Using Tera Term to Change the PIN
Using PuTTY to Program the HC-06
Programming the HC-06 with AT Command from the PIC Micro
Analysis of Listing 8-2
The HC-SR501 PIR Motion Sensor
Analysis of Listing 8-3
Summary
Chapter 9: Communication
Getting the PIC to Communicate with Other Devices
The SPI Mode
The Buffer Full (BF) Flag in the SSPSTAT Register
Synchronizing the Sequence
SSPSTAT Register
The SSPCON1 Register
Using the SPI to Read from the TC72
Operating Modes for the TC72
The Registers of the TC72
The Algorithm for Using the TC72
Displaying the Temperature Reading
Binary Numbers
Adding Binary Numbers
Analysis of Listing 9-1
Reading the Temperature from the TC72
Examples of the 2’s Complement Process
Using the Sprintf Function
Analysis of Listing 9-2
Comparing the Two Approaches
Using the PIC18f4525 as the Slave
Analysis of Listing 9-3
Analysis of Listing 9-4
Summary
Chapter 10: Using the I2C Protocol
I2C Communication Protocol
EEPROM
24LC256 EEPROM
Writing to the EEPROM
Reading from the EEPROM
TC74 Temperature Sensor
Reading the Temperature
Using I2C with 24LC256 and TC74
Analysis of Listing 10-1
That Little Thought
Summary
Chapter 11: Using the UART
UART at a Glance
Interrupts and How They Work
Analysis of Listing 11-1
The Baud Rate
Using Tera Term
Using Handshaking
Analysis of Listing 11-2
Two PICs Communicate via the UART
Analysis of Listing 11-3
Summary
Chapter 12: Real-Time Clock and Interrupts
The RTC Program
Analysis of Listing 12-1
The DS1307 RTC Module
Setting Up and Reading from the DS1307
The I2C Protocol
Writing to the Slave
The Start Bit
The Address Bits and Control Bit in the First Byte
The Acknowledgment Bit
The Data Byte
The Stop Bit
Reading from the Slave
The NACK or Not Acknowledgment Bit
Analysis of Listing 12-2
TM1637 and the Four Seven-Segment Display
The TM1367 Driver IC
Analysis of Listing 12-3
Summary
Chapter 13: Working with LCDs
Creating Your Own Characters on an LCD
The Pixel Maps
A Simple Exercise
Analysis of Listing 13-1
The CCP Module
Algorithm for the Bike Speed Program
The Speed of a Bicycle
Analysis of Listing 13-2
Finding the Program Instructions
Program Counter and the Stack
The Stack
The Vector Table and the ISR
Summary
Chapter 14: Analyzing Obscure Instructions and Logic Operators in C
Obscure C Instructions
Analysis of Listing 14-1
Some Logic Operators
& Symbol
Testing the Programs in MPLABX
Analysis of Listing 14-3
The && Operator
The ‘|’ Operator
The ‘||’ Operator
The ^ EXOR or Exclusive OR
The &= Function
The |= Function
The ‘%’ or Modulus or Remainder Operator
The ‘~’ Or 1’s Complement
The ‘<>n’ Operator
Summary
Appendix: Additional Insights
Data Types and Memory
The Program Memory Area
The Data RAM
The Data EEPROM
Variables
Appendix A: Data Types
Appendix B: Some Useful Definitions
Appendix C: Mathematical and Logic Operators
Appendix D: Keywords
Appendix E: Numbering Systems Within Microprocessor-Based Systems
Introduction
Binary Numbers
Converting Decimal to Binary
Adding and Subtracting Binary Numbers
Subtracting Binary Numbers
The Hexadecimal Number System
Appendix F: Building Circuit Boards
Preparation
The Circuit Diagram
The Vero Board Plan
Preparing to Solder
Tinning the Components
Soldering the Components
Patience and Practice
Appendix G: The LCD Header File for Eight-Bit Mode
Appendix H: The ASCII Character Set
Appendix I: The LCD Instruction Set
Index