关闭

关闭

关闭

封号提示

内容

首页 AVR_Studio_5使用说明.pdf

AVR_Studio_5使用说明.pdf

AVR_Studio_5使用说明.pdf

上传者: 茕茕 2011-11-04 评分 0 0 0 0 0 0 暂无简介 简介 举报

简介:本文档为《AVR_Studio_5使用说明pdf》,可适用于IT/计算机领域,主题内容包含AVRSTUDIO快速入门指南by伯兮科技infoliboxicnAVRStudio按部就班编程AVRStudio是atmel推出的新的编程环境使用符等。

AVRSTUDIO快速入门指南by伯兮科技infoliboxicnAVRStudio按部就班编程AVRStudio是atmel推出的新的编程环境使用的用户可能不太适应通过一段时间的摸索本人将主要过程进行一下小结希望起到抛砖引玉的作用。该软件可以在wwwatmelcom中找到本人用的是windows平台。软件下载和安装这里就不再描述了。安装好后桌面会出现如下的图标:双击打开该软件。或者通过开始菜单打开软件打开软件后显示如下:AVRSTUDIO快速入门指南by伯兮科技infoliboxicnAVRSTUDIO快速入门指南by伯兮科技infoliboxicn如上图单击ExampleProject或快捷键(CtrlShiftE)Atmel提供了个项目例程。我们这里只选择一个进行说明即使用MEGA进行简单的寄存器操作这是单片机应用的基础也是全部!AVRSTUDIO快速入门指南by伯兮科技infoliboxicn选择megaAVR,bit项目名称ProjectName:按照自己的需要更改还有路径。这里改为:megatest单击okAVRSTUDIO快速入门指南by伯兮科技infoliboxicn错误信息不要管!生成的文件在资源管理器中显示Megagpioexamplec文件就是主函数了。右键菜单属性。AVRSTUDIO快速入门指南by伯兮科技infoliboxicn更改关键选项其余的自己摸索。选中hex今后烧写程序到硬件中使用。AVRSTUDIO快速入门指南by伯兮科技infoliboxicn选择debugging选择模拟器(通常我们并没有atmel提供的硬件)浏览一下主函数:***file*AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*briefmegaAVRSTKGPIOExample**Copyright(C)AtmelCorporationAllrightsreserved**pageLicense**Redistributionanduseinsourceandbinaryforms,withorwithout*modification,arepermittedprovidedthatthefollowingconditionsaremet:**Redistributionsofsourcecodemustretaintheabovecopyrightnotice,*thislistofconditionsandthefollowingdisclaimer**Redistributionsinbinaryformmustreproducetheabovecopyrightnotice,*thislistofconditionsandthefollowingdisclaimerinthedocumentation*andorothermaterialsprovidedwiththedistribution**ThenameofAtmelmaynotbeusedtoendorseorpromoteproductsderived*fromthissoftwarewithoutspecificpriorwrittenpermission**Thissoftwaremayonlyberedistributedandusedinconnectionwithan*AtmelAVRproduct**THISSOFTWAREISPROVIDEDBYATMEL"ASIS"ANDANYEXPRESSORIMPLIED*WARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF*MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENTARE*EXPRESSLYANDSPECIFICALLYDISCLAIMEDINNOEVENTSHALLATMELBELIABLEFOR*ANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIAL*DAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSOR*SERVICESLOSSOFUSE,DATA,ORPROFITSORBUSINESSINTERRUPTION)HOWEVER*CAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICT*LIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAY*OUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCH*DAMAGE****mainpage*sectionintroIntroduction*ThisexampledemonstratesGPIOportaccess,pinaccess,pininterruptand*pinpullupconfiguration**sectionfilesFiles:*megagpioexamplec:megaAVRGPIOexampleapplication*confexampleh:ExampleconfigurationAVRSTUDIO快速入门指南by伯兮科技infoliboxicn**sectionsetupSetup*ThisexampleismadeforSTKwithtwopincablesinthefollowing*strapconfiguration:*PORTB<>SWITCHES*PORTD<>LEDS**sectiondescriptionDescription*Theexamplewillutilizedifferentregistersforsettingandreadingport*andpinGPIOsTheseGPIOsareconnectedtoswitchesandLEDsontheSTK**Intheendoftheexamplepinchangeinterruptsareenabledandcanbe*testedwithSTKSWThiswilltoggleLEDfromtheinterrupthandler*NotallmegaAVRdevicessupportspinchangeinterrupts,soforthosethis*isdisabled**Forthebestdemonstrationit'srecommendedtorunthisinadebugsession*andsinglestepthruthedifferentoperations**sectioncompinfoCompilationInfo*Thissoftwarewaswrittenforthe<Ahref="http:gccgnuorg">GNUGCC<A>*forAVRn*Othercompilersmayormaynotwork**sectioncontactinfoContactInformation*Forfurtherinformation,visit*<Ahref="http:wwwatmelcom">Atmel<A>n*SupportandFAQ:http:supportatmelno*#include"compilerh"#include<avrinterrupth>#include"confexampleh"OnlyusePinChangeInterrupthandlerfordevicessupportingthis#ifdefEXAMPLEPCINTvect***briefPinchangeinterrupthandlerforPB**CreatebreakpointhereandthenrunPressSWinordertotest*this*ISR(EXAMPLEPCINTvect){AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*TogglePD(LED)**Notethatitwilltogglebothonbuttonpressandrelease*PIND=(<<PIND)}#endif***briefMainroutine*intmain(void){Variabletoputswitchinputintouinttval*UseportDforoutputtocontroltheSTKLEDs**Firstsetthedatadirectionregistertoxffinordertosetall*portpinstooutputfunction*DDRD=xffSetoutputlevelshighWillturnoffSTKLEDsPORTD=xffSetoutputlevelslowWillturnonSTKLEDsPORTD=*ForinputweuseportBinordertoreadinputfromtheSTK*switches**Wedon'tneedtosetthesepinstoinputafterresetsincethey*aredefaultsetasinputsafterreset**ButatypicalrequirementwhenreadingswitchesarepullupsSTK*don'trequirethese,butweenabletheinternalpullupsjusttobe*onthesafeside*PORTB=xff*ReadSTKswitchesonportBinputsintoavariableAVRSTUDIO快速入门指南by伯兮科技infoliboxicn**PressanyoftheSTKswitchesinordertoseeadifferencehere*Apresswillbeseenasbitvalueandnotpressisdueto*pullups*val=PINB*It'salsopossibletocontrolasingleorasetofpinsonaport**SettingpinPDhighinordertoturnoffLED*PORTD|=(<<PORTD)SettingpinPDlowinordertoturnonLEDPORTD=~(<<PORTD)TogglebothpinPDandPD,whichtogglesLEDandLED#ifdefined(AVRATmega)||defined(AVRATmega)||defined(AVRATmega)||defined(AVRATmega)*ForoldermegaAVRdevicesreadmodifywritePORTregister*Thisisn'tsafeforinterrupts*PORTD^=(<<PIND)|(<<PIND)#elseUsePINregistertotoggleonnewermegaAVRdevicesPIND=(<<PIND)|(<<PIND)#endifOnlyusePinChangeInterrupthandlerfordevicessupportingthis#ifdefEXAMPLEPCICR*EnablepinchangeinterruptforPBwhichiscontrolledbySW**Firstweneedtoenablepinchangeinterruptforthewantedport*EXAMPLEPCICR=(<<EXAMPLEPCIE)ThenweneedtosetthepinchangeportmasktogetthebitwewantEXAMPLEPCMSK=(<<PCINT)#endifEnableinterruptssei()AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*Busyloop,andabreakpointcanbeusedintheinterrupthandlerto*seeinterruptsbeeingtriggeredbySW*while(true)}AVRSTUDIO快速入门指南by伯兮科技infoliboxicnF,逐语句的执行添加IOVIEWAVRSTUDIO快速入门指南by伯兮科技infoliboxicnF执行下一句上图执行的是DDRD=xff这句AVRSTUDIO快速入门指南by伯兮科技infoliboxicn至此以此类推可以对所有的寄存器进行操作。所有复杂的程序都做了。停止程序的执行!鼠标悬停在PORTD上出现倒立的三角。单击三角选择FindReferencesAVRSTUDIO快速入门指南by伯兮科技infoliboxicn双击查找定义。(上图最后一行#definePORTD…)*Copyright(c),PeterJansenCopyright(c),AtmelCorporationAllrightsreservedRedistributionanduseinsourceandbinaryforms,withorwithoutmodification,arepermittedprovidedthatthefollowingconditionsaremet:*Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimer*Redistributionsinbinaryformmustreproducetheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimerinthedocumentationandorothermaterialsprovidedwiththedistribution*NeitherthenameofthecopyrightholdersnorthenamesofcontributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftwarewithoutspecificpriorwrittenpermissionTHISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMEDINNOEVENTSHALLTHECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSORSERVICESLOSSOFUSE,DATA,ORPROFITSORBUSINESSINTERRUPTION)HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE*AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*$Id:iomh::Zarcanum$**avriomhdefinesforATmegaAsof:ThisshouldbeuptodatewithdatasheetEAVR*#ifndefAVRIOMH#defineAVRIOMH*Thisfileshouldonlybeincludedfrom<avrioh>,neverdirectly*#ifndefAVRIOH#error"Include<avrioh>insteadofthisfile"#endif#ifndefAVRIOXXXH#defineAVRIOXXXH"iomh"#else#error"Attempttoincludemorethanone<avrioXXXh>file"#endif*IOregisters**InputPins,PortF*#definePINFSFRIO(x)*InputPins,PortE*#definePINESFRIO(x)*DataDirectionRegister,PortE*#defineDDRESFRIO(x)*DataRegister,PortE*#definePORTESFRIO(x)*ADCDataRegister*#defineADCWSFRIO(x)*forbackwardscompatibility*#ifndefASSEMBLER#defineADCSFRIO(x)#endif#defineADCLSFRIO(x)#defineADCHSFRIO(x)AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*ADCControlandstatusregister*#defineADCSRSFRIO(x)#defineADCSRASFRIO(x)*newnameindatasheet(EAVR)**ADCMultiplexerselect*#defineADMUXSFRIO(x)*AnalogComparatorControlandStatusRegister*#defineACSRSFRIO(x)*USARTBaudRateRegisterLow*#defineUBRRLSFRIO(x)*USARTControlandStatusRegisterB*#defineUCSRBSFRIO(xA)*USARTControlandStatusRegisterA*#defineUCSRASFRIO(xB)*USARTIODataRegister*#defineUDRSFRIO(xC)*SPIControlRegister*#defineSPCRSFRIO(xD)*SPIStatusRegister*#defineSPSRSFRIO(xE)*SPIIODataRegister*#defineSPDRSFRIO(xF)*InputPins,PortD*#definePINDSFRIO(x)*DataDirectionRegister,PortD*#defineDDRDSFRIO(x)*DataRegister,PortD*#definePORTDSFRIO(x)*InputPins,PortC*#definePINCSFRIO(x)AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*DataDirectionRegister,PortC*#defineDDRCSFRIO(x)*DataRegister,PortC*#definePORTCSFRIO(x)*InputPins,PortB*#definePINBSFRIO(x)*DataDirectionRegister,PortB*#defineDDRBSFRIO(x)*DataRegister,PortB*#definePORTBSFRIO(x)*InputPins,PortA*#definePINASFRIO(x)*DataDirectionRegister,PortA*#defineDDRASFRIO(xA)*DataRegister,PortA*#definePORTASFRIO(xB)*EEPROMControlRegister*#defineEECRSFRIO(xC)*EEPROMDataRegister*#defineEEDRSFRIO(xD)*EEPROMAddressRegister*#defineEEARSFRIO(xE)#defineEEARLSFRIO(xE)#defineEEARHSFRIO(xF)*SpecialFunctionIORegister*#defineSFIORSFRIO(x)*WatchdogTimerControlRegister*#defineWDTCRSFRIO(x)*OnchipDebugRegister*#defineOCDRSFRIO(x)AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*TimerOutputCompareRegister*#defineOCRSFRIO(x)*TimerCounter*#defineTCNTSFRIO(x)*TimerCounterControlregister*#defineTCCRSFRIO(x)*TCInputCaptureRegister*#defineICRSFRIO(x)#defineICRLSFRIO(x)#defineICRHSFRIO(x)*TimerCounterOutputCompareRegisterB*#defineOCRBSFRIO(x)#defineOCRBLSFRIO(x)#defineOCRBHSFRIO(x)*TimerCounterOutputCompareRegisterA*#defineOCRASFRIO(xA)#defineOCRALSFRIO(xA)#defineOCRAHSFRIO(xB)*TimerCounter*#defineTCNTSFRIO(xC)#defineTCNTLSFRIO(xC)#defineTCNTHSFRIO(xD)*TimerCounterControlandStatusRegister*#defineTCCRBSFRIO(xE)*TimerCounterControlRegister*#defineTCCRASFRIO(xF)*TimerCounterAsynchronousControlStatusRegister*#defineASSRSFRIO(x)*OutputCompareRegister*#defineOCRSFRIO(x)*TimerCounter*#defineTCNTSFRIO(x)AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*TimerCounterControlRegister*#defineTCCRSFRIO(x)*MCUStatusRegister*#defineMCUSRSFRIO(x)#defineMCUCSRSFRIO(x)*newnameindatasheet(EAVR)**MCUgeneralControlRegister*#defineMCUCRSFRIO(x)*TimerCounterInterruptFlagRegister*#defineTIFRSFRIO(x)*TimerCounterInterruptMaSKregister*#defineTIMSKSFRIO(x)*ExternalInterruptFlagRegister*#defineEIFRSFRIO(x)*ExternalInterruptMaSKregister*#defineEIMSKSFRIO(x)*ExternalInterruptControlRegisterB*#defineEICRBSFRIO(xA)*RAMPageZselectregister*#defineRAMPZSFRIO(xB)*XDIVDividecontrolregister*#defineXDIVSFRIO(xC)*xDxESP**xFSREG**ExtendedIOregisters**DataDirectionRegister,PortF*#defineDDRFSFRMEM(x)*DataRegister,PortF*#definePORTFSFRMEM(x)*InputPins,PortG*AVRSTUDIO快速入门指南by伯兮科技infoliboxicn#definePINGSFRMEM(x)*DataDirectionRegister,PortG*#defineDDRGSFRMEM(x)*DataRegister,PortG*#definePORTGSFRMEM(x)*StoreProgramMemoryControlandStatusRegister*#defineSPMCRSFRMEM(x)#defineSPMCSRSFRMEM(x)*newnameindatasheet(EAVR)**ExternalInterruptControlRegisterA*#defineEICRASFRMEM(xA)*ExternalMemoryControlRegisterB*#defineXMCRBSFRMEM(xC)*ExternalMemoryControlRegisterA*#defineXMCRASFRMEM(xD)*OscillatorCalibrationRegister*#defineOSCCALSFRMEM(xF)*wireSerialInterfaceBitRateRegister*#defineTWBRSFRMEM(x)*wireSerialInterfaceStatusRegister*#defineTWSRSFRMEM(x)*wireSerialInterfaceAddressRegister*#defineTWARSFRMEM(x)*wireSerialInterfaceDataRegister*#defineTWDRSFRMEM(x)*wireSerialInterfaceControlRegister*#defineTWCRSFRMEM(x)*TimeCounterOutputCompareRegisterC*#defineOCRCSFRMEM(x)#defineOCRCLSFRMEM(x)#defineOCRCHSFRMEM(x)AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*TimerCounterControlRegisterC*#defineTCCRCSFRMEM(xA)*ExtendedTimerInterruptFlagRegister*#defineETIFRSFRMEM(xC)*ExtendedTimerInterruptMaskRegister*#defineETIMSKSFRMEM(xD)*TimerCounterInputCaptureRegister*#defineICRSFRMEM(x)#defineICRLSFRMEM(x)#defineICRHSFRMEM(x)*TimerCounterOutputCompareRegisterC*#defineOCRCSFRMEM(x)#defineOCRCLSFRMEM(x)#defineOCRCHSFRMEM(x)*TimerCounterOutputCompareRegisterB*#defineOCRBSFRMEM(x)#defineOCRBLSFRMEM(x)#defineOCRBHSFRMEM(x)*TimerCounterOutputCompareRegisterA*#defineOCRASFRMEM(x)#defineOCRALSFRMEM(x)#defineOCRAHSFRMEM(x)*TimerCounterCounterRegister*#defineTCNTSFRMEM(x)#defineTCNTLSFRMEM(x)#defineTCNTHSFRMEM(x)*TimerCounterControlRegisterB*#defineTCCRBSFRMEM(xA)*TimerCounterControlRegisterA*#defineTCCRASFRMEM(xB)*TimerCounterControlRegisterC*#defineTCCRCSFRMEM(xC)*USARTBaudRateRegisterHigh*AVRSTUDIO快速入门指南by伯兮科技infoliboxicn#defineUBRRHSFRMEM(x)*USARTControlandStatusRegisterC*#defineUCSRCSFRMEM(x)*USARTBaudRateRegisterHigh*#defineUBRRHSFRMEM(x)*USARTBaudRateRegisterLow*#defineUBRRLSFRMEM(x)*USARTControlandStatusRegisterB*#defineUCSRBSFRMEM(xA)*USARTControlandStatusRegisterA*#defineUCSRASFRMEM(xB)*USARTIODataRegister*#defineUDRSFRMEM(xC)*USARTControlandStatusRegisterC*#defineUCSRCSFRMEM(xD)*Interruptvectors**ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()AVRSTUDIO快速入门指南by伯兮科技infoliboxicn*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()*ExternalInterruptRequest*#defineINTvectVECTOR()#defineSIGINTERRUPTVECTOR()

用户评论(0)

0/200

精彩专题

上传我的资料

每篇奖励 +2积分

资料评价:

/45
1下载券 下载 加入VIP, 送下载券

意见
反馈

立即扫码关注

爱问共享资料微信公众号

返回
顶部