单片机原理及应用(双语版·新形态版) 课件 第5章MCS51的中断处理_第1页
单片机原理及应用(双语版·新形态版) 课件 第5章MCS51的中断处理_第2页
单片机原理及应用(双语版·新形态版) 课件 第5章MCS51的中断处理_第3页
单片机原理及应用(双语版·新形态版) 课件 第5章MCS51的中断处理_第4页
单片机原理及应用(双语版·新形态版) 课件 第5章MCS51的中断处理_第5页
已阅读5页,还剩88页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

IntroductoryMicrocontrollerTheoryandApplicationsChapter5InterruptHandlingontheMCS-51ThisistheManagingDirector…Urgentprobleminsalesdepartment….Emailarrived!!中断Ring,ring,ring….Excuseme!CanIhaveawordwithyou?Interrupts1432765MainprograminstructionsInterrupt中断Mainprograminstructions1432765MainProgramstopsrunningProgramCounterissavedontheStacubprogramInterruptServiceRoutine(ISR)中断服务程序JumpstoanISRincodememorubprogramInterruptServiceRoutine(ISR)RETIPOPstheReturnAddressfromtheStack12765431432MainprograminstructionsWhat’sthedifferencebetweenaSubroutine子程序andanInterrupt中断?ASubroutineiscalledbyaprogramMOV A,#56hACALL DELAY…………….AnInterruptiscausedbyavoltagechangeintotheCPUInterruptSourcesINT0INT1RESETSerialPortTimersExternalInterruptsTXDRXDInterruptSourcesCPUINT0INT1Timer0Timer1SerialPortINT0RESETChangeofvoltageOverflow溢出ofTimerData数据readyInterruptSourceFlagsCPUINT0INT1Timer0Timer1SerialPortINT0RESETIE0IE1TI/RITF0TF1InterruptControlCircuitEA--ESET1EX1ET0EX0InterruptEnablingandDisabling允许和屏蔽usingIERegisterEnableAllSerialT1T0INT0INT10--10010EnableAllSerialT1T0INT0INT1Whichinterruptsarenowenabled?NONEInterruptEnablingandDisabling允许和屏蔽usingIERegister1--00000EnableAllSerialT1T0INT0INT1Whichinterruptsarenowenabled?NONEInterruptEnablingandDisabling允许和屏蔽usingIERegister1--01010EnableAllIfEA=0 thenallaredisabledIfEA=1 theninterruptscan beenabledInterruptEnablingandDisabling允许和屏蔽usingIERegisterWhathappensiftwointerruptsarriveatthesametime?ExternalInterrupt0HighestpriorityTimer0ExternalInterrupt1Timer1SerialPortLowestpriority5.5.1PriorityRankingOrder优先权等级次序1432765MainprograminstructionsINT0TIMER1HigherpriorityLowerpriority1321432765RETIISRforINT01321432765ISRforINT0RETIISRforTIMER1RETI1321321432765ISRforINT0RETIISRforTIMER1RETI1321321432765ISRforINT0ISRforTIMER11325423MainprograminstructionsWhathappensifoneinterruptisinterruptedbyanother?1321432765RETILowerpriorityHigherpriorityISR1Interrupt21321432765ISR1RETIISR2RETI1321321432765ISR1ISR21325423Mainprograminstructions1321432765LowerpriorityHigherpriorityISR1Interrupt2IfInterrupt2hasthehigherpriority…..4RETI1432765ISR112ISR21234RETIMainprograminstructions1432765ISR11234ISR1ISR21234RETIRETIMainprograminstructions1432765ISR1123445ISR1ISR21234RETIRETIMainprograminstructionsPleasetrythefollowing..Question5.10.2Question5.10.3Question5.10.4Question5.10.5Page99Question5.10.2INT0&Timer1togetherPriorities:INT0>Timer1RunINT0ISRthenTimer1ISR+++++++++++++++++++++++++++++++++Question5.10.3

DuringSerialPortISRreceivesTimer0interrupt.Whataction?Priorities:Timer0>SerialPortTimer0willinterruptSerialISR,runTimer0ISR,thencompleteSerialISRQuestion5.10.4IE=08h.INT0andTimer1togetherIfIE=08hthenEA=0Allinterruptsdisabled+++++++++++++++++++++++++++++++++Question5.10.5

DuringTimer1ISRreceivesSerialinterrupt.Whataction?Priorities:Timer1>SerialPortTimer1ISRwillfinish,then,runSerialISR---PSPT1PX1PT0PX0InterruptPriority-IPSerialT1T0INT0INT1SETBPSSETBPT05.5.4ChangingtheInterruptPrioritiesMOVIP,#00010010bMOVIP,#12hTimer0HighprioritySerialPortHighpriorityExternalInterrupt0LowpriorityExternalInterrupt1LowpriorityTimer1LowpriorityPriorityRankingOrder优先权等级次序InterruptControlCircuitPleasetrythefollowing..Question5.10.6Question5.10.7Page100PleasechangetoIE=82hQuestion5.10.6IP=04hIE=9FhWhileINT0ISRisrunning,INT1receivedIE=10011111bAllinterruptsenabledIP=00000100bINT1hashighpriorityINT0ISRisinterrupted,INT1ISRruns,thenINT0willcomplete.+++++++++++++++++++++++++++++++++Question5.10.7IP=10hIE=82hTimer0ISRreceivesSerialinterrupt.IE=10000010bOnlyTimer0enabledSerialinterruptdoesnotrunubprogramInterruptServiceRoutine(ISR)JumpstoanISRincodememoryWhereistheISR?5.6MemorylocationsCodeMemory000000130023001B0003000BResetExternalInterrupt0Timer0ExternalInterrupt1Timer1SerialportInterrupthandlerInterruptServiceRoutine(ISR)中断服务程序INTERRUPTFACILITIESTYPEFLAGISRADDRESSReset-0000hExternalInt0IE00003hTimer0TF0000BhExternalInt1IE10013hTimer1TF1001BhSerialPortTI/RI0023hResetExternalInterrupt0Timer0ExternalInterrupt1Timer1SerialportJumpovertheISRstoMainUnusedmemory0050hMain000000130023001B0003000BSJMP0050h

ORG 0000h SJMP 0050h ;JumpoverISRs

ORG 0003h AJMP EXTINT0 ;ISRforExtInt0

ORG 000Bh AJMP TIMER0 ;ISRforTimer0

ORG 0013h AJMP EXTINT1 ;ISRforExtInt1

ORG 001Bh AJMP TIMER1 ;ISRforTimer1

ORG 0023h AJMP SERIAL ;ISRforSerialPort

ORG 0050h ;StartofMainprogramMAIN: UnusedmemoryMainMainORG0050hLabelSJMPMAINSJMP0050h

ORG 0000h SJMP MAIN ;JumpoverISRs

ORG 0003h AJMP EXTINT0 ;ISRforExtInt0

ORG 000Bh AJMP TIMER0 ;ISRforTimer0

ORG 0013h AJMP EXTINT1 ;ISRforExtInt1

ORG 001Bh AJMP TIMER1 ;ISRforTimer1

ORG 0023h AJMP SERIAL ;ISRforSerialPortMAIN: ;StartofMainprogram

ORG 0000h SJMP MAIN ;JumpoverISR

ORG 0003h AJMP EXTINT0 ;ISRforExtInt0MAIN ;StartofMainprogram

SJMP $EXTINT0:

RETIWhenonlyoneinterruptisenabled…ExternalInterruptsINT0andINT1Typeofinterrupt….ExternalInterruptsINT0andINT1Interruptcausedby…. EITHERalowlevel电平触发ORahigh-to-lowtransition(edgetriggering) 边沿触发Vint05IT0=1IT0=0(InterruptType)timeTF1TR1TF0TR0IE1IT1IE0IT0TimerControlTCONInterruptTypeInterruptEdgeflagSetwhenInterruptlinegoeslowIT0=0IT1=0Interruptswhenlow-levelIE0/IE1willbesetIE0/IE1mustbeclearedbytheprogram

CLRIE0

IT0=1IT1=1Interruptswhenhigh-to-lowedgetransitionIE0/IE1willbesetIE0/IE1willbeclearedwhenISRstartsExternalInterruptsINT0andINT1015.9.1Example:ControloftrafficlightsRunamainprogramwhichisinterruptedwhenacarblocksasensor.Lightsshouldthenchangetoallowthevehicletoproceed.5.9.1Example:ControloftrafficlightsSensor0Red0Green1Sensor101INT0Direction0Direction1+5VP.1.0P.1.1INT0Sensor0Sensor10015.9.1PhotocellStartEnableinterruptEdgetriggeringDirectionflag=0MainProgramactivity5.9.1DIRN BIT 20.0h;FlagforGreendirection ORG 0000h SJMPSTART ORG 0003h AJMPISRINT0 ;ISRforINT0START: SETBEA SETBEX0 ;EnableinterruptINT0 SETBIT0 ;Setforedgetriggering CLR DIRN

;Setdirectiontobe0MAIN: NOP NOP ;Mainprogram SJMPMAIN01Sensor1Sensor0Light0Light15.9.1+5VP.1.0P.1.1INT0Sensor0Sensor1LightNoLightHighRLowR1005.9.1Sensor0high?Direction=0?Direction=1?ChangetoDirection0ChangetoDirection1ReturnDirectionflag=1ISRReturnYYNNYNROAD0:ROAD1:Directionflag=05.9.1Sensor0high?Direction=0?Direction=1?ChangetoDirection0ChangetoDirection1ReturnDirectionflag=1ISRReturnYYNNYNROAD0:ROAD1:Directionflag=05.9.101Sensor1Sensor0Light0Light15.9.1Sensor0high?Direction=0?Direction=1?ChangetoDirection0ChangetoDirection1ReturnDirectionflag=1ISRReturnYYNNYNROAD0:ROAD1:Directionflag=05.9.101Sensor1Sensor0Light0Light15.9.1Sensor0high?Direction=0?Direction=1?ChangetoDirection0ChangetoDirection1ReturnDirectionflag=1ISRReturnYYNNYNROAD0:ROAD1:Directionflag=05.9.1ISRINT0: ;InterruptServiceRoutine CLR EA ;Disableinterrupts JNB SENSOR0,ROAD1ROAD0: JNB DIRN,RETURN;IsDirection=0? ACALLCHANGE_TO_0;Changelights CLR DIRN

;Direction=0? SJMPRETURNROAD1: JB DIRN,RETURN;IsDirection=1? ACALLCHANGE_TO_1;Changelights SETBDIRN ;Direction=1RETURN: SETBEA ;Enableinterruptsagain RETISUBROUTINEChangeto0Red0&Yellow1ONRed0andRed1ONGreen0andRed1ONReturnSUBROUTINEChangeto1Red1&Yellow0ONRed1andRed0ONGreen1andRed0ONReturn5.9.1CHANGE_TO_0:;Tochangedirectionoflightsto0

ACALL LIGHTS_OFF CLR RED0 ;ONRed0 CLR YELLOW1 ;ONYellow1

ACALL DELAY ACALL LIGHTS_OFF CLR RED0 ;ONRed0 CLR RED1 ;ONRed1

ACALL DELAY ACALL LIGHTS_OFF CLR GREEN0 ;ONGreen0 CLR RED1 ;ONRed1

ACALL DELAY RETCHANGE_TO_1:;Tochangedirectionoflightsto1

ACALL LIGHTS_OFF CLR RED1 ;ONRed1 CLR YELLOW0 ;ONYellow0

ACALL DELAY ACALL LIGHTS_OFF CLR RED1 ;ONRed1 CLR RED0 ;ONRed0

ACALL DELAY ACALL LIGHTS_OFF CLR GREEN1 ;ONGreen1 CLR RED0 ;ONRed0

ACALL DELAY RETLIGHTS_OFF: ;Toturnoffallthelights SETB RED0 SETB YELLOW0 SETB GREEN0 SETB RED1 SETB YELLOW1 SETB GREEN1 RET5.9.1Pleasetrythefollowing..Question5.10.11Page100Question5.10.11PushbuttontotoggleLED

LED_____ P1.0;LEDonP1.0 FLAG_____ 20h.4;Lightonflag ORG 0000h AJMP MAIN ORG ______ ;ISRforINT0 AJMP ISR_INT0MAIN: SETB EA SETB ____ ;Edgetrigger SETB EX0 ;EnableINT0 SETB FLAG ;Lighton SJMP $Question5.10.11PushbuttontotoggleLEDBITBIT0003hIT0ISR_INT0: ____ FLAG ;Complement MOV C,FLAG ____ LIGHT ;IfFlag=0,then ;turnLEDon ____ LED ;IfFlag=1,then ;turnLEDoff AJMP EXITLIGHT: CLR LED ;TurnonLEDEXIT: ____ ;ReturnQuestion5.10.11PushbuttontotoggleLEDCPLJNCSETBRET5.7Multiple-sourceinterruptsHowcanwereceivemanyexternalinterrupts?WeonlyhaveINT0andINT1Highforinterrupt00000Highforinterrupt101000Highforinterrupt01 ORG 0000h AJMP MAIN ORG 0003h ;ISRforINT0 AJMP ISR_INT0MAIN: ;Mainprogram

SJMP $5.7Multiple-sourceinterruptsISR_INT0: JB P1.1,ISR1 ;Polllines JB P1.2,ISR2 JB P1.3,ISR3 JB P1.4,ISR4 JB P1.5,ISR5ISR1: ;Interrupt1

RETIISR2: ;Interrupt2

RETIISR3: ;Interrupt3

RETI5.9.2RemotesensorwithswitchinterruptIfinterruptthenaveragelast10itemsonstack8051P0.7P0.0P1.0A-DThermometer11hF6h49hC6h2FhStackINT0P3.2+508051P0.7P0.0P1.0A-DThermo-meter11hF6h49hC6h2FhStackINT0P3.2+5025oC19h100000111119h

ORG0000h

MAIN:

SETBP1.0 NEXT:JNBP1.0,$;Wait JB P1.0,$ ;Wait PUSHP0 SJMPNEXT8051P0.7P0.0P1.0A-DThermo-meter11hF6h49hC6h2FhStackINT0P3.2+5025oC19h119h0Calculateaverageoftopten

TEMPEQU30h ORG0000h SJMPMAIN ORG0003h AJMPISR_INT0MAIN:SETBIT0 SETBEA SETBEX0 SETBP1.0 NEXT:JNBP1.0,$;Wait JB P1.0,$ ;Wait PUSHP0 SJMPNEXTISR_INT0: RETI?

TEMPEQU30h ORG0000h SJMPMAIN ORG0003h AJMPISR_INT0MAIN:SETBIT0 SETBEA SETBEX0 SETBP1.0 NEXT:JNBP1.0,$;Wait JB P1.0,$ ;Wait PUSHP0 SJMPNEXTISR_INT0: MOVR0,#0Ah POPAX: POPTEMP ADDA,T

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论