• MC9S08中断机制


    When an interrupt is requested, the CPU completes the current instruction before responding to the
    interrupt. At this point, the program counter is pointing at the start of the next instruction, which is where
    the CPU should return after servicing the interrupt. The CPU responds to an interrupt by performing the
    same sequence of operations as for a software interrupt (SWI) instruction, except the address used for the
    vector fetch is determined by the highest priority interrupt that is pending when the interrupt sequence
    started.
    The CPU sequence for an interrupt is:
    1. Store the contents of PCL, PCH, X, A, and CCR on the stack, in that order.
    2. Set the I bit in the CCR.
    3. Fetch the high-order half of the interrupt vector.
    4. Fetch the low-order half of the interrupt vector.
    5. Delay for one free bus cycle.
    6. Fetch three bytes of program information starting at the address indicated by the interrupt vector
    to fill the instruction queue in preparation for execution of the first instruction in the interrupt
    service routine.
    After the CCR contents are pushed onto the stack, the I bit in the CCR is set to prevent other interrupts
    while in the interrupt service routine. Although it is possible to clear the I bit with an instruction in the
    Chapter 7 Central Processor Unit (S08CPUV3)
    MC9S08DV60 Series Data Sheet, Rev 2
    118 Freescale Semiconductor
    interrupt service routine, this would allow nesting of interrupts (which is not recommended because it
    leads to programs that are difficult to debug and maintain).
    For compatibility with the earlier M68HC05 MCUs, the high-order half of the H:X index register pair (H)
    is not saved on the stack as part of the interrupt sequence. The user must use a PSHH instruction at the
    beginning of the service routine to save H and then use a PULH instruction just before the RTI that ends
    the interrupt service routine. It is not necessary to save H if you are certain that the interrupt service routine
    does not use any instructions or auto-increment addressing modes that might change the value of H.
    The software interrupt (SWI) instruction is like a hardware interrupt except that it is not masked by the
    global I bit in the CCR and it is associated with an instruction opcode within the program so it is not
    asynchronous to program execution.

    1.注意压栈的顺序: PCL, PCH, X, A, and CCR;

    2.为了兼容05系列,没有将索引寄存器的H压栈,如果不确定中断代码是否修改了H的值,应该将H压栈; 

    2.SWI不CCR的I位影响,即不受SEI、CLI指令影响;

    代码结构如下:

    0001  PSHH   ;新版本软件编译器,如CodeWarrior 6.0的编译器自动加上这句

    0002  中断代码

    0003  。。。

    000X     PULH

    000X     RTI

    执行RTI,MCU自动完成以下工作:

    SP ← (SP) + $0001; Pull (CCR)
    SP ← (SP) + $0001; Pull (A)
    SP ← (SP) + $0001; Pull (X)
    SP ← (SP) + $0001; Pull (PCH)
    SP ← (SP) + $0001; Pull (PCL)

  • 相关阅读:
    sql统计
    如何让文本框内的提示信息在激活文本框时清空
    Button onclick事件
    CustomValidator 的应用
    DjangoORM数据库创建
    HDU3685 几何+重心+凸包+判定锐角三角形
    CF181c
    POJ2187 旋转卡壳+凸包
    HDU2907凸包+凹面
    HDU2108+几何+判断凸多边形
  • 原文地址:https://www.cnblogs.com/yuxi/p/1867015.html
Copyright © 2020-2023  润新知