. ~ ~ 4 . :A R R L" s,' .' . ~ , • ) f Author Mark Spencer,WA8SME, Editor Nancy G.Hallas, W1NCY Production Staff Michelle Bloom,WB1ENT Jodi Morin, KA1JPA MatyWeinberg, KB1EIB Sue Fagan, KB10KW, Cover Design David Pingree, N1NAS, Technical Illustrations • Copyright© 2010by TheAmericanRadio RelayLeague,Inc. Copyrightsecuredunderthe Pan-AmericanConvention Allrightsreserved.Nopartofthisworkmay bereproduced inany form exceptbywritten permissionofthe publisher.Allrights of translationarereserved. PrintedinCanada Quedanreservados todoslosderechos ISBN:978-0-97259-0-0892 Order number:0892 FirstPrinting The MPLal:fJ9 software contained on the included CD-ROM is reprinted with permission of the copyright holder,MicrochipTechnology Incorporated.All rights reserved. No further reprints or reproductions may be made without MicrochipTechnology Inc's prior written consent. PI(;® is a registered trademark of MicrochipTechnology Inc inthe US and othercountries. PICDEM@is a trademark of Microchip Technology Inc inthe US and othercountries. Table of Contents 1.Introduction Appendix 1 Glossary 2. Inside the PIC16F676 Appendix 2 Answers to Chapter Questions 3.Software and Hardware Setup Appendix 3 Keyer Construction Manual 4. Program Architecture Appendix 4 PIC16F676 Include File 5. Program Development Contents 6.Working With Registers Index The Most Important Chapter 7. Instruction Set Overview CD-ROM Contents 8.Device Setup 1.MPLAB IDE Software 9. Delay Subroutines 2. Device Documentation 10. Basic Input/Output 3. Parts List and Specification 11.Analog to Digital Converters 4.Video Files 12.Comparators 5. Chapter Exercise Program Files 13. Interrupts 14.Timer 0 andTimer 1 Resources 15.Asynchronous Serial Communications 16.Serial Peripheral Interlace Communications 17.WorkingWith Data 18. Putting It AllTogether Foreword AmateurRadio hasalong traditionof whatwe affectionatelycall"homebrcwing." Homebrewing simply means theact of building a piece ofequipmentwith your bare hands, oftenin thecomfortofyour ownhome.Intheearliestdaysof AmateurRadio,homebrewing was mandatory;there were nocommercial products available.Buteven inthismodem eraof click-and-purchase Internetshopping,many hamsstillpreferto build theirown equipment wheneverpossible. ' One thing that haschanged in recent years isthenature of whatwe build.Hams are increasinglyattracted to theextraordinarypotentialofmicrocontrollers astoolsineverything from stationaccessoriesto transceivers.Asaresult, they're eagerto learn howt? program thesedevicesand putthem to work. InARRL's PIC'> ProgrammingforBeginners,MarkSpencer,WA8SME,shows youhowto "speak" thelanguage of microcontrollers.You'llfind that workingwith PICs issurprisingly easy,educationaland, mostof all, fun. David Sumner, KIZZ ARRL Executive VicePresident Newington,Connecticut March 2010 Acknowledgements and Dedication I would like to acknowledge the contributions ofyou, the readerofthistext. As a life-long learner, you are my real inspiration. Attimes itfeels like technology is passing usby,but I am inspired by those who want to be more than justtechnology users...and Ithank you for that. I would also like to thank Ron Cade,W6ZQ, who reviewed the draft of thisbook as a student of microcontrollers. He kept me honest and true to my commitment to not to assume the reader understands what I mean. MarkSpencer,WA8SME(andlife longlearner) About the Author Mark Spencer,WA8SME,hasbeen ahamradio operator forover45 yearsand hasalso held the callsG5EPV,DAIOY,and HL9AW.Mark isnot sure ifhis interest inscience and technologyfostered his interest in ham radio,of ifhis interest inham radiofostered histechnicalcareerpath and interests.He hasdegrees in Metallurgical Engineering and Communications.Originallyfrom the Detroit,Michigan area,Markentered educationas a secondcareer following a20 year careeras an Air ForceOfficer flyingT-38, 8-52,'U-2,and TR-l aircraft. Mark isa self-described and practicing life-long learner.This passion for learning,and helping otherstolearn,supports both hisprofessionaland leisure etforts.He iscurrently the ARRL'sEducationand Technology Program(ETP) Coordinator.His primary ETP responsibilities include developingcurriculumleading toward wirelesstechnologyliteracy, providing assistance toteachers implementing hamradio and related content intheir school's curriculum,managingtheARRL ham radio equipmentgrant program for schools, and instructing teachers in wireless technology literacy during theTeachers Institutes. Mark'sdefinition ofcomputerliteracycame aboutduring hiscombat experiences in Desert Storm,and that visionfor computer literacy has served as hiscompass indeveloping instructionalprogramsand in his writings.Though personally passionateaboutlearning, each and every personalendeavor hasthedualpurpose offacilitating the learning of others...including thistext. Mark's current ham radio interests include ham satellites and adapting microcontroller technology toham radio. About the ARRL Theseed forAmateurRadiowasplanted inthe 1890s,when Guglielmo Marconibegan hisexperimentsinwireless telegraphy.Soonhe wasjoinedbydozens,thenhundreds,ofothers who wereenthusiasticaboutsending andreceiving messagesthroughthe air- some withacommercial interest.butotherssolelyoutofalove for thisnewcommunications medium.The United StatesgovernmentbeganlicensingAmateurRadiooperatorsin 1912. By 1914,there were thousands of AmateurRadiooperators- hams- inthe UnitedStates. HiramPercyMaxim,a leading Hartford,Connecticutinventorand industrialist.saw the needfor anorganizationtobandtogether this fledgling groupofradio experimenters.InMay 1914 he founded the AmericanRadio RelayLeague (ARRL)tomeet thatneed. TodayARRL,withapproximately 155,000 members,isthe largestorganizationof radio amateurs intheUnited States.The ARRL isanot-far-profitorganization that: • promotesinterest inAmateurRadiocommunicationsand experimentation • representsUSradio amateurs inlegislativematters, and • maintainsfraternalismanda high standardofconduct amongAmateurRadio operators." At ARRL headquartersinthe Hartfordsuburbof Newington,thestaffhelpsserve theneedsof members.ARRL is also InternationalSecretariatforthe International AmateurRadio Union,whichismade upofsimilarsocietiesin 150 countriesaroundthe world. ARRLpublishes the monthlyjournalQST,as wellasnewslettersand many publicationscovering allaspectsof AmateurRadio.Itsheadquartersstation,WIAW,transmitsbulletinsof interest toradioamateurs'andMorsecode prac ticesessions.The ARRL alsocoordinatesanextensive fieldorganization.which includesvolunteers whoprovide techni calinformationand othersupportservicesfor radio amateursas well ascommunications forpublic-serviceactivities.In addition,ARRLrepresentsUSamateurswith the FederalCommunicationsCommission and other governmentagencies inthe USandabroad. MembershipinARRL meansmuch morethanreceiving QSTeachmonth.Inadditiontotheservicesalready described,ARRLoffersmembership services onapersonallevel,suchas theTechnical InformationService-where memberscan getanswersby phone,emailor the ARRLwebsite, toalltheirtechnicalandoperatingquestions. Fun ARRLmembership (available onlyto licensedradioamateurs)givesyouavoice inhowtbe affairsof theorga nization are governed. ARRLpolicyissetbya BoardofDirectors (one fromeachof 15 Divisions).Eachyear,one-third of the ARRLBoard of Directorsstandsforelectionbythe fun memberstheyrepresent.Theday-to-dayoperationof ARRLHQis managedbyanExecutive Vice Presidentand hisstaff. No matter whataspectof AmateurRadio attractsyou,ARRLmembership isrelevant and important.There would beno Amateur Radioaswe knowittodaywere itnotfor theARRL. Wewouldbe happyto welcomeyou asamember! (AnAmateur Radio license isnotrequired forAssociate Membership.)For more information aboutARRLandanswers toanyquestionsyou may have about AmateurRadio,writeorcall: ARRL- the nationalassociationfor Amateur Radio 225MainStreet NewingtonCT 06111-1494 Voice: 860-594-0200 Fax: 860-594-0259 E-mail: [email protected] Internet: www.arrl.org! Prospective new amateurscall(toll-free): 800-32-NEW HAM (800-326-3942) [email protected] orcheckoutARRLWebatwww.arrl.org/ ,:: -- -- ~ o ~... 9 , c Introduction to Programming Microcontrollers
Description: