This book is a hands-on introduction to the principles and practice of embedded system design using the PIC microcontroller. Packed with helpful examples and illustrations, it gives an in-depth treatment of microcontroller design, programming in both assembly language and C, and features advanced to
Designing Embedded Systems with PIC Microcontrollers, Second Edition: Principles and Applications
β Scribed by Tim Wilmshurst
- Publisher
- Newnes
- Year
- 2009
- Tongue
- English
- Leaves
- 651
- Edition
- 2
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
I think this is a terrific book ,for anyone trying to get up to speed with Pic's.
It makes programming with Assembler and C an achievable goal for most people.
I worked my way through this book from start to finish and enjoyed every page.
I built the the ping-pong and Derbot which helped me gain a better understanding of the code and the chips.
I found the introduction to MPLAB IDE to be of great value to me as debugging doesn't really change through the range of Pic,s.
The book takes you from a small Pic 16f84a all the way up to 18xxxx Pic,s.By the time you are done with these there,s a nice overview of whats next.
I am now on De Jasio's Pic32 book,and It was not such a giant leap to get going with these pics as I am now pretty familiar with MPLAB and the basic Pic mindset.
In my opinion it is a good beginners course, after which you can complete your project or start the next level with confidence.
β¦ Table of Contents
Cover
......Page 1
Copyright
......Page 2
Introduction to the first edition......Page 3
Introduction to the second edition......Page 6
Acknowledgements......Page 8
Section 1
Getting Started with Embedded Systems......Page 9
1.1.1 What is an embedded system?......Page 10
1.2.1 The domestic refrigerator......Page 11
1.2.2 A car door mechanism......Page 12
1.2.3 The electronic βping-pongβ game......Page 13
1.2.4 The Derbot Autonomous Guided Vehicle......Page 14
1.3 Some computer essentials......Page 15
1.3.2 Instruction sets β the Complex Instruction Set Computer and the ReducedInstruction Set Computer......Page 16
1.3.3 Memory types......Page 17
1.3.4 Organising memory......Page 18
1.4.2 Microcontrollers......Page 19
1.4.4 Microcontroller packaging and appearance......Page 20
1.5.1 Background......Page 22
1.5.2 PIC 8-bit microcontrollers today......Page 23
1.6 An introduction to PIC microcontrollersusing the Baseline Series......Page 25
1.6.1 The architecture of the 12F508......Page 26
Summary......Page 28
Questions and exercises......Page 29
Section 2
Minimum Systems and the PIC 16F84A......Page 31
2.1.1 A family overview......Page 32
2.2 An architecture overview of the 16F84A......Page 36
2.3 A review of memory technologies......Page 38
2.3.1 Static RAM (SRAM)......Page 39
2.3.3 EEPROM (Electrically Erasable Programmable Read-Only Memory)......Page 40
2.4.1 Program memory and the stack......Page 41
2.4.2 Data and Special Function register memory (RAM)......Page 43
2.4.4 EEPROM......Page 45
2.5.1 Clock oscillator and instruction cycle......Page 46
2.5.2 Pipelining......Page 47
2.6 Power-up and Reset......Page 49
2.7 Taking things further β the 16F84A on-chip reset circuit......Page 50
Questions and exercises......Page 53
CHAPTER 3 -
Parallel ports, power supplyand the clock oscillator......Page 55
3.2 The technical challenge of parallel input/output......Page 56
3.2.1 Building a parallel interface......Page 57
3.2.2 Port electrical characteristics......Page 59
3.2.3 Some special cases......Page 60
3.3.1 Switches......Page 61
3.3.2 Light-emitting diodes......Page 63
3.4.1 16F84A Port B......Page 65
3.4.2 16F84A Port A......Page 67
3.4.3 Port output characteristics......Page 68
3.5.1 Clock oscillator types......Page 69
3.5.3 The 16F84A clock oscillator......Page 71
3.6.2 16F84A operating conditions......Page 73
3.7 The hardware design of the electronic ping-pong game......Page 74
Summary......Page 75
Questions and exercises......Page 76
CHAPTER 4 -
Starting to program βan introduction to Assembler......Page 79
4.1.1 The problem of programming and the Assembler compromise......Page 80
4.1.3 The program development cycle......Page 82
4.2.1 More on the PIC 16 Series ALU......Page 83
4.2.2 The PIC 16 Series instruction set β an introduction......Page 84
4.3.2 Assembler format......Page 86
4.3.4 Number representation......Page 87
4.3.5 A very first program......Page 88
4.4.1 Introducing MPLAB......Page 89
4.5 An introductory MPLAB tutorial......Page 90
4.5.1 Creating a project......Page 92
4.5.3 Selecting the microcontroller and setting the Configuration Word......Page 93
4.5.4 Assembling the project......Page 94
4.5.5 The list file and identifying errors......Page 95
4.6 An introduction to simulation......Page 96
4.6.3 Resetting and running a program......Page 97
4.7 A larger program β using data memory and moving data......Page 99
4.8 Programming for a target piece of hardware β a simple datatransfer program......Page 101
4.8.1 Tutorial: simulating Program Example 4.5......Page 104
4.9.1 Conventional programming β using the PICSTART Plus......Page 105
4.9.2 In-circuit programming β using the PICkit 2......Page 107
4.10 Taking things further: the 16 Series instruction set format......Page 109
References......Page 110
5.1 The main idea β building structure into programs......Page 111
5.1.1 Flow diagrams......Page 112
5.1.2 State diagrams......Page 113
5.2 Conditional branching and working with bits......Page 114
5.2.1 Working with bits β the data transfer program......Page 115
5.2.2 Branching on Status register bits......Page 116
5.3 Subroutines......Page 119
5.3.1 Adapting the Fibonacci program to use subroutines......Page 120
5.4 Generating time delays and intervals......Page 121
5.5.1 Breakpoints......Page 125
5.5.2 Stopwatch......Page 127
5.5.3 Trace......Page 128
5.6 Introducing logical instructions......Page 129
5.7 Look-up tables......Page 131
5.7.1 Introducing the look-up table......Page 132
5.7.3 Resetting the look-up table pointer with an AND instruction......Page 135
5.8.1 Include Files......Page 136
5.8.2 Macros......Page 137
5.8.4 Using the LIST directive......Page 138
5.9.1 A Structure for the ping-pong program......Page 139
5.9.2 Exploring the ping-pong program code......Page 140
5.10 Simulating the ping-pong program β tutorial......Page 143
5.11 A glance at graphical simulators......Page 145
5.12.1 Using indirect addressing to save a Fibonacci series......Page 146
Summary......Page 147
References......Page 148
CHAPTER 6 -
Working with time: interrupts,counters and timers......Page 149
6.1.1 Interrupt structures......Page 150
6.1.2 The 16F84A interrupt structure......Page 151
6.1.3 The CPU response to an interrupt......Page 153
6.2.1 Programming with a single interrupt......Page 154
6.2.3 Stopping interrupts from wrecking your program 1 β context saving......Page 156
6.2.4 Stopping interrupts from wrecking your program 2 β critical regions and masking......Page 159
6.3.1 The digital counter reviewed......Page 160
6.3.2 The counter as a timer......Page 161
6.3.3 The 16F84A Timer 0 module......Page 163
6.4.1 Object or event counting......Page 164
6.4.2 Hardware-generated delays......Page 166
6.5 The Watchdog Timer......Page 167
6.6 Sleep mode......Page 168
6.7 Taking things further β interrupt latency......Page 169
Questions and exercises......Page 170
Section 3
Larger Systems and the PIC 16F873A......Page 173
CHAPTER 7 -
Larger Systems and the PIC 16F873A......Page 174
7.2 The 16F873A block diagram and CPU......Page 175
7.2.1 Overview of the Central Processing Unit and core......Page 176
7.2.2 Overview of memory......Page 178
7.3.1 The 16F873A program memory......Page 179
7.3.2 The 16F873A data memory and Special Function Registers......Page 181
7.4 βSpecialβ memory operations......Page 183
7.4.1 Accessing EEPROM and program memory......Page 184
7.4.2 In-Circuit Serial Programming (ICSP)......Page 186
7.5.1 The interrupt structure......Page 187
7.5.3 Interrupt identification and context saving......Page 188
7.6.2 Reset and power supply......Page 190
7.7.1 The 16F873A Port A......Page 191
7.7.3 The 16F873A Port C......Page 193
7.8.1 The challenge of testing an embedded system......Page 195
7.8.2 Oscilloscopes and logic analysers......Page 197
7.8.3 In-circuit emulators......Page 199
7.8.4 On-chip debuggers......Page 200
7.9 The Microchip in-circuit debugger (ICD 2)......Page 201
7.10.1 Power supply, oscillator and reset......Page 202
7.10.2 Use of the parallel ports......Page 203
7.11.2 Applying the ICD 2......Page 205
7.11.3 Setting the configuration bits within the program......Page 209
7.12 Taking things further β the 16F874A/16F877A Ports D and E......Page 211
Summary......Page 212
References......Page 213
CHAPTER 8 -
The human and physical interfaces......Page 216
8.1 The main idea β the human interface......Page 217
8.2.1 The keypad......Page 219
8.2.2 Design example: use of a keypad in the Derbot hand controller......Page 221
8.3 LED displays......Page 222
8.3.1 LED arrays: seven-segment displays......Page 225
8.3.2 Design example: the Derbot hand controller seven-segment display......Page 226
8.4 Liquid crystal displays......Page 230
8.4.1 The HD44780 LCD driver and its derivatives......Page 231
8.4.2 Design example: use of LCD display in the Derbot hand controller......Page 233
8.5 The main idea β interfacing to the physical world......Page 234
8.6.1 The microswitch......Page 236
8.6.3 Optical object sensing......Page 237
8.6.4 The opto-sensor applied as a shaft encoder......Page 238
8.7 More on digital input......Page 239
8.7.1 16F873A input characteristics......Page 240
8.7.2 Ensuring legal logic levels and input protection......Page 241
8.7.3 Switch debouncing......Page 244
8.8.1 DC and stepper motors......Page 246
8.8.2 Angular positioning: the βservoβ......Page 247
8.9.1 Simple DC switching......Page 248
8.9.2 Simple switching on the Derbot......Page 250
8.9.3 Reversible switching: the H-bridge......Page 251
8.10 Building the Derbot......Page 253
References......Page 256
Questions and exercises......Page 257
CHAPTER 9 -
Taking timing further......Page 259
9.2.2 Timer 1......Page 260
9.2.3 Application of Timer 0 and Timer 1 as counters for Derbot odometry......Page 262
9.2.4 Using Timer 0 and Timer 1 to generate repetitive interrupts......Page 265
9.3.1 Timer 2......Page 266
9.3.2 The PR2 register, comparator and postscaler......Page 268
9.4.2 Capture mode......Page 269
9.5.1 The principle of pulse width modulation......Page 271
9.5.2 Generating pulse width modulation signals in hardware β the 16F87XA pulsewidth modulation......Page 273
9.5.3 Pulse width modulation applied in the Derbot for motor control......Page 275
9.6.1 An example of software-generated pulse width modulation......Page 278
9.7 Pulse width modulation used for digital-to-analog conversion......Page 282
9.7.1 An example of pulse width modulation used for digital-to-analog conversion......Page 283
9.8.1 The principle of frequency measurement......Page 285
9.8.2 Frequency (speed) measurement in the Derbot......Page 286
9.9 Speed control applied to the Derbot......Page 288
9.10 When there is no timer......Page 291
9.12 Where do we go from here?......Page 293
Summary......Page 294
Questions and exercises......Page 295
CHAPTER 10 - Starting with serial
......Page 297
10.1 The main idea β introducing serial......Page 298
10.2.1 Synchronous basics......Page 299
10.2.3 Microwire and Serial Peripheral Interface......Page 301
10.3 The 16F87XA Master Synchronous Serial Port modulein SPI mode......Page 302
10.3.1 Port overview......Page 303
10.3.2 Port configuration......Page 304
10.3.3 Setting the clock......Page 305
10.3.4 Managing data transfer......Page 306
10.4 A simple Serial Peripheral Interface example......Page 307
10.6 Enhancing synchronous serial and the Inter-IntegratedCircuit bus......Page 309
10.6.2 The pull-up resistor......Page 310
10.6.3 Inter-Integrated Circuit signal characteristics......Page 311
10.7.1 The MSSP Inter-Integrated Circuit registers and their preliminary use......Page 312
10.7.2 The Master Synchronous Serial Port in Inter-Integrated Circuit Slave mode......Page 315
10.7.3 The Master Synchronous Serial Port in Inter-Integrated Circuit Master mode......Page 318
10.8.2 The Autonomous Guided Vehicle as an Inter-Integrated Circuit master......Page 320
10.8.3 The hand controller as an Inter-Integrated Circuit slave......Page 323
10.9 Evaluation of synchronous serial data communication andan introduction to asynchronous serial data communication......Page 326
10.9.1 Asynchronous principles......Page 327
10.9.2 Synchronising serial data β without an incoming clock......Page 328
10.10.2 The USART asynchronous transmitter......Page 329
10.10.3 The USART baud rate generator......Page 331
10.10.4 The USART asynchronous receiver......Page 332
10.10.5 An asynchronous example......Page 334
10.10.6 Using address detection with the USART receive mode......Page 335
10.11 Implementing serial without a serial port β βbit bangingβ......Page 336
Questions and exercises......Page 337
CHAPTER 11 -
Data acquisition and manipulation......Page 340
11.1 The main idea β analog and digital quantities,their acquisition and use......Page 341
11.2.1 The analog-to-digital converter......Page 342
11.2.4 Sample and Hold, and acquisition time......Page 345
11.2.5 Timing and microprocessor control......Page 347
11.3.1 Overview and block diagram......Page 348
11.3.2 Controlling the ADC......Page 349
11.3.3 The analog input model......Page 352
11.3.4 Calculating acquisition time......Page 354
11.3.6 Trading off conversion speed and resolution......Page 355
11.4.2 Acquisition time......Page 356
11.4.3 Data conversion......Page 357
11.5.1 Fixed- and floating-point arithmetic......Page 358
11.5.2 Binary to Binary Coded Decimal conversion......Page 359
11.5.4 Scaling and the Derbot light meter example......Page 360
11.6 The Derbot light-seeking program......Page 362
11.7 The comparator module......Page 364
11.7.2 The 16F87XA comparators and voltage reference......Page 365
11.8.1 The electronic tape measure......Page 366
11.8.2 The light meter......Page 367
11.8.3 The voltmeter......Page 368
References......Page 369
CHAPTER 12 -
Some PIC microcontroller advances......Page 371
12.2.1 Architecture overview......Page 372
12.2.2 The 16F88 peripherals......Page 373
12.3 The 16F883......Page 375
12.4 NanoWatt technology......Page 378
12.5.1 Clock sources......Page 380
12.6 Some enhanced peripherals......Page 383
12.6.2 The enhanced capture, compare and pulse width modulation module......Page 384
12.6.4 The enhanced addressable USART......Page 385
12.6.5 The analog-to-digital converter module......Page 386
References......Page 388
Section 4
Smarter Systems and the PIC 18F2420......Page 390
CHAPTER 13 -
Smarter systems and the PIC 18F2420......Page 391
Similar to the 16 Series......Page 392
New for the 18 Series......Page 393
13.2 The 18F2420/2520 block diagram and Status register......Page 395
13.3 The 18 Series instruction set......Page 398
Instructions which have been upgraded......Page 401
13.3.1 The extended instruction set......Page 402
13.4.2 Access Random Access Memory......Page 403
13.4.3 Indirect addressing and accessing tables in data memory......Page 405
13.5.1 The program memory map......Page 406
13.5.2 The Program Counter......Page 407
13.5.4 The Configuration registers......Page 408
13.6 The Stacks......Page 409
13.6.3 The Fast Register Stack......Page 410
13.7.2 The interrupt sources, their enabling and prioritisation......Page 411
13.7.4 Global enabling......Page 413
13.7.6 The Interrupt registers......Page 414
13.7.7 Context saving with interrupts......Page 416
13.9 The oscillator sources......Page 419
13.9.2 Power-managed modes......Page 421
13.10.2 The Fibonacci program......Page 423
13.10.3 Applying the interrupts......Page 426
13.13 A peripheral review and the parallel ports......Page 428
13.13.1 The 18F2420 Port A......Page 429
13.14 The timers......Page 430
13.14.1 Timer 0......Page 431
13.14.2 Timers 1 and 2......Page 432
13.14.4 The Watchdog Timer......Page 433
13.15.2 Compare mode......Page 434
13.16 The serial ports......Page 435
13.17 The analog-to-digital converter......Page 436
References......Page 438
CHAPTER 14 -
Introducing C......Page 441
14.2.1 A little history......Page 442
14.2.3 Laying out the program β declarations, statements, comments and space......Page 443
14.2.5 The C function......Page 446
14.2.6 Data type and storage......Page 447
14.2.8 Control of program flow and the βwhileβ keyword......Page 448
14.2.10 Use of libraries and the Standard Library......Page 449
14.3 Compiling the C program......Page 450
14.4.1 Specification of radix......Page 451
14.5.1 The linker, header and library files......Page 452
14.5.2 Building the project......Page 454
14.6 Simulating a C program......Page 456
14.7.1 Program preliminaries β more on declaring variables......Page 457
14.7.2 The βdoβwhileβ construct......Page 458
14.8.1 Hardware peripheral functions......Page 459
14.8.3 The general software library......Page 460
14.9 Further reading......Page 462
References......Page 463
15.1 The main idea β adapting C to the embedded environment......Page 464
15.2.2 The βif β and βifβelseβ conditional branch structures......Page 465
15.2.4 Simulating and running the example program......Page 467
15.3.2 The function definition......Page 469
15.3.4 Library delay functions and βDelay10KTCYx( )β......Page 470
15.4.1 Using the βbreakβ keyword......Page 471
15.4.2 Using the βforβ keyword......Page 472
15.5.1 Using the timer peripherals......Page 473
15.5.2 Using pulse width modulation......Page 476
Summary......Page 477
16.1 The main idea β using C for data manipulation......Page 478
16.2.2 Using the 18F2420 analog-to-digital converter......Page 479
16.2.4 Simulating the light-seeking program......Page 484
16.3.2 Arrays......Page 486
16.3.3 Using pointers with arrays......Page 487
16.3.6 A word on evaluating the βwhileβ condition......Page 488
16.3.7 Simulating the program example......Page 489
16.4 Using the Inter-Integrated Circuit peripheral......Page 491
16.4.1 An example Inter-Integrated Circuit program......Page 492
16.5.1 Overview of example program......Page 494
16.5.2 Using library functions for data formatting......Page 495
Summary......Page 497
17.1 The main idea β more C and the wider C environment......Page 498
17.2 Assembler inserts......Page 499
17.3 Controlling memory allocation......Page 500
17.3.1 Memory allocation pragmas......Page 501
17.3.2 Setting the Configuration Words......Page 502
17.4.2 Locating and identifying the Interrupt Service Routine......Page 503
17.5.1 Using Timer 0......Page 504
17.5.2 Using interrupts, and the Interrupt Service Routine action......Page 505
17.5.3 Simulating the flashing LEDs program......Page 506
17.6.1 Storage classes......Page 508
17.6.3 Duration......Page 509
17.6.6 Storage class examples......Page 510
17.7.1 The C18 start-up files......Page 511
17.7.3 Simulating c018i.c......Page 512
17.8 Structures, unions and bit-fields......Page 514
17.9 Processor-specific header files......Page 515
17.9.1 Special Function Register definitions......Page 516
17.10.1 What the Linker does......Page 517
17.10.2 The Linker Script......Page 518
17.10.3 The .map file......Page 519
Summary......Page 520
References......Page 521
CHAPTER 18 -
Multi-tasking and the real-timeoperating system......Page 522
18.1.1 Multi-tasking β tasks, priorities and deadlines......Page 523
18.1.2 So what is βreal timeβ?......Page 524
18.2.1 Evaluating the super loop......Page 525
18.2.3 Using interrupts for prioritisation β the foreground/background structure......Page 526
18.2.5 A general-purpose βoperating systemβ......Page 527
18.3 The real-time operating system......Page 528
18.4.1 Cyclic scheduling......Page 529
18.4.2 Round-robin scheduling and context switching......Page 530
18.4.3 Task states......Page 531
18.4.4 Prioritised pre-emptive scheduling......Page 532
18.4.6 The role of interrupts in scheduling......Page 533
18.5.2 Writing tasks and setting priority......Page 534
18.6 Data and resource protection β the semaphore......Page 535
References......Page 536
19.1 The main idea β Salvo, an example RTOS......Page 537
19.1.1 Basic Salvo features......Page 538
19.2.1 Building Salvo applications β the library build......Page 539
19.2.3 Using Salvo with C18......Page 540
19.3.1 Initialisation and scheduling......Page 541
19.4.1 Program overview and the main function......Page 543
19.4.2 Tasks and scheduling......Page 545
19.4.4 Setting the configuration file......Page 546
19.4.5 Building the Salvo example......Page 547
19.4.6 Simulating the Salvo program......Page 548
19.5.1 An example program using an interrupt-based clock tick......Page 549
19.5.3 Using interrupts and establishing the clock tick......Page 552
19.5.5 Using a binary semaphore......Page 554
19.5.6 Simulating the program......Page 555
19.6 Using Salvo messages and increasing real-time operatingsystem complexity......Page 557
19.7 A program example with messages......Page 558
19.7.2 The task: USnd_Task......Page 562
19.7.4 The use of messages......Page 563
19.7.5 The use of interrupts and the Interrupt Service Routines......Page 564
References......Page 567
Section 5
Where Can We Go from Here? Distributed Systems, Bigger Systems......Page 568
20.1 The main idea β networking and connectivity......Page 569
20.1.1 A word on protocols......Page 570
20.2 Infrared connectivity......Page 571
20.2.1 The Infrared Data Association and the PIC microcontroller......Page 572
20.3.1 Bluetooth......Page 573
20.3.3 Zigbee and the PIC microcontroller......Page 574
20.4.1 The Controller Area Network......Page 575
20.4.2 Controller Area Network and the PIC microcontroller......Page 576
20.4.3 The Local Interconnect Network......Page 578
20.4.4 The Local Interconnect Network and the PIC microcontroller......Page 579
20.5 The Universal Serial Bus......Page 580
20.5.1 Using PIC microcontrollers with USB......Page 581
20.6 Embedded systems and the Internet......Page 582
References......Page 583
CHAPTER 21 -
Moving beyond 8-bit: a surveyof larger PIC microcontrollers......Page 585
21.3 The PIC24F family......Page 586
21.3.1 The CPU......Page 589
21.3.2 Memory......Page 590
21.3.3 Traps and interrupts......Page 593
21.3.5 Power supply......Page 594
21.3.6 The pins and ports......Page 596
21.3.7 Peripherals and the Real-Time Clock and Calendar......Page 597
21.3.8 Conclusion on the PIC24F family......Page 598
21.4.1 What is Digital Signal Processing?......Page 599
21.4.3 The Digital Signal Processing engine......Page 601
21.5.1 Overview of PIC32 architecture......Page 604
21.5.2 The Central Processing Unit......Page 607
21.5.2 The memory......Page 608
21.6 A last and final conclusion......Page 609
References......Page 610
Questions......Page 611
APPENDIX 1 -
The PIC 16 Series instruction set......Page 612
APPENDIX 2 -
The electronic ping-pong program......Page 614
APPENDIX 3
The Derbot AGV - hardware design details......Page 619
The Derbot incremental shaft encoder......Page 621
APPENDIX 4
Some basics of Autonomous Guided Vehicles......Page 623
APPENDIX 5
The PIC 18 Series instruction set......Page 627
APPENDIX 6
Essentials of C......Page 632
Index......Page 637
π SIMILAR VOLUMES
This book is a hands-on introduction to the principles and practice of embedded system design using the PIC microcontroller. Packed with helpful examples and illustrations, it gives an in-depth treatment of microcontroller design, programming in both assembly language and C, and features advanced to
This book is a hands-on introduction to the principles and practice of embedded system design using the PIC microcontroller. Packed with helpful examples and illustrations, it gives an in-depth treatment of microcontroller design, programming in both assembly language and C, and features advanced to
This book is a hands-on introduction to the principles and practice of embedded system design using the PIC microcontroller. Packed with helpful examples and illustrations, it gives an in-depth treatment of microcontroller design, programming in both assembly language and C, and features advanced to
This book is a hands-on introduction to the principles and practice of embedded system design using the PIC microcontroller. Packed with helpful examples and illustrations, it gives an in-depth treatment of microcontroller design, programming in both assembly language and C, and features advanced to