ENGLISH

Introductory Programs with the 32-bit PIC Microcontroller: A Line-by-Line Code Analysis and Reference Guide for Embedded Programming in C

Book information

Publisher
Apress
Year
2023
ISBN
9781484290507, 9781484290514
Language
english
Format
PDF
Filesize
11 MB (11462483 bytes)
Series
Maker Innovations Series
Pages
779\779
Time added
2023-05-04 17:47:10

Description

Embark on a journey into the world of embedded programming. This book introduces you to the 32bit PIC and will teach you how the main functions of C programming work and can be used with a PIC micro. My main aim in writing this book is to introduce you to the 32-bit micro and help you understand how to program them in the C programming language. I also want to show you that you can program them and that you can make a career as an embedded programmer. I hope that after reading this book, you will have developed your understanding of C and that you will have the confidence to go and develop your own programs. A one-stop reference for the would-be embedded programmer, you'll explore the electronics needed for a variety of programs as well as how to use different devices with the PIC. The book starts with downloading the environment and creating a simple project, one that uses different oscillators, Phase Lock Loop, and circuitry needed to create the different system clocks—an easy entry point to this exciting environment. You'll also review the MPLABX integrated development environment (IDE) and see how to program the 32Bit PIC, which can be adapted to different PICs. Throughout subsequent chapters, you’ll learn how to use a range of programs that use PIC modules such as the SPI, I2C, UART communication modules, the ADC module, the Capture, Compare, and Pulse Width Modulation module, and the RTCC, Real Time Clock and Calendar Module. What You'll Learn: Create a project in MPLABX Configure the different clock frequencies that are used in the 32bit PIC Build a variable delay subroutine to be used in a simple traffic lights program Use the MAX 7219 driver IC to control the 8by8 matrix display Program an I2C expander module to control the display on a LCD Prerequisites: As to any prerequisites you need before reading this book, there are none. I will assume you are a complete novice, and I will explain every step as you progress through the book. Every instruction will be analyzed to explain how the C instruction works and how it achieves what we want from the instructions. The only things you will definitely need to use this book are as follows. Who This Book Is For: Readers who want to try their hand at embedded programming, newcomers to programming the PIC 32, programmers who want to look into using MPLAB Harmony 3, and programmers who want to understand how C instructions work with respect to 32bit PIC. Also students who are studying for an engineering qualification. Table of Contents About the Author About the Technical Reviewer The Aims and Objectives of the Book Introduction Chapter 1: Creating Our First C Program What Is MPLAB X Creating a Project in MPLAB X The Initial Comments The Speed of the Clock Writing the Configuration Words Our First Program Setting the PORTS Exercise 1-1 The Hexadecimal Number System The First Program Listing Analysis of Listing 1-1 Simulating the Program in MPLAB X Solution to Exercise 1-1 Summary Chapter 2: Header Files and Delays What Are Header Files and Why We Use Them? Creating a Header File Using the Header File Slowing the PIC Down Creating a Delay The Variable Delay Subroutine What Is a Subroutine The Analysis of the Delay Subroutine Creating a 1ms Delay Good Programming Practice The Algorithm The Flowchart Our First Useful Program The Algorithm The Allocation List The Flowchart for the Program Creating the Project Analysis of Listing 2-3 Downloading the Program to a Prototype Board Extending the Program to the Crossroads Traffic Lights The Algorithm Analysis of Listing 2-4 Simulating the Program Within MPLAB X Summary Chapter 3: The Seven-Segment Display Controlling a Seven-Segment Display The Seven-Segment Display Common Anode Seven-Segment Display Common Cathode Seven-Segment Display Controlling the Display with the PIC The Seven-Segment Display Program The Algorithm The Flowchart The Listing for the Seven-Segment Display Program Analysis of Listing 3-1 Improving the Seven-Segment Display Program The Problem with the Program Arrays Using Pointers Analysis of Listing 3-2 The Improved Program Exercise 3-1 Solution to Exercise 3-1 Summary Chapter 4: The LCD The 1602 LCD Instruction or Command Mode Data Mode The Control Pins of the LCD The LCD Header File for PORTE Analysis of Listing 4-1 Analysis of Listing 4-2 Creating Your Own Symbols to Display on the LCD The Pixel Maps The 8-Bit Binary Values for the Four Special Characters The Program “Pixel to Matrix” The Special Character Program The Program Listing for the Special Character Program Analysis of Listing 4-3 Summary Chapter 5: The Dot Matrix Display The 8 by 8 Dot Matrix Board The Single Dot Matrix Display The Max7219 Driver IC Writing to the Max7219 Analysis of Listing 5-1 Creating the Data for Each Row in the Two-Dimensional Array Controlling Four 64-Bit Dot Matrix Boards Analysis of Listing 5-3 Analysis of Listing 5-2 A Program to Scroll Text on the Matrix Display Summary Chapter 6: Communication The 25LC256 EEPROM What Is an EEPROM Device Writing to the EEPROM Reading from the EEPROM The Connections of the EEPROM on the Explorer 16 Development Board The Algorithm for the EEPROM Program Analysis of Listing 6-1 The Setting of the CKE and CKP Bits The Message “Ann Ward” Using the Parallel Master Port The Data for the PMMODE Control Register The PMCON Control Register The PMAEN Control Register Analysis of Listing 6-2 Analysis of Listing 6-3 Summary Chapter 7: The I2C Communication The I2C Protocol I2C Communication 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 the I2C Protocol Header File The I2C Expander Module The LCD2004 The Connections of the I2C Expander Analysis of Listing 7-2 The Program to Use the I2C Expander to Control the LCD2004 Analysis of Listing 7-3 Summary Chapter 8: Interrupts Interrupts The Fetch and Execute Cycle The Program Counter or “PC” Single Vectored Interrupts Multivectored Interrupts How Does the PIC Keep Track of Where It Must Go and Where It Must Get Back To? The Stack and Its Main Use The Sources of Interrupts in a 32-Bit PIC Analysis of Listing 8-1 Using More Than One Interrupt Source with Single Vector Mode Analysis of Listing 8-2 Interrupt Priority Multivectored Interrupts with Priority Analysis of Listing 8-3 Summary Chapter 9: The Real-Time Clock The External Crystal 32.768kHz Oscillator The 24-Hour LCD Clock Program Analysis of Listing 9-1 The TM1637 and the Four Seven-Segment Displays The TM1637 Driver IC Analysis of Listing 9-2 Summary Chapter 10: The Real-Time Clock and the DS3231 The DS3231 RTC Module The Order the DS3231 Expects the Data The Program Algorithm Displaying the Temperature Binary Numbers Adding Binary Numbers Reading the Temperature from the TC72 Examples of the Two’s Complement Process Using the UART and a Terminal Software Using the Alarms of the DS3231 The UART The UxMODE Control Register The UxSTA Register Using Tera Term Connecting the Devices to the PIC32 Analysis of Listing 10-1 Summary Chapter 11: The RTCC Module The RTCC Module of the 32-Bit PIC BCD (Binary-Coded Decimal) Displaying the 32-Bit Value on the LCD RTCC Module Program Analysis of Listing 11-1 Understanding Instruction on Line 504 RTCALRM = 0x8403; Summary Chapter 12: The Real Analog World The Real-World Signals An Analog Signal The Digital World A Simple Voltmeter Program The Algorithm of the Voltmeter Program Analysis of Listing 12-1 The ADC Process The Acquisition Time The 4–20mA Transducer Controlling Two Analog Inputs Analysis of Listing 12-2 Summary Chapter 13: The DHT11 Transducer The DHT11 Humidity and Temperature Sensor Communicating with the DHT11 The Use of a Pull-Up Resistor The DHT11 Program Listing Analysis of Listing 13-1 The Logical OR and AND Truth Tables A Design Procedure Know the Events You Want to Control Analysis of Listing 13-2 Simulating the Program in MPLAB X Summary Chapter 14: Creating a Square Wave Creating a Simple Square Wave Using the Output Compare Module (OCMP) of the PIC32 Using the Logic Analyzer Within MPLAB X Creating Some Musical Notes Creating a PWM Square Wave with the OC1MP Module The Average of a Square Wave Analysis of Listing 14-4 Varying the Brightness of a Lamp Analysis of Listing 14-5 Summary Appendix Data Types and Memory The Program Memory Area The Data RAM The Data EEPROM Variables Appendix 1: Data Types Appendix 2: Some Useful Definitions Appendix 3: Mathematical and Logic Operators Appendix 4: Keywords Appendix 5: Numbering Systems Within Microprocessor-Based Systems Introduction Binary Numbers Converting Decimal to Binary Example 1 Converting from Binary to Decimal Example 2 Exercise 1 Adding and Subtracting Binary Numbers Exercise 2 Worked Example Subtracting Binary Numbers Exercise 3 Worked Example The Hexadecimal Number System Exercise 4 Worked example Appendix 6: The ASCII Character Set Appendix 7: The LCD Instruction Set Index Capture.PNG Capture.PNG

Similar books

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

2010 · PDF

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

1858 · PDF

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

2022 · PDF

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

1809 · PDF