Example: stock market

EMBEDDED SYSTEMS PROGRAMMING WITH THE PIC16F877

EMBEDDED SYSTEMS PROGRAMMING WITH THE PIC16F877 Second Edition By Timothy D. Green Copyright 2008 by Timothy D. Green All Rights Reserved. 2 Table of Contents Preface .. 5 List of Figures .. 6 Abbreviations and Acronyms .. 7 Trademarks .. 10 Chapter 1 Introduction to ESP and the PIC .. 11 Chapter 2 Microcontrollers and the PIC16F877 .. 15 Section Chapter Summary .. 15 Section Memory and Memory Organization .. 15 Section The PIC16F877 .. 16 Section PROGRAMMING the PIC .. 17 Chapter 3 Simple PIC Hardware & Software ( Hello World ) .. 20 Section Chapter Summary .. 20 Section A Simple Example System.

5-2 PIC Matrix Keypad Interface Circuit 5-3 Seven Segment LED Digit Display in Common Cathode and Common Anode Forms 5-4 Single LED Digit Drives for Common Cathode/Anode Forms 5-5a Multiplexed LED Digit Drives for Common Cathode Form 5-5b Multiplexed LED Digit Drives for Common Anode Form

Tags:

  Circuit

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of EMBEDDED SYSTEMS PROGRAMMING WITH THE PIC16F877

1 EMBEDDED SYSTEMS PROGRAMMING WITH THE PIC16F877 Second Edition By Timothy D. Green Copyright 2008 by Timothy D. Green All Rights Reserved. 2 Table of Contents Preface .. 5 List of Figures .. 6 Abbreviations and Acronyms .. 7 Trademarks .. 10 Chapter 1 Introduction to ESP and the PIC .. 11 Chapter 2 Microcontrollers and the PIC16F877 .. 15 Section Chapter Summary .. 15 Section Memory and Memory Organization .. 15 Section The PIC16F877 .. 16 Section PROGRAMMING the PIC .. 17 Chapter 3 Simple PIC Hardware & Software ( Hello World ) .. 20 Section Chapter Summary .. 20 Section A Simple Example System.

2 20 Section Summary of Instructions and Concepts .. 25 Chapter 4 The PIC Instruction Set (Part I) .. 27 Section Chapter Summary .. 27 Section The PIC16F877 Instruction Set .. 27 Section Summary of Instructions and Concepts .. 33 Chapter 5 The PIC Instruction Set (Part II) .. 34 Section Chapter Summary .. 34 Section Introduction .. 34 Section Keypad and Display Interface .. 35 Section The STATUS Register and Flag Bits .. 39 Section The Keypad Software .. 40 Section The LED Display Software .. 43 Section Improved Display and Indirect Addressing .. 46 Section Odds & Ends .. 50 Section Using KEY_SCAN and DISPLAY Together.

3 54 Section A Last Look at the Advanced Security System .. 56 Section Summary of Instructions and Concepts .. 57 Chapter 6 Fundamental ESP Techniques .. 59 Section Chapter Summary .. 59 Section Introduction .. 59 Section Software Readability .. 59 Section Software Maintainability .. 60 3 Chapter 6 Section Software Fundamentals .. 60 Section The Background Routine .. 61 Section The Watch-Dog Timer .. 61 Section Event-Driven Software .. 62 Section Interrupts .. 65 Section Slow Inputs and Outputs .. 65 Section Software Time Measurement .. 66 Section Hashing .. 67 Section Waveform Encoding .. 68 Section Waveform Decoding.

4 71 Section RAM, ROM, and Time Tradeoffs .. 75 Section ROM States .. 75 Section Limitations of C/C++ .. 76 Chapter 7 Advanced ESP .. 78 Section Chapter Summary .. 78 Section Introduction .. 78 Section Sine Wave Generation ..78 Section Dual-Tone-Multi-Frequency (DTMF) Signaling ..81 Section Pulse-Width Modulation ..82 Section ADPCM Data Compression ..84 Section Test Functions and System Ideas ..87 Chapter 8 PIC Peripherals and Interrupts ..91 Section Chapter Summary ..91 Section Overview of the PIC Peripherals ..91 Section Input/Output Ports ..93 Section Port A .. 93 Section Port B, Port C, Port D.

5 95 Section Port E .. 95 Section Interrupts .. 95 Section ADC and Analog MUX .. 98 Section Watch-Dog Timer .. 102 Section Timer 0 .. 103 Section Timer 1 .. 105 Section Timer 2 .. 106 Section Capture Mode .. 107 Section Compare Mode .. 109 Section Pulse-Width Modulation (PWM) .. 111 Section Parallel Slave Port .. 114 4 Chapter 8 Section EEPROM Data Memory .. 116 Section FLASH Program Memory .. 117 Section FLASH Code & Data EEPROM Protection .. 118 Section The CONFIGURATION Word .. 119 Section Sleep Modes & Reset Modes .. 120 Chapter 9 PIC Peripherals, Serial Communications Ports.

6 122 Section Chapter Summary ..122 Section Introduction ..122 Section USART (Overview) ..122 Section USART (Asynchronous Mode, Full-Duplex) ..123 Section USART (Synchronous, Master Mode) .. 127 Section USART (Synchronous, Slave Mode) .. 128 Section Serial Peripheral Interface (Master Mode) .. 128 Section Serial Peripheral Interface (Slave Mode) ..132 Section I2C System Overview ..134 Section I2C Slave Mode ..137 Section I2C Master Mode .. 139 Chapter 10 DSP Fundamentals.

7 147 Section Chapter Summary .. 147 Section Introduction .. 147 Section An Example: A Low-Pass Filter .. 148 Section An Example: A High-Pass Filter .. 148 Section DSP Filters in General .. 149 Section Aliasing and the Nyquist Sampling Theorem ..149 Section DSP Cookbook I: A Simple LPF/HPF .. 151 Section DSP Cookbook II: A Simple BPF .. 152 Section DSP Cookbook III: A Median Filter .. 153 Section DSP Example I: Standard DTMF Decoding ..154 Section DSP Example II: Alternative DTMF Decoding .. 155 Section DSP Application: Speech Compression .. 159 Appendix A The PIC16F877 Instruction Set .. 163 Appendix B Useful C++ Programs for PIC ASM Applications.

8 180 Appendix C Special Function Registers (RAM Addresses & Bits) ..185 Appendix D PIC16F877 Register File Map ..191 Appendix E PIC16F877 Pin Function Map ..192 Appendix F Save/Restore Registers on Interrupt .. 193 References .. 195 5 Preface This book is intended for use by Junior-level undergraduates, Senior-level undergraduates, and Graduate students in electrical engineering as well as practicing electrical engineers and hobbyists and seeks to provide a gentle introduction to EMBEDDED SYSTEMS PROGRAMMING with the Microchip PIC16F877 microcontroller. After introducing the PIC16F877 and its PROGRAMMING , this book covers the fundamental techniques and advanced level techniques of EMBEDDED SYSTEMS PROGRAMMING in a general sense.

9 The general sense ESP techniques can be applied to any microcontroller. There is also an introduction to the fundamentals of digital signal processing (DSP) using the PIC16F877 . I would like to thank Dr. Dan Simon of the Cleveland State University Electrical Engineering Department for his kind and valuable help and suggestions in the preparations for this book. I would also like to thank John R. Owerko and James R. Jackson, both of Products, Inc., for their expertise in the security SYSTEMS market. I owe them both a great debt for my knowledge of security SYSTEMS and for expanding my knowledge of the techniques of EMBEDDED SYSTEMS PROGRAMMING in general. Special thanks also go to Sister Renee Oliver who proofread the manuscript and offered many helpful suggestions.

10 Thanks go to my friends Damian Poirier, Jim Strieter, Greg Glazer, Zarif Bastawros, Brian McGeever, Ted Seman, and Jim Chesebrough who offered many helpful suggestions. Any errors that remain in the text are mine and I will correct them in the next edition. Timothy D. Green November 2005 Cleveland, Ohio 6 List of Figures 2-1 uP Internal View Block Diagram 2-2 PIC16F877 Internal Block Diagram 3-1 Simple Hardware View (Ports Only) 3-2 Basic Hardware System Example 4-1 A Simple Security System 5-1 Twelve-Key Matrix Keypad 5-2 PIC Matrix Keypad Interface circuit 5-3 Seven Segment LED Digit Display in Common Cathode and Common Anode Forms 5-4 Single LED Digit Drives for Common Cathode/Anode Forms 5-5a Multiplexed LED Digit Drives for Common Cathode Form 5-5b Multiplexed LED Digit Drives for Common Anode Form 5-6 Illustration of Indirect RAM Addressing 5-7 Diagram of RLF and RRF Instructions 6-1 All Digital Watch-Dog Timer circuit 6-2 Event-Driven Push-Button Switch DeBouncing 6-3 Manchester Code Waveform 6-4 Decoding of Manchester


Related search queries