M. Rafiquzzaman
Microcontroller Theory and Applications with the PIC18F
M. Rafiquzzaman
Microcontroller Theory and Applications with the PIC18F
- Gebundenes Buch
- Merkliste
- Auf die Merkliste
- Bewerten Bewerten
- Teilen
- Produkt teilen
- Produkterinnerung
- Produkterinnerung
"This new edition of Microcontroller Theory and Applications with the PIC18F, Third Edition is an enhanced analysis of the interfacing techniques associated with Microchip's PIC18F4321 microcontroller through fundamental concepts of assembly and C language programming. Over the course of 11 chapters, this edition includes extended coverage on basic topics from the last edition, emphasizing characteristics, principles, and interfacing techniques, now demonstrated through simple devices such as switches, LEDs, Seven-segment displays, then advanced devices like LCD displays and ADC. Complex…mehr
Andere Kunden interessierten sich auch für
- David BockelmanThe Theory Measurement and Applications of Mode Specific Scattering Parameters With Multiple Modes of Propagation121,99 €
- Dogan IbrahimNucleo Boards Programming with the STM32CubeIDE29,99 €
- Kevin LynchEmbedded Computing and Mechatronics with the Pic32 Microcontroller78,99 €
- Dogan IbrahimGet Started with the MAX78000FTHR Development Board32,95 €
- Uri DubinCross-Entropy Method: Theory with Applications44,99 €
- Ankit PonkiaMicrostrip Patch Antennas With Enhanced BW For ISM Band Applications39,99 €
- V. JagadeesanDesign of Automated JNSP System for Thin Film Device Applications44,99 €
-
-
-
"This new edition of Microcontroller Theory and Applications with the PIC18F, Third Edition is an enhanced analysis of the interfacing techniques associated with Microchip's PIC18F4321 microcontroller through fundamental concepts of assembly and C language programming. Over the course of 11 chapters, this edition includes extended coverage on basic topics from the last edition, emphasizing characteristics, principles, and interfacing techniques, now demonstrated through simple devices such as switches, LEDs, Seven-segment displays, then advanced devices like LCD displays and ADC. Complex topics like PWM, stack, bank-memory, Serial I/O, and CCP are presented in a simpler manner in this new edition for easier learning. Companion lecture slides are readily available to supplement teaching"--
Hinweis: Dieser Artikel kann nur an eine deutsche Lieferadresse ausgeliefert werden.
Hinweis: Dieser Artikel kann nur an eine deutsche Lieferadresse ausgeliefert werden.
Produktdetails
- Produktdetails
- Verlag: John Wiley & Sons Inc
- 3. Auflage
- Seitenzahl: 496
- Erscheinungstermin: 31. Dezember 2024
- Englisch
- ISBN-13: 9781394318230
- ISBN-10: 1394318235
- Artikelnr.: 71778133
- Herstellerkennzeichnung
- Libri GmbH
- Europaallee 1
- 36244 Bad Hersfeld
- gpsr@libri.de
- Verlag: John Wiley & Sons Inc
- 3. Auflage
- Seitenzahl: 496
- Erscheinungstermin: 31. Dezember 2024
- Englisch
- ISBN-13: 9781394318230
- ISBN-10: 1394318235
- Artikelnr.: 71778133
- Herstellerkennzeichnung
- Libri GmbH
- Europaallee 1
- 36244 Bad Hersfeld
- gpsr@libri.de
M. Rafiquzzaman, Ph.D., P.E, Professor Emeritus, Electrical & Computer Engineering Department, California State Polytechnic University, Pomona, CA. Professor Rafiquzzaman has over 50 years of academic and industrial experience. He has authored 18 books (including all editions) on digital logic, microprocessors, microcontrollers, and computer architecture. His first popular book on microprocessors was published by Wiley in 1982 and his other books are published by Wiley, Prentice-Hall, CRC Press, Harper & Row, and West Publishing. Dr. Rafiquzzaman is a member of the US Olympic committee. He managed Swimming, Diving, and Synchronized Swimming events of the 1984 Los Angeles Olympic Organizing Committee. He is currently President of Rafi Systems Inc., a high tech cataract lens manufacturing company in California.
Preface xiii
About the Companion Website xvii
1 Introduction to Microcontrollers 1
1.1 Explanation of Terms 3
1.2 Microcontroller Data Types 7
1.2.1 Unsigned and Signed Binary Numbers 7
1.2.2 ASCII and EBCDIC Codes 9
1.2.3 Unpacked and Packed Binary-Coded-Decimal Numbers 10
1.3 Evolution of the Microcontroller 10
1.4 Embedded Controllers 14
2 Microcontroller Basics 15
2.1 Basic Blocks of a Microcomputer 15
2.1.1 System Bus 16
2.1.2 Clock Signals 17
2.2 Microcontroller Architectures 18
2.3 Central Processing Unit (CPU) 19
2.3.1 Register Section 19
2.3.2 Control Unit 28
2.3.3 Arithmetic and Logic Unit (ALU) 29
2.3.4 Simplified Explanation of Control Unit Design 29
2.4 Basic Concept of Pipelining 30
2.5 RISC Versus CISC 32
2.6 Functional Representation of a Typical Microcontroller - The PIC18F
4321 33
Questions and Problems 34
3 Microcontroller Memory and Input/Output (I/O) 37
3.1 Introduction to Microcontroller Memory 37
3.1.1 Main Memory 38
3.1.2 READ and WRITE Timing Diagrams 40
3.1.3 Main Memory Organization 42
3.2 Microcontroller Input/Output (I/O) 45
3.2.1 Overview of Digital Output Circuits 47
3.2.2 Simple I/O Devices 49
3.2.3 Programmed I/O 51
3.2.4 Unconditional and Conditional Programmed I/O 52
3.2.5 Interrupt I/O 53
Questions and Problems 56
4 Programming Languages 61
4.1 Computer Programming Languages 61
4.2 Machine Language 62
4.3 Assembly Language 63
4.3.1 Types of Assemblers 64
4.3.2 Assembler Delimiters 65
4.3.3 Specifying Numbers by Typical Assemblers 65
4.3.4 Assembler Directives or Pseudoinstructions 65
4.3.5 Assembly Language Instruction Formats 67
4.3.6 Typical Instruction Set 69
4.3.7 Typical Addressing Modes 75
4.3.8 Subroutine Calls in Assembly Language 76
4.4 High-Level Language 77
4.5 Introduction to C Language 78
4.5.1 Data Types 81
4.5.2 Bit Manipulation Operators 81
4.5.3 Control Structures 83
4.5.4 The if-else Construct 83
4.5.5 The switch Construct 84
4.5.6 The while Construct 85
4.5.7 The for Construct 86
4.5.8 The do-while Construct 87
4.5.9 Structures and Unions 87
4.5.10 Functions in c 88
4.5.11 Arrays 89
4.5.12 Macros 89
4.6 Choosing a Programming Language 90
4.7 Flowcharts 90
Questions and Problems 91
5 PIC18F Architecture and Addressing Modes 93
5.1 Basic Features of the PIC18F Family 93
5.2 PIC18F Register Architecture 96
5.3 PIC18F Memory Organization 99
5.3.1 PIC18F Program Memory 100
5.3.2 PIC18F Data Memory 100
5.4 PIC18F Addressing Modes 104
5.4.1 Literal or Immediate Addressing Mode 104
5.4.2 Inherent or Implied Addressing Mode 104
5.4.3 Direct or Absolute Addressing Mode 105
5.4.4 Indirect Addressing Mode 105
5.4.5 Relative Addressing Mode 111
5.4.6 Bit Addressing Mode 113
Questions and Problems 113
6 Assembly Language Programming with the PIC18F: Part 1 115
6.1 Introduction to the PIC18F MPLAB Assembler 115
6.2 PIC18F Instruction Format 119
6.3 PIC18F Instruction Set 121
6.3.1 Data Movement Instructions 123
6.3.2 Arithmetic Instructions 128
6.3.3 Logic Instructions 137
6.3.4 Rotate Instructions 140
6.3.5 Bit Manipulation Instructions 144
6.3.6 PIC18F Test, Compare, and Skip instructions 147
Questions and Problems 153
7 Assembly Language Programming with the PIC18F: Part 2 157
7.1 PIC18F Jump/Branch Instructions 157
7.2 PIC18F Table Read/Write Instructions 159
7.3 PIC18F Subroutine Instructions 163
7.4 PIC18F System Control Instructions 165
7.5 PIC18F Hardware Versus Software Stack 165
7.6 Multiplication and Division Algorithms 173
7.6.1 Signed Multiplication Algorithm 173
7.6.2 Unsigned Division Algorithm 175
7.6.3 Signed Division Algorithm 177
7.7 Advanced Programming Examples 179
7.8 PIC18F Delay Routine 183
Questions and Problems 185
8 PIC18F Programmed I/O Using Assembly & C 189
8.1 PIC18F Pins and Signals 189
8.1.1 Clock 194
8.1.2 PIC18F Reset 198
8.1.3 High-Voltage and Low-Voltage Programming (HVP and LVP) 200
8.1.4 "pragma config" and "config" Directives 200
8.1.5 A Simplified Setup for the PIC18F 4321 201
8.1.6 Downloading Programs into the PIC18F4321 Using the PICKit3 Interface
202
8.2 PIC18F4321 Programmed I/O 202
8.2.1 I/O Instructions in PIC18F Assembly 206
8.2.2 Configuring PIC18F4321 I/O Ports Using PIC18F Assembly 206
8.2.3 configuring PIc18F4321 I/O Ports Using c 208
8.2.4 Interfacing LEDs (Light-Emitting Diodes) and Seven-Segment Displays
210
8.2.5 Programmed I/O Examples Using PIC18F Assembly 211
8.2.6 Programmed I/O Examples Using C Language 215
Questions and Problems 222
9 PIC18F Interrupt I/O, LCD, and Keyboard Interfacing 227
9.1 Basics of Polled I/O Versus Interrupt I/O 227
9.1.1 Interrupt I/O 228
9.2 PIC18F Interrupts 233
9.2.1 Interrupt Procedure 233
9.2.2 PIC18F Interrupt Types 233
9.2.3 Programming the PIC18F External Interrupts 234
9.2.4 Programming PIC18F External Interrupts Using Assembly 239
9.2.5 Programming PIc18F External Interrupts Using c 240
9.2.6 Accessing PIC18F On-Chip Peripheral Devices Using Polled I/O Versus
Interrupt I/O 249
9.3 PIC18F Interface to a Typical LCD (Liquid Crystal Display) 250
9.4 Interfacing PIC18F4321 to a Hexadecimal Keyboard and a Seven-Segment
Display 257
9.4.1 Basics of Keyboard and Display Interface to a Microcontroller 257
9.4.2 PIC18F4321 Interface to a Hexadecimal Keyboard and a Seven-Segment
Display 258
Questions and Problems 266
10 PIC18F Timers and Analog Interface 271
10.1 PIC18F Timers 271
10.1.1 Timer 0 273
10.1.2 Timer 1 282
10.1.3 Timer 2 288
10.1.4 Timer 3 292
10.2 Analog Interface 302
10.2.1 PIC18F On-Chip ADC (A/D Converter) 302
10.2.2 Interfacing an External D/A converter Using c 315
Questions and Problems 316
11 PIC18F CCP and Serial I/O 321
11.1 PIC18F CCP (Capture/Compare/PWM (Pulse Width Modulation)) Module 321
11.1.1 CCP Registers 322
11.1.2 CCP Modules and Associated Timers 322
11.1.3 PIC18F4321 Capture Mode 322
11.1.4 PIC18F4321 Compare Mode 326
11.1.5 PIC18F4321 PWM (Pulse Width Modulation) Mode 329
11.2 dc Motor Control 332
11.3 Serial Interface 336
11.3.1 Synchronous Serial Data Transmission 337
11.3.2 Asynchronous Serial Data Transmission 337
11.3.3 Basics of SPI and I2c 337
11.4 PIC18F Serial I/O 338
11.4.1 PIC18F SPI Mode 338
11.4.2 PIC18F I2C (Inter-integrated Circuit) Mode 348
Questions and Problems 358
Appendix A Answers to Selected Problems 361
Appendix B Glossary 369
Appendix C PIC18F Instruction Set (Alphabetical Order) 379
Appendix D PIC18F Instruction Set - Details 383
Appendix E PIC18F4321 Special Function Registers 429
Appendix F Tutorial for Assembling and Debugging a PIC18F Assembly Language
Program Using the MPLAB X 431
Appendix G Tutorial for Compiling and Debugging a C-Program Using the
Microchip's XC8 Compiler 447
Appendix H Interfacing the PIC18F4321 to a Personal Computer or Laptop
Using PICkitTM 4 463
Bibliography 469
Index 471
About the Companion Website xvii
1 Introduction to Microcontrollers 1
1.1 Explanation of Terms 3
1.2 Microcontroller Data Types 7
1.2.1 Unsigned and Signed Binary Numbers 7
1.2.2 ASCII and EBCDIC Codes 9
1.2.3 Unpacked and Packed Binary-Coded-Decimal Numbers 10
1.3 Evolution of the Microcontroller 10
1.4 Embedded Controllers 14
2 Microcontroller Basics 15
2.1 Basic Blocks of a Microcomputer 15
2.1.1 System Bus 16
2.1.2 Clock Signals 17
2.2 Microcontroller Architectures 18
2.3 Central Processing Unit (CPU) 19
2.3.1 Register Section 19
2.3.2 Control Unit 28
2.3.3 Arithmetic and Logic Unit (ALU) 29
2.3.4 Simplified Explanation of Control Unit Design 29
2.4 Basic Concept of Pipelining 30
2.5 RISC Versus CISC 32
2.6 Functional Representation of a Typical Microcontroller - The PIC18F
4321 33
Questions and Problems 34
3 Microcontroller Memory and Input/Output (I/O) 37
3.1 Introduction to Microcontroller Memory 37
3.1.1 Main Memory 38
3.1.2 READ and WRITE Timing Diagrams 40
3.1.3 Main Memory Organization 42
3.2 Microcontroller Input/Output (I/O) 45
3.2.1 Overview of Digital Output Circuits 47
3.2.2 Simple I/O Devices 49
3.2.3 Programmed I/O 51
3.2.4 Unconditional and Conditional Programmed I/O 52
3.2.5 Interrupt I/O 53
Questions and Problems 56
4 Programming Languages 61
4.1 Computer Programming Languages 61
4.2 Machine Language 62
4.3 Assembly Language 63
4.3.1 Types of Assemblers 64
4.3.2 Assembler Delimiters 65
4.3.3 Specifying Numbers by Typical Assemblers 65
4.3.4 Assembler Directives or Pseudoinstructions 65
4.3.5 Assembly Language Instruction Formats 67
4.3.6 Typical Instruction Set 69
4.3.7 Typical Addressing Modes 75
4.3.8 Subroutine Calls in Assembly Language 76
4.4 High-Level Language 77
4.5 Introduction to C Language 78
4.5.1 Data Types 81
4.5.2 Bit Manipulation Operators 81
4.5.3 Control Structures 83
4.5.4 The if-else Construct 83
4.5.5 The switch Construct 84
4.5.6 The while Construct 85
4.5.7 The for Construct 86
4.5.8 The do-while Construct 87
4.5.9 Structures and Unions 87
4.5.10 Functions in c 88
4.5.11 Arrays 89
4.5.12 Macros 89
4.6 Choosing a Programming Language 90
4.7 Flowcharts 90
Questions and Problems 91
5 PIC18F Architecture and Addressing Modes 93
5.1 Basic Features of the PIC18F Family 93
5.2 PIC18F Register Architecture 96
5.3 PIC18F Memory Organization 99
5.3.1 PIC18F Program Memory 100
5.3.2 PIC18F Data Memory 100
5.4 PIC18F Addressing Modes 104
5.4.1 Literal or Immediate Addressing Mode 104
5.4.2 Inherent or Implied Addressing Mode 104
5.4.3 Direct or Absolute Addressing Mode 105
5.4.4 Indirect Addressing Mode 105
5.4.5 Relative Addressing Mode 111
5.4.6 Bit Addressing Mode 113
Questions and Problems 113
6 Assembly Language Programming with the PIC18F: Part 1 115
6.1 Introduction to the PIC18F MPLAB Assembler 115
6.2 PIC18F Instruction Format 119
6.3 PIC18F Instruction Set 121
6.3.1 Data Movement Instructions 123
6.3.2 Arithmetic Instructions 128
6.3.3 Logic Instructions 137
6.3.4 Rotate Instructions 140
6.3.5 Bit Manipulation Instructions 144
6.3.6 PIC18F Test, Compare, and Skip instructions 147
Questions and Problems 153
7 Assembly Language Programming with the PIC18F: Part 2 157
7.1 PIC18F Jump/Branch Instructions 157
7.2 PIC18F Table Read/Write Instructions 159
7.3 PIC18F Subroutine Instructions 163
7.4 PIC18F System Control Instructions 165
7.5 PIC18F Hardware Versus Software Stack 165
7.6 Multiplication and Division Algorithms 173
7.6.1 Signed Multiplication Algorithm 173
7.6.2 Unsigned Division Algorithm 175
7.6.3 Signed Division Algorithm 177
7.7 Advanced Programming Examples 179
7.8 PIC18F Delay Routine 183
Questions and Problems 185
8 PIC18F Programmed I/O Using Assembly & C 189
8.1 PIC18F Pins and Signals 189
8.1.1 Clock 194
8.1.2 PIC18F Reset 198
8.1.3 High-Voltage and Low-Voltage Programming (HVP and LVP) 200
8.1.4 "pragma config" and "config" Directives 200
8.1.5 A Simplified Setup for the PIC18F 4321 201
8.1.6 Downloading Programs into the PIC18F4321 Using the PICKit3 Interface
202
8.2 PIC18F4321 Programmed I/O 202
8.2.1 I/O Instructions in PIC18F Assembly 206
8.2.2 Configuring PIC18F4321 I/O Ports Using PIC18F Assembly 206
8.2.3 configuring PIc18F4321 I/O Ports Using c 208
8.2.4 Interfacing LEDs (Light-Emitting Diodes) and Seven-Segment Displays
210
8.2.5 Programmed I/O Examples Using PIC18F Assembly 211
8.2.6 Programmed I/O Examples Using C Language 215
Questions and Problems 222
9 PIC18F Interrupt I/O, LCD, and Keyboard Interfacing 227
9.1 Basics of Polled I/O Versus Interrupt I/O 227
9.1.1 Interrupt I/O 228
9.2 PIC18F Interrupts 233
9.2.1 Interrupt Procedure 233
9.2.2 PIC18F Interrupt Types 233
9.2.3 Programming the PIC18F External Interrupts 234
9.2.4 Programming PIC18F External Interrupts Using Assembly 239
9.2.5 Programming PIc18F External Interrupts Using c 240
9.2.6 Accessing PIC18F On-Chip Peripheral Devices Using Polled I/O Versus
Interrupt I/O 249
9.3 PIC18F Interface to a Typical LCD (Liquid Crystal Display) 250
9.4 Interfacing PIC18F4321 to a Hexadecimal Keyboard and a Seven-Segment
Display 257
9.4.1 Basics of Keyboard and Display Interface to a Microcontroller 257
9.4.2 PIC18F4321 Interface to a Hexadecimal Keyboard and a Seven-Segment
Display 258
Questions and Problems 266
10 PIC18F Timers and Analog Interface 271
10.1 PIC18F Timers 271
10.1.1 Timer 0 273
10.1.2 Timer 1 282
10.1.3 Timer 2 288
10.1.4 Timer 3 292
10.2 Analog Interface 302
10.2.1 PIC18F On-Chip ADC (A/D Converter) 302
10.2.2 Interfacing an External D/A converter Using c 315
Questions and Problems 316
11 PIC18F CCP and Serial I/O 321
11.1 PIC18F CCP (Capture/Compare/PWM (Pulse Width Modulation)) Module 321
11.1.1 CCP Registers 322
11.1.2 CCP Modules and Associated Timers 322
11.1.3 PIC18F4321 Capture Mode 322
11.1.4 PIC18F4321 Compare Mode 326
11.1.5 PIC18F4321 PWM (Pulse Width Modulation) Mode 329
11.2 dc Motor Control 332
11.3 Serial Interface 336
11.3.1 Synchronous Serial Data Transmission 337
11.3.2 Asynchronous Serial Data Transmission 337
11.3.3 Basics of SPI and I2c 337
11.4 PIC18F Serial I/O 338
11.4.1 PIC18F SPI Mode 338
11.4.2 PIC18F I2C (Inter-integrated Circuit) Mode 348
Questions and Problems 358
Appendix A Answers to Selected Problems 361
Appendix B Glossary 369
Appendix C PIC18F Instruction Set (Alphabetical Order) 379
Appendix D PIC18F Instruction Set - Details 383
Appendix E PIC18F4321 Special Function Registers 429
Appendix F Tutorial for Assembling and Debugging a PIC18F Assembly Language
Program Using the MPLAB X 431
Appendix G Tutorial for Compiling and Debugging a C-Program Using the
Microchip's XC8 Compiler 447
Appendix H Interfacing the PIC18F4321 to a Personal Computer or Laptop
Using PICkitTM 4 463
Bibliography 469
Index 471
Preface xiii
About the Companion Website xvii
1 Introduction to Microcontrollers 1
1.1 Explanation of Terms 3
1.2 Microcontroller Data Types 7
1.2.1 Unsigned and Signed Binary Numbers 7
1.2.2 ASCII and EBCDIC Codes 9
1.2.3 Unpacked and Packed Binary-Coded-Decimal Numbers 10
1.3 Evolution of the Microcontroller 10
1.4 Embedded Controllers 14
2 Microcontroller Basics 15
2.1 Basic Blocks of a Microcomputer 15
2.1.1 System Bus 16
2.1.2 Clock Signals 17
2.2 Microcontroller Architectures 18
2.3 Central Processing Unit (CPU) 19
2.3.1 Register Section 19
2.3.2 Control Unit 28
2.3.3 Arithmetic and Logic Unit (ALU) 29
2.3.4 Simplified Explanation of Control Unit Design 29
2.4 Basic Concept of Pipelining 30
2.5 RISC Versus CISC 32
2.6 Functional Representation of a Typical Microcontroller - The PIC18F
4321 33
Questions and Problems 34
3 Microcontroller Memory and Input/Output (I/O) 37
3.1 Introduction to Microcontroller Memory 37
3.1.1 Main Memory 38
3.1.2 READ and WRITE Timing Diagrams 40
3.1.3 Main Memory Organization 42
3.2 Microcontroller Input/Output (I/O) 45
3.2.1 Overview of Digital Output Circuits 47
3.2.2 Simple I/O Devices 49
3.2.3 Programmed I/O 51
3.2.4 Unconditional and Conditional Programmed I/O 52
3.2.5 Interrupt I/O 53
Questions and Problems 56
4 Programming Languages 61
4.1 Computer Programming Languages 61
4.2 Machine Language 62
4.3 Assembly Language 63
4.3.1 Types of Assemblers 64
4.3.2 Assembler Delimiters 65
4.3.3 Specifying Numbers by Typical Assemblers 65
4.3.4 Assembler Directives or Pseudoinstructions 65
4.3.5 Assembly Language Instruction Formats 67
4.3.6 Typical Instruction Set 69
4.3.7 Typical Addressing Modes 75
4.3.8 Subroutine Calls in Assembly Language 76
4.4 High-Level Language 77
4.5 Introduction to C Language 78
4.5.1 Data Types 81
4.5.2 Bit Manipulation Operators 81
4.5.3 Control Structures 83
4.5.4 The if-else Construct 83
4.5.5 The switch Construct 84
4.5.6 The while Construct 85
4.5.7 The for Construct 86
4.5.8 The do-while Construct 87
4.5.9 Structures and Unions 87
4.5.10 Functions in c 88
4.5.11 Arrays 89
4.5.12 Macros 89
4.6 Choosing a Programming Language 90
4.7 Flowcharts 90
Questions and Problems 91
5 PIC18F Architecture and Addressing Modes 93
5.1 Basic Features of the PIC18F Family 93
5.2 PIC18F Register Architecture 96
5.3 PIC18F Memory Organization 99
5.3.1 PIC18F Program Memory 100
5.3.2 PIC18F Data Memory 100
5.4 PIC18F Addressing Modes 104
5.4.1 Literal or Immediate Addressing Mode 104
5.4.2 Inherent or Implied Addressing Mode 104
5.4.3 Direct or Absolute Addressing Mode 105
5.4.4 Indirect Addressing Mode 105
5.4.5 Relative Addressing Mode 111
5.4.6 Bit Addressing Mode 113
Questions and Problems 113
6 Assembly Language Programming with the PIC18F: Part 1 115
6.1 Introduction to the PIC18F MPLAB Assembler 115
6.2 PIC18F Instruction Format 119
6.3 PIC18F Instruction Set 121
6.3.1 Data Movement Instructions 123
6.3.2 Arithmetic Instructions 128
6.3.3 Logic Instructions 137
6.3.4 Rotate Instructions 140
6.3.5 Bit Manipulation Instructions 144
6.3.6 PIC18F Test, Compare, and Skip instructions 147
Questions and Problems 153
7 Assembly Language Programming with the PIC18F: Part 2 157
7.1 PIC18F Jump/Branch Instructions 157
7.2 PIC18F Table Read/Write Instructions 159
7.3 PIC18F Subroutine Instructions 163
7.4 PIC18F System Control Instructions 165
7.5 PIC18F Hardware Versus Software Stack 165
7.6 Multiplication and Division Algorithms 173
7.6.1 Signed Multiplication Algorithm 173
7.6.2 Unsigned Division Algorithm 175
7.6.3 Signed Division Algorithm 177
7.7 Advanced Programming Examples 179
7.8 PIC18F Delay Routine 183
Questions and Problems 185
8 PIC18F Programmed I/O Using Assembly & C 189
8.1 PIC18F Pins and Signals 189
8.1.1 Clock 194
8.1.2 PIC18F Reset 198
8.1.3 High-Voltage and Low-Voltage Programming (HVP and LVP) 200
8.1.4 "pragma config" and "config" Directives 200
8.1.5 A Simplified Setup for the PIC18F 4321 201
8.1.6 Downloading Programs into the PIC18F4321 Using the PICKit3 Interface
202
8.2 PIC18F4321 Programmed I/O 202
8.2.1 I/O Instructions in PIC18F Assembly 206
8.2.2 Configuring PIC18F4321 I/O Ports Using PIC18F Assembly 206
8.2.3 configuring PIc18F4321 I/O Ports Using c 208
8.2.4 Interfacing LEDs (Light-Emitting Diodes) and Seven-Segment Displays
210
8.2.5 Programmed I/O Examples Using PIC18F Assembly 211
8.2.6 Programmed I/O Examples Using C Language 215
Questions and Problems 222
9 PIC18F Interrupt I/O, LCD, and Keyboard Interfacing 227
9.1 Basics of Polled I/O Versus Interrupt I/O 227
9.1.1 Interrupt I/O 228
9.2 PIC18F Interrupts 233
9.2.1 Interrupt Procedure 233
9.2.2 PIC18F Interrupt Types 233
9.2.3 Programming the PIC18F External Interrupts 234
9.2.4 Programming PIC18F External Interrupts Using Assembly 239
9.2.5 Programming PIc18F External Interrupts Using c 240
9.2.6 Accessing PIC18F On-Chip Peripheral Devices Using Polled I/O Versus
Interrupt I/O 249
9.3 PIC18F Interface to a Typical LCD (Liquid Crystal Display) 250
9.4 Interfacing PIC18F4321 to a Hexadecimal Keyboard and a Seven-Segment
Display 257
9.4.1 Basics of Keyboard and Display Interface to a Microcontroller 257
9.4.2 PIC18F4321 Interface to a Hexadecimal Keyboard and a Seven-Segment
Display 258
Questions and Problems 266
10 PIC18F Timers and Analog Interface 271
10.1 PIC18F Timers 271
10.1.1 Timer 0 273
10.1.2 Timer 1 282
10.1.3 Timer 2 288
10.1.4 Timer 3 292
10.2 Analog Interface 302
10.2.1 PIC18F On-Chip ADC (A/D Converter) 302
10.2.2 Interfacing an External D/A converter Using c 315
Questions and Problems 316
11 PIC18F CCP and Serial I/O 321
11.1 PIC18F CCP (Capture/Compare/PWM (Pulse Width Modulation)) Module 321
11.1.1 CCP Registers 322
11.1.2 CCP Modules and Associated Timers 322
11.1.3 PIC18F4321 Capture Mode 322
11.1.4 PIC18F4321 Compare Mode 326
11.1.5 PIC18F4321 PWM (Pulse Width Modulation) Mode 329
11.2 dc Motor Control 332
11.3 Serial Interface 336
11.3.1 Synchronous Serial Data Transmission 337
11.3.2 Asynchronous Serial Data Transmission 337
11.3.3 Basics of SPI and I2c 337
11.4 PIC18F Serial I/O 338
11.4.1 PIC18F SPI Mode 338
11.4.2 PIC18F I2C (Inter-integrated Circuit) Mode 348
Questions and Problems 358
Appendix A Answers to Selected Problems 361
Appendix B Glossary 369
Appendix C PIC18F Instruction Set (Alphabetical Order) 379
Appendix D PIC18F Instruction Set - Details 383
Appendix E PIC18F4321 Special Function Registers 429
Appendix F Tutorial for Assembling and Debugging a PIC18F Assembly Language
Program Using the MPLAB X 431
Appendix G Tutorial for Compiling and Debugging a C-Program Using the
Microchip's XC8 Compiler 447
Appendix H Interfacing the PIC18F4321 to a Personal Computer or Laptop
Using PICkitTM 4 463
Bibliography 469
Index 471
About the Companion Website xvii
1 Introduction to Microcontrollers 1
1.1 Explanation of Terms 3
1.2 Microcontroller Data Types 7
1.2.1 Unsigned and Signed Binary Numbers 7
1.2.2 ASCII and EBCDIC Codes 9
1.2.3 Unpacked and Packed Binary-Coded-Decimal Numbers 10
1.3 Evolution of the Microcontroller 10
1.4 Embedded Controllers 14
2 Microcontroller Basics 15
2.1 Basic Blocks of a Microcomputer 15
2.1.1 System Bus 16
2.1.2 Clock Signals 17
2.2 Microcontroller Architectures 18
2.3 Central Processing Unit (CPU) 19
2.3.1 Register Section 19
2.3.2 Control Unit 28
2.3.3 Arithmetic and Logic Unit (ALU) 29
2.3.4 Simplified Explanation of Control Unit Design 29
2.4 Basic Concept of Pipelining 30
2.5 RISC Versus CISC 32
2.6 Functional Representation of a Typical Microcontroller - The PIC18F
4321 33
Questions and Problems 34
3 Microcontroller Memory and Input/Output (I/O) 37
3.1 Introduction to Microcontroller Memory 37
3.1.1 Main Memory 38
3.1.2 READ and WRITE Timing Diagrams 40
3.1.3 Main Memory Organization 42
3.2 Microcontroller Input/Output (I/O) 45
3.2.1 Overview of Digital Output Circuits 47
3.2.2 Simple I/O Devices 49
3.2.3 Programmed I/O 51
3.2.4 Unconditional and Conditional Programmed I/O 52
3.2.5 Interrupt I/O 53
Questions and Problems 56
4 Programming Languages 61
4.1 Computer Programming Languages 61
4.2 Machine Language 62
4.3 Assembly Language 63
4.3.1 Types of Assemblers 64
4.3.2 Assembler Delimiters 65
4.3.3 Specifying Numbers by Typical Assemblers 65
4.3.4 Assembler Directives or Pseudoinstructions 65
4.3.5 Assembly Language Instruction Formats 67
4.3.6 Typical Instruction Set 69
4.3.7 Typical Addressing Modes 75
4.3.8 Subroutine Calls in Assembly Language 76
4.4 High-Level Language 77
4.5 Introduction to C Language 78
4.5.1 Data Types 81
4.5.2 Bit Manipulation Operators 81
4.5.3 Control Structures 83
4.5.4 The if-else Construct 83
4.5.5 The switch Construct 84
4.5.6 The while Construct 85
4.5.7 The for Construct 86
4.5.8 The do-while Construct 87
4.5.9 Structures and Unions 87
4.5.10 Functions in c 88
4.5.11 Arrays 89
4.5.12 Macros 89
4.6 Choosing a Programming Language 90
4.7 Flowcharts 90
Questions and Problems 91
5 PIC18F Architecture and Addressing Modes 93
5.1 Basic Features of the PIC18F Family 93
5.2 PIC18F Register Architecture 96
5.3 PIC18F Memory Organization 99
5.3.1 PIC18F Program Memory 100
5.3.2 PIC18F Data Memory 100
5.4 PIC18F Addressing Modes 104
5.4.1 Literal or Immediate Addressing Mode 104
5.4.2 Inherent or Implied Addressing Mode 104
5.4.3 Direct or Absolute Addressing Mode 105
5.4.4 Indirect Addressing Mode 105
5.4.5 Relative Addressing Mode 111
5.4.6 Bit Addressing Mode 113
Questions and Problems 113
6 Assembly Language Programming with the PIC18F: Part 1 115
6.1 Introduction to the PIC18F MPLAB Assembler 115
6.2 PIC18F Instruction Format 119
6.3 PIC18F Instruction Set 121
6.3.1 Data Movement Instructions 123
6.3.2 Arithmetic Instructions 128
6.3.3 Logic Instructions 137
6.3.4 Rotate Instructions 140
6.3.5 Bit Manipulation Instructions 144
6.3.6 PIC18F Test, Compare, and Skip instructions 147
Questions and Problems 153
7 Assembly Language Programming with the PIC18F: Part 2 157
7.1 PIC18F Jump/Branch Instructions 157
7.2 PIC18F Table Read/Write Instructions 159
7.3 PIC18F Subroutine Instructions 163
7.4 PIC18F System Control Instructions 165
7.5 PIC18F Hardware Versus Software Stack 165
7.6 Multiplication and Division Algorithms 173
7.6.1 Signed Multiplication Algorithm 173
7.6.2 Unsigned Division Algorithm 175
7.6.3 Signed Division Algorithm 177
7.7 Advanced Programming Examples 179
7.8 PIC18F Delay Routine 183
Questions and Problems 185
8 PIC18F Programmed I/O Using Assembly & C 189
8.1 PIC18F Pins and Signals 189
8.1.1 Clock 194
8.1.2 PIC18F Reset 198
8.1.3 High-Voltage and Low-Voltage Programming (HVP and LVP) 200
8.1.4 "pragma config" and "config" Directives 200
8.1.5 A Simplified Setup for the PIC18F 4321 201
8.1.6 Downloading Programs into the PIC18F4321 Using the PICKit3 Interface
202
8.2 PIC18F4321 Programmed I/O 202
8.2.1 I/O Instructions in PIC18F Assembly 206
8.2.2 Configuring PIC18F4321 I/O Ports Using PIC18F Assembly 206
8.2.3 configuring PIc18F4321 I/O Ports Using c 208
8.2.4 Interfacing LEDs (Light-Emitting Diodes) and Seven-Segment Displays
210
8.2.5 Programmed I/O Examples Using PIC18F Assembly 211
8.2.6 Programmed I/O Examples Using C Language 215
Questions and Problems 222
9 PIC18F Interrupt I/O, LCD, and Keyboard Interfacing 227
9.1 Basics of Polled I/O Versus Interrupt I/O 227
9.1.1 Interrupt I/O 228
9.2 PIC18F Interrupts 233
9.2.1 Interrupt Procedure 233
9.2.2 PIC18F Interrupt Types 233
9.2.3 Programming the PIC18F External Interrupts 234
9.2.4 Programming PIC18F External Interrupts Using Assembly 239
9.2.5 Programming PIc18F External Interrupts Using c 240
9.2.6 Accessing PIC18F On-Chip Peripheral Devices Using Polled I/O Versus
Interrupt I/O 249
9.3 PIC18F Interface to a Typical LCD (Liquid Crystal Display) 250
9.4 Interfacing PIC18F4321 to a Hexadecimal Keyboard and a Seven-Segment
Display 257
9.4.1 Basics of Keyboard and Display Interface to a Microcontroller 257
9.4.2 PIC18F4321 Interface to a Hexadecimal Keyboard and a Seven-Segment
Display 258
Questions and Problems 266
10 PIC18F Timers and Analog Interface 271
10.1 PIC18F Timers 271
10.1.1 Timer 0 273
10.1.2 Timer 1 282
10.1.3 Timer 2 288
10.1.4 Timer 3 292
10.2 Analog Interface 302
10.2.1 PIC18F On-Chip ADC (A/D Converter) 302
10.2.2 Interfacing an External D/A converter Using c 315
Questions and Problems 316
11 PIC18F CCP and Serial I/O 321
11.1 PIC18F CCP (Capture/Compare/PWM (Pulse Width Modulation)) Module 321
11.1.1 CCP Registers 322
11.1.2 CCP Modules and Associated Timers 322
11.1.3 PIC18F4321 Capture Mode 322
11.1.4 PIC18F4321 Compare Mode 326
11.1.5 PIC18F4321 PWM (Pulse Width Modulation) Mode 329
11.2 dc Motor Control 332
11.3 Serial Interface 336
11.3.1 Synchronous Serial Data Transmission 337
11.3.2 Asynchronous Serial Data Transmission 337
11.3.3 Basics of SPI and I2c 337
11.4 PIC18F Serial I/O 338
11.4.1 PIC18F SPI Mode 338
11.4.2 PIC18F I2C (Inter-integrated Circuit) Mode 348
Questions and Problems 358
Appendix A Answers to Selected Problems 361
Appendix B Glossary 369
Appendix C PIC18F Instruction Set (Alphabetical Order) 379
Appendix D PIC18F Instruction Set - Details 383
Appendix E PIC18F4321 Special Function Registers 429
Appendix F Tutorial for Assembling and Debugging a PIC18F Assembly Language
Program Using the MPLAB X 431
Appendix G Tutorial for Compiling and Debugging a C-Program Using the
Microchip's XC8 Compiler 447
Appendix H Interfacing the PIC18F4321 to a Personal Computer or Laptop
Using PICkitTM 4 463
Bibliography 469
Index 471