ebook img

Microcontrollers: High-Performance Systems and Programming PDF

694 Pages·2013·23.885 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Microcontrollers: High-Performance Systems and Programming

Electrical Engineering Sanchez Canton Microcontrollers HIGH-PERFORMANCE SYSTEMS AND PROGRAMMING Microcontrollers M Microcontrollers: High-Performance Systems and Programming discusses the practical factors that make the high-performance PIC i c series a better choice than their mid-range predecessors for most systems. However, one consideration in favor of the mid-range r devices is the abundance of published application circuits and code samples. This book fills that gap: o HIGH-PERFORMANCE SYSTEMS • Provides downloadable software, including tools, resources, c supplementary materials, and code listings AND PROGRAMMING • Includes sample circuits with their corresponding programs, o as well as tested PCB files n • Focuses on the popular embedded systems with PIC18 series microcontrollers t • Contains an appendix with a C language tutorial, PIC18 r instruction set, links to useful tools and software Julio Sanchez • Supplies sample circuits that are not copyrighted or patented, so o readers can freely use them in their own applications • Covers selected topics and examples that provide solutions to l Maria P. Canton problems that practicing engineers may encounter and are not l readily found in the literature e r Designed to be functional and hands-on, this book provides sample circuits with their corresponding programs. It clearly depicts and s labels the circuits, in a way that is easy to follow and reuse. The book matches sample programs to the individual circuits and discusses general programming techniques. K16291 Microcontrollers HIGH-PERFORMANCE SYSTEMS AND PROGRAMMING K16291_FM.indd 1 9/24/13 11:25 AM K16291_FM.indd 2 9/24/13 11:25 AM Microcontrollers HIGH-PERFORMANCE SYSTEMS AND PROGRAMMING Julio Sanchez Eastern Florida State College Maria P. Canton Brevard Public Schools Boca Raton London New York CRC Press is an imprint of the Taylor & Francis Group, an informa business K16291_FM.indd 3 9/24/13 11:25 AM CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2014 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Version Date: 20130923 International Standard Book Number-13: 978-1-4665-6668-2 (eBook - PDF) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the valid- ity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or uti- lized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopy- ing, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http:// www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com Tab le of Con tents Pref ace xx Chapt er 1 Microcontrollers for Em bed ded Syst ems 1 1.1 Em bed ded Sys tems 1 1.2 Micro chip PIC 1 1.2.1 PIC Ar chi tec ture 2 1.2.2 Pro gramm ing the PIC 2 PIC Pro gram mers 3 De vel op ment Boards 4 1.3 PIC Arc hit ect ure 4 1.3.1 Base line PIC Fam ily 5 PIC10 de vices 6 PIC12 De vices 7 1.3.2 Mid-Range Fam ily 9 PIC14 De vices 9 PIC16 De vices 9 1.3.3 High-Per for mance PICs and DSPs 10 Dig i tal Sig nal Pro ces sor 11 Analog-to-Dig i tal 12 Chapt er 2 PIC18 Ar chi tec ture 13 2.1 PIC18 Fami ly Over view 13 2.1.1 PIC18FXX2 Group 14 2.1.2 PIC18FXX2 De vice Group Over view 15 2.1.3 PIC18F4X2 Block Di ag ram 16 2.1.4 Cen tral Pro cess ing Unit 17 Sta tus Reg is ter 17 Pro gram Coun ter Reg is ter 17 Hard ware Mul ti plier 18 In ter rupts 18 2.1.5 Spe cial CPU Feat ures 19 Watch dog Timer 20 Wake-Up by In ter rupt 21 Low Volt age De tec tion 21 De vice Con fig u ra tion 21 2.2 Mem ory Or ga ni za tion 22 2.2.1 Pro gram Mem ory 22 v vi Tab le of Cont ents 2.2.2 18FXX2 Stack 23 Stack Op er a tions 23 Fast Reg is ter Stack 24 In struc tions in Mem ory 25 2.2.3 Data Mem ory 25 2.2.4 Data EEPROM Mem ory 27 2.2.5 In di rect Ad dress ing 28 2.3 PIC18FXX2 Osc ill at or 29 2.3.1 Os cil la tor Op tions 29 Crys tal Os cil la tor and Ce ramic Res o na tor 29 RC Os cil la tor 30 Ex ter nal Clock In put 31 Phase Locked Loop Os cil la tor Mode 31 2.4 Syst em Res et 31 2.4.1 Re set Ac tion 32 Power-On Res et (POR) 33 Power-Up Timer (PWRT) 33 Osc ill at or Start-Up Timer (OST) 33 PLL Lock Time-Out 33 Brown-Out Re set (BOR) 33 Time-Out Seq uence 33 2.5 I/O Ports 34 2.5.1 Port Reg is ters 34 2.5.2 Para l lel Slave Port 35 2.6 Int er nal Modu les 35 2.6.1 PIC18FXX2 Mod ules 35 Chapt er 3 Prog ram ming Tools and Soft ware 37 3.1 En vi ron ment 37 3.1.1 Em bedd ed Sys tems 37 3.1.2 High- and Low-Level Lan guages 38 3.1.3 Lan guage-Spe cific Soft ware 40 3.2 Microc hip's MPLAB 40 3.2.1 MPLAB X 40 3.2.2 De vel op ment Cy cle 40 3.3 An In te grated De vel op ment En vi ron ment 41 3.3.1 Ins tall ing MPLAB 42 3.3.2 Crea t ing the Pro ject 43 3.3.3 Set ting the Pro ject Build Op tions 45 3.3.4 Adding a Source File 47 3.3.5 Build ing the Pro ject 48 3.3.6 .hex File 48 3.3.7 Quickbuild Op tion 50 3.4 MPLAB Sim ul at ors and Debuggers 50 3.4.1 MPLAB SIM 51 Us ing Break points 51 Watch Win dow 52 Sim u la tor Trace 52 3.4.2 MPLAB Stimu l us 54 Stim u lus Di a log 54 3.4.3 MPLAB Hard ware Debuggers 55 Tab le of Cont ents vii 3.4.4 An Im prov ised Debugger 56 3.5 De vel op ment Pro gram mers 56 3.5.1 Micro chip PICkit 2 and PICkit 3 58 3.5.2 Micropro USB PIC Pro gramm er 60 3.5.3 MPLAB ICD 2 and ICD 3 In-Cir cuit Debuggers/Pro gramm ers 60 3.6 Test Cir cuits and De velo pm ent Boards 61 3.6.1 Com mer cial De vel op ment Boards 61 3.6.2 Cir cuit Prot o type 63 3.6.3 Bread board 64 Lim i ta tions of Bread boards 65 Breadboarding Tools and Tech niques 66 3.6.4 Wire Wrapp ing 67 3.6.5 Perfboards 67 3.6.6 Printed Cir cuit Boards 68 Chapt er 4 As sem bly Lang uage Prog ram 71 4.1 Ass em bly Lan guage Code 71 4.1.1 A Cod ing Tem plate 71 Pro gram Header 73 Pro gram En vi ron ment Di rec tives 73 Con fig u ra tion Bits 73 Er ror Mes sage Level Con trol 74 Vari ables and Con stants 74 Code Area and In ter rupts 74 4.1.2 Pro gramm ing Style 74 Source File Com ments 75 4.2 Def ini ng Data Ele m ents 75 4.2.1 equ Di rec tive 76 4.2.2 cblock Di rec tive 76 4.2.3 Ac cess to Banked Mem ory 77 4.3 Nami ng Con vent ions 77 4.3.1 Reg is ter and Bit Names 77 4.4 PIC 18Fxx2 In struc tion Set 79 4.4.1 Byte-Ori ented In struc tions 80 4.4.2 Bit-Ori ented In struc tions 80 4.4.3 Lit eral Ins truc tions 80 4.4.4 Con trol Ins truc tions 80 Chapt er 5 PIC18 Prog ram ming in C Lan guage 85 5.1 C Comp ile rs 85 5.1.1 C ver sus As sem bly Lan guage 85 5.1.2 MPLAB C18 86 5.2 MPLAB C18 Ins tall at ion 86 5.2.1 MPLAB Soft ware Com pon ents 87 5.2.2 Con fig u ra tion Op tions 88 5.2.3 Sys tem Re quire ments 89 5.2.4 Ex ec u tion Flow 90 5.3 C Comp iler Proj ect 91 5.3.1 Crea t ing the Pro ject 91 viii Tab le of Cont ents Se lect Hardw are De vice 92 Se lect the Lang uage Toolsuite 92 Cre ate a New Pro ject 93 Add Files to the Pro ject 95 5.3.2 Sel ect ing the Build Di rec tory 96 5.4 A First Pro gram in C 98 5.4.1 Source Code Anal y sis 99 main() Func tion 100 Lo cal Func tions 101 Chapt er 6 C Lan guage in an Em bed ded En vi ronm ent 103 6.1 MPLAB C18 Sys tem 103 6.1.1 PIC18 Ex tended Mode 104 6.2 MPLAB C18 Lib rar ies 104 6.2.1 Start-Up Rou tines 104 6.2.2 Onl ine Help for C18 and Li brar ies 105 6.3 Pro ces sor-In de pend ent Li brar ies 106 6.3.1 Gen eral Soft ware Li brary 106 Char ac ter Clas si fi ca tion Func tions 107 Data Con ver sion Func tions 107 Mem ory and String Ma nip u la tion Func tions 108 De lay Func tions 110 Re set Func tions 111 Char ac ter Out put Func tions 112 6.4 Pro ces sor-Spe cific Li brar ies 115 6.4.1 Hardw are Per iph eral Lib rary Func tions 115 6.4.2 Soft ware Pe riph er als Li brary Func tions 116 6.4.3 Mac ros for Inline As sem bly 116 6.4.4 Pro ces sor-Spe cific Header Files 117 6.5 Math Lib rar ies 118 6.5.1 ANSI-IEEE 754 Bi nary Float ing-Point Stan dard 118 Encodings 119 Round ing 119 6.5.2 Stan dard Math Li brary Func tions 120 6.5.3 Float ing-Point Math Sam ple Pro gram 120 6.6 C18 Lang uage Spec ifi cs 122 6.6.1 C18 Int e ger Data Types 122 6.6.2 C18 Float ing-Point Data Types 122 6.6.3 Endianness 123 6.6.4 Stora ge Classes 123 6.6.5 Static Func tion Ar gum ent 123 6.6.6 Stor age Qual i fi ers 123 far and near Qual i fi ers 123 rom and ram Qual i fi ers 124 Chapt er 7 Prog ram ming Sim ple In put and Out put 125 7.1 Port-Conn ected I/O 125 7.1.1 A Sim ple Cir cuit and Code 125 7.1.2 Cir cuit Schem at ics 125 7.1.3 As sem bler Sim ple I/O Pro gram 126 Tab le of Cont ents ix 7.1.4 As sem bler Source Code Anal y sis 129 Com mand Mon i tor ing Loop 129 Ac tion on the LEDs 130 A De lay Rou tine 130 7.2 C Lang uage Simp le I/O Pro gram 131 7.2.1 C Source Code Anal y sis 132 main() Func tion 133 7.3 Seven-Segm ent LED Prog ramm ing 134 7.3.1 Com puted Goto 135 7.3.2 As sem bler Seven-Seg ment LED Pro gram 136 Ac cess Bank Op er a tion 136 Port A for Dig i tal Op er a tion 137 DIP Switch Proc essi ng 138 Seven-Seg ment Code with Com puted Goto 139 7.3.3 As sem bler Tab le Lookup Sam ple Pro gram 140 7.4 C Lang uage Seven-Segm ent LED Prog rams 141 7.4.1 Code Sel ec tion by Switch Con struct 142 7.4.2 Code Sel ec tion by Tab le Lookup 142 7.5 A Demo ns trat ion Board 143 7.6.1 Power Sup ply 145 Volt age Reg u la tor 145 Chapt er 8 In ter rupts 147 8.1 Int err upt Mecha n ism 147 8.2 PIC18 Int err upt Syst em 147 8.2.1 Hardw are Sources 148 8.2.2 Int er rupt Con trol and Sta tus Reg is ters 148 INTCON Reg is ters 149 PIE Reg is ters 151 PIR Reg is ters 152 IPR Reg is ters 152 8.2.3 In ter rupt Pri or i ties 154 High-Pri or ity In ter rupts 154 Low-Pri or ity In ter rupts 155 An In ter rupt In ter rupt ing An other One 155 8.2.4 Con text Sav ing Op er a tions 155 Con text Sav ing during Low-Pri or ity In ter rupts 156 8.3 Port B Int err upts 157 8.3.1 Port B Ex ter nal In ter rupt 158 8.3.2 INT0 In ter rupt Demo Pro gram 158 cblock Di rec tive 158 Vectoring the In ter rupt 159 Ini tial iza tion 160 Setup INT0 160 Pro gram Fore ground 161 In ter rupt Ser vice Rou tine 161 Switch Debouncing 162 In ter rupt Ac tion 162 8.3.3 Port B Line Change Int er rupt 163 Reentrant In ter rupts 164 Mul ti ple Ex ter nal In ter rupts 165

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.