how to write an ISR for 8052 microcontroller in C language

Sep 23, 2004 2 Replies

hi all, I have seen a sample code in which the ISR looks like this


=========================================================== static isr_serial (void) interrupt 4 using 1 ===========================================================


I have seen first time the keyword "interrupt" would some body please tell me why we are using this keyword and what is the meaning of 4 ? and using 1 ?


please guide me in detail waiting for your reply Gul...


the standard 8051 has 5 interrupts (2 timers, 2 external, 1 uart)

"interrupt 4" means the compiler will link this function from the 4th entry in the interrupt vector, that is, which interrupt this will service. (the name means nothing.)

"using 1" means that this function will use register bank 1. this is not strictly necessary since the compiler can generate code to save registers. however, doing so is slower.

-eck.

Amara wrote:

Hi Amara I think the example coms fra code for the SDCC compiler. You can find a usermanual at:

formatting link
interrupt 4 means that the source of the interrupt is number 4. This is the seriel port of a 8052 device. The number tells the compiler where to put the rutine, so that the interrupt can call it.

using 1 means the register bank 1 will be used for this interrupt. If you have an interrupt that must execure wery fast, the "using" telles the compiler to generate code that activates register bank 1 during this interrupt. The benefit from this it that the MCU does not have to store all its valures (push the registers) before executing the interrupt.

Hope you will find this helpfull. Regards Toke K.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required