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

can i RET in the interrupt insted of RETI

Hi! i use p89v51rd2fa microcontroller and microversion 3 C51 compiler. if i write an interrupt function in c the compiler create a asm code like

push ACC
push PSW

a=b;

pop PSW
pop ACC
RETI


can i change the RETI to RET.
regrads,
venkatesh.

  • but your program will never work.

    it is very well documented in "the bible"

    why do you ask?

    Erik

  • I echo the question, why do you need to change this?
    Reasoning:
    You are using a compiler for a reason. To keep you from messing with low level code as much as possible (and possibly messing up your project in a bad way), the compiler handles interrupts just fine for, why do you need to mess with code that works? Also I believe the compiler should generate the push and pop code for you, if you use that in C it will be redundant code. You shouldn't need any assembly to make a complete ISR using the interrupt function keyword.
    http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm

    The RETI and RET are similar instructions but if you have an interrupt you must use RETI or as priorly stated your program will cease to work properly.

    Perhaps some reading of the documentation first? There is no advantage to changing it to RETI save the disadvantage you will break your program (in horrible ways likely).

    Stephen

  • Hi! I believe the compiler should generate the push and pop code for you, if you use that in C it will be redundant code. You shouldn't need any assembly to make a complete ISR using the interrupt function keyword

    i don't use push and pop in the c program.the above code that i was posted is only asm wondow of keil.

    Actually my need is one main interrupt and one sub interrupt.the main interrupt was placed in actuall interrupt vector address [interrupt 0 in 0x000B] and the sub interrupt in 0x400B.the main interrupt was used in my own IAP bootloader code the sub interrupt is used in application code.i need to access the sub interrupt when the application code was executing.due to that i write a LCALL to the sub interrupt in the main interrupt. the code is working fine with RET command [i chane the RETI(0x32) to RET(0x22) in hex file]in sub interrupt and its not working with RETI command.

    thank you!
    regards,
    venkatesh.

  • Why declare a function as an interrupt handler and then patch the compiler output if you are not going to use the function as an ISR?

    Telling the compiler that it is an ISR specifically requests that the compiler should use special prologe/epiloge code.

  • Why declare a function as an interrupt handler and then patch the compiler output if you are not going to use the function as an ISR?

    Acctually both interrupts has different tasks.the main interrupt was doing serial transmission in bootloader mode and the sub interrupt also have serial trasmission in application code.the message protocol was totally change in the both communication.

    regards,
    venkatesh.

  • Actually my need is one main interrupt and one sub interrupt.the main interrupt was placed in actuall interrupt vector address [interrupt 0 in 0x000B] and the sub interrupt in 0x400B.the main interrupt was used in my own IAP bootloader code the sub interrupt is used in application code.i need to access the sub interrupt when the application code was executing.due to that i write a LCALL to the sub interrupt in the main interrupt

    this works if you use #pragma noiv
    CSEG at 0x0b
    jb flag, appT0x ; in app mode
    ljmp bootT0
    appT0x: ljmp appT0

    my guess is that your problem is that the highlighted above should be ljmp

    Erik

  • my guess is that your problem is that the highlighted above should be ljmp
    i check it with ljmp also it's working with only change of RETI to RET.

    In my application the bootloader was never modified in site.the application code only downloaded to it by IAP method.So the application code design by change the setting in options for target/c51/interrupt at address=0x4000.by the above change the interrupt vectors in apllication must be placed like interrupt 0 in 0x400b interrupt 4 in 0x4023 this will never change.so lcall or ljmp from bootloder is pointing the above fixed address.if i use the #pragma noiv the interrupt vector address address at 0x400b or 0x4023 are disabled.what is change in RETI compare to RET.
    regards,
    venkatesh.

  • this works if you use #pragma noiv
    CSEG at 0x0b
    jb flag, appT0x ; in app mode
    ljmp bootT0
    appT0x: ljmp 0400bh

  • Sorry! i m not under stand,i thing u said that to write
    the ljmp manually in the address 0x0b am i right?then one more thing i use c language not asm.

    regards,
    venkatesh.

  • thing u said that to write
    I can not comment on what micro (u) said to write, if you mean me, type 'you'

    Erik

  • Sorry sir! now i understand.thank you for your valuable reply.thank you once again...:-)
    regards,
    venkatesh.

  • why bother with some very convoluted C code (C was never intended for absolute addresses) when some extremely simple assembly code will do?

    Erik

  • why bother with some very convoluted C code (C was never intended for absolute addresses) when some extremely simple assembly code will do?

    Yes! you are correct but i am not familiar with asm coading also most part of the program was also done by c language.Since i have one more asm file [iap.a51] for the IAP calls so i can use asm coading in this file.

    regards,
    venkatesh.

  • when you use RET instead RETI the code will still be
    executet at interruptlevel. So at some point there has
    to be a RETI. see my solution:
    http://www.keil.com/forum/docs/thread129.asp

    but before use that you should first fully understand
    it. I use this code to change interrupt functions at
    runtime. works perfect here

    Thomas

  • Hi! it works with RETI also when i make the changes denoted by Erik.Thanks Erik and Thanks Thomas.here is the code.

                     CSEG at 0x0B
                    JB    FLAG,?appT0x ; in app mode
                    ljmp  02456H
    ?appT0x:
                    ljmp  0400BH
                    RET
    
                    CSEG at 0x23
                    JB    FLAG,?appT4x ; in app mode
                    ljmp  2468H
    ?appT4x:
                    ljmp  04023h
                    RET
    


    there is no change in interrupt [RETI].
    regards,
    venkatesh.