PIC单片机入门培训资料

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming1701PICPICmicro®MCU–介绍PIC16系列产品的汇编编程HANDS-ON©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming2讲述90分钟休息20分钟2个实验60分钟休息60分钟104个实验2小时休息20分钟日程讲述部分实验部分1实验部分2©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming3架构存储器指令集开发软件(MPLAB®IDE)讲述部分的内容©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming4Labs在MPLABIDE创建项目调试和跳转控制PWMA/D中断演示(时间允许的话)PIC16F877A实现多任务实验和演示部分的内容©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming5架构©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming6MicrochipPIC®MCU金字塔PIC16C5XPIC12C5XXPIC16PIC12FPIC18dsPIC14bits16bits24bits12bits8bitMCU16bitMCU程序存储器宽度数据存储器宽度©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming7PICmicroArchitectureRISC-likeFeatures内部为哈佛结构寄存器文档大多数单指令周期指令流水线操作长字型指令指令数很少指令实现的功能基本不重复PIC单片机之所以有很高的性能是因为其具备如下特性:©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming8PIC单片机架构哈佛结构从同一存储器空间取指令和取操作数据.限制了数据流量程序和数据存储器冯-纽曼结构8-位程序存储器数据存储器8-位12/14/16-位哈佛结构从两个独立的存储空间分别取指令和存取操作数.数据流量增加针对程序区和数据区可以设计不同的数据线宽度©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming9FlushFetch4FetchSUB_1大部分单片机,其取指和执行过程是顺序进行的.指令流水线的引入允许取指和执行可以同步进行.使得指令可以在一个指令周期内执行.程序分支例外(如GOTO,CALL或直接修改PC),这需两个指令周期.Tcy0Tcy1Tcy2Tcy3Tcy4PIC单片机架构指令流水线Execute1Fetch31.MOVLW55hFetch1Execute3Fetch2Execute2Fetch42.MOVWFPORTB3.CALLSUB_14.BSFPORTA,BIT3©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming10PIC单片机架构寄存器文档概念GeneralPurposeRegisters(RAM)OtherSFRsPORTAFSRSTATUSPCLTMR0INDFWRegisterALU数据存储器直接数据地址7操作码714-位字长的指令范例:RAM被看作是一组通用的寄存器.周边模块(I/O)也作为寄存器.所有的指令操作都可针对所有的寄存器.长字指令使得在指令中直接寻址寄存器.©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming11PICmicro架构指令实例PICMCU指令编码为操作码和参数编码用一个字完成OPCODEk立即数类指令kkkkkkk©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming12PICMCU晶振PICMCU4MHz(250ns)1MHz(1us)foscTcy指令率是输入时钟的1/4输入晶振频率叫做fosc一个指令周期占用1Tcy©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming13存储器©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming14PICmicro架构存储器两种类型程序(RAM和EEPROM)组成Pages-页(程序存储器)Banks–组(数据存储器)©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming15PICmicro架构存储器表FLASH程序存储器RAM数据存储器大小(words)GPR大小(bytes)1K64PIC12F675PIC16F877A8K368PICmicroMCU©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming16分页的程序存储器(14bit核)OPCODEkkkkkkkkkkkCALLorGOTOinstruction3bitsforinstruction11bitsfordestination在14-bit核的器件中:11位访问211或2048(2k)空间访问更多的空间,需要更多的位程序存储器的分页提供这些位©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming1714-bit核架构程序存储器程序存储器最大8K字四页,每页2k使用PCLATH4:3访问页复位地址0000h中断地址0004hPage00000h0004h07FFhInterruptResetPage10800h0FFFhPage21000h17FFhPage31800h1FFFhPCLATH4:3=00PCLATH4:3=01PCLATH4:3=10PCLATH4:3=11©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming18PICmicro架构程序存储器:PC绝对寻址OPCODEkkkk14-bitInstructionforcallandgotokkkkkkk用CALL和GOTO指令修改PCkkkkkkkkkxxxkkxxxPCLATHRegister有效的13-bit程序存储器地址11-bitsFromInstruction2-bitsFromPCLATHkkkk©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming19PICmicro架构分页的程序存储器当执行CALLorGOTO指令时,需考虑分页当跳转到不同的页时,修改页位调用页位:–GOTO地址–CALL地址–InstructionPCL,F;e.g.ADDWFPCL,F返回时不需考虑页©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming20PICmicro架构PC相对寻址(14-bitcore)PCH5PCL813-BitProgramCounterPCLATH5InternalDataBus8558高字节写入PCLATH.然后低字节写入PCL,将装入13-bit值到PC.movlwHIGHDelaymovwfPCLATHmovlwLOWDelaymovwfPCLNote:PCHcannotberead©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming21分组的数据存储器(14bitcore)DataModifyingInstruction7位指令编码7位目标地址在14-bit核的器件中:7位访问27或128空间访问更多的空间,需要更多的位程序存储器的分组提供这些位OPCODEfffffff©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming22PICmicro架构数据存储器:直接寻址低7位的数据地址直接在指令中描述高2位在STATUS寄存器中(又称寄存器组号BANK)指向目标寄存器的9位有效地址IRPRP1RP0OPCODETOPDZDCCSTATUS寄存器14位长指令fffffffRP1RP0fffffff7位来自指令2位来自STATUS寄存器©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming23PICmicro架构数据存储器组成分成4个组SFR映射到最顶端32位置通过RP0,1和IRP选择组GPRsSFRsBank0000h01Fh020h07FhGPRsSFRsBank1080h09Fh0A0h0FFh0F0hGPRsSFRsBank2100h11Fh120h17Fh170hGPRsSFRsBank3180h19Fh1A0h1FFh1F0hRP1:0RP1:0RP1:0RP1:0=00=01=10=11©MicrochipTechnologyIncorporated.AllRightsReserved.701PICPIC®MCU-IntroductiontoProgramming24FileAddress(hex)Bank0Unimplementeddatamemorylocation;readas'0'.寄存器图PIC12F675PICmicro架构数据存储器PCLATHPCLATHINTCONINTCONFSRFSRG

1 / 201
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功