This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem about function calling in ISR

I call some sub-routine in ISR. And I mark the ISR as "using 1". But I find out this will lead to the error of parameters passing from ISR to the sub-routine. How come?

Parents
  • The problem is probably that the called function is assuming it will be called with the selected register bank set to something other than one.

    By default, the compiler will generate object code that accesses registers by using direct addressing. This is helpful in generating efficient code. For example, using direct addressing, it is possible to push the value of a register onto the stack using a single instruction:

        PUSH  AR0
    
    To generate these direct instructions, the compiler needs to know which of the four register banks will be selected when a function is called. Normally, this will be register bank zero; but, in the case of a function called from your ISR, it will be one. You can tell the compiler which register bank is to be used by means of the REGISTERBANK compiler directive.

    See: http://www.keil.com/support/man/docs/c51/c51_registerbank.asp

Reply
  • The problem is probably that the called function is assuming it will be called with the selected register bank set to something other than one.

    By default, the compiler will generate object code that accesses registers by using direct addressing. This is helpful in generating efficient code. For example, using direct addressing, it is possible to push the value of a register onto the stack using a single instruction:

        PUSH  AR0
    
    To generate these direct instructions, the compiler needs to know which of the four register banks will be selected when a function is called. Normally, this will be register bank zero; but, in the case of a function called from your ISR, it will be one. You can tell the compiler which register bank is to be used by means of the REGISTERBANK compiler directive.

    See: http://www.keil.com/support/man/docs/c51/c51_registerbank.asp

Children