I have noticed that the Kiel compiler doesn't produce the correct interrupt vector if 8051 interrupt numbers are used. For example for external interrupt 0 (IE0), the interrupt number has to be 0, instead of 1 to produce a jump at location 1. Example:
void edge1 (void) interrupt 0{ /*produces correct code
while
void edge1 (void) interrupt 1{ /*produces wrong code
This is the case with all the interrupts I have used. My questions is what do you have to do to produce a reset vector? Reset is interrupt number 0 in 8051 numbering. Using -1 or 255 both produce a compile error.
Is it?
Where did you see that defined?
The so-called "bible" for the 8051 never considers reset as an interrupt.
Neither does it use any concept of interrupt "numbers" - it speaks only of the vector addresses.
The C51 interrupt numbers are a Keil invention as part of their interrupt keyword extension in C51 - you cannot put any other meaning on them other than defined in the Keil C51 manual!
.
However, this is a regular FAQ due to the following quote from the document you refer to:
Source Priority Within Level 1. IE0 (highest) 2. TF0 3. IE1 4. TF1 5. RI+TI (lowest)
Yet another post from you with useful content, I see.
"this is a regular FAQ due to the following quote from the document you refer to"
I don't see how that has anything to do with interrupt numbers - and it certainly doesn't suggest that reset is "interrupt 0".
please expand...
Oh dear. You said:
I said:
You have now responded with:
The point is this:
The 8051 documentation does assign numbers to the interrupts. These numbers reflect each interrupts priority level.
Keil assign numbers to the interrupt vectors which happen to be the priority level (as enumerated in the above table) minus one. This causes regular confusion as the two concepts are, probably fairly reasonably, confused. It would probably have been a better choice if Keil had used the numbering from the above table.
The idea of the reset vector being somehow 'interrupt 0' is not inferred or suggested by any of the above.
Clear?
The 8051 documentation does assign numbers to the interrupts. These numbers reflect each interrupts priority level. VERY incomplete statement and many have been led astray by this.
Correctly the statement should be: These numbers reflect each interrupts priority level for interrupts occurring in the same processor cycle
Another caveat is that some modern derivatives have 'gaps' in the interrupt vectors (usually an interrupt that another family member has) and do not have gaps in the 'interrupt numbers'
Thus the only safe way to get an 'interrupt number' is by the formula ((interrupt_vector_address/8 ) -3)
Erik
"The point is this: The 8051 documentation does assign numbers to the interrupts."
That's not my reading of that list.
My reading is that it's simply an ordered list where 1 is the highest priority, and 5 the lowest - I don't see that as "numbering the interrupts". Especially as the table you quoted is immediately followed by this note:
"Note that the 'priority within level' structure is only used to resolve simultaneous requests of the same priority level."
So the numbers are not intended to be any kind of general interrupt identifier - just an indication of priority within the context of that particular discussion.
"This causes regular confusion as the two concepts are, probably fairly reasonably, confused"
You may well be right there!
"Clear?"
I think I get what you're saying now.
"Keil assign numbers to the interrupt vectors which happen to be the priority level (as enumerated in the above table) minus one."
Pure coincidence?
More directly, Keil assign numbers to the interrupt vectors which happen to be the same as the enable bit positions in the IE register.
Probably the true rationale between the so-called "interrupt numbers" in Keil's C51 is that they are the position (index) of the vector within the vector table.
Hence the formula quoted by Erik.
That should be:
"the only safe way to get Keil's so-called 'interrupt number' for C51 is by the formula ((interrupt_vector_address/8 ) -3)"
and, in fact, it's not completely safe - as it doesn't state the upper-bound on Keil's so-called C51 "interrupt numbers".
Therefore, the only really safe way to get Keil's so-called 'interrupt number' for C51 is to Please read the manual: http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm
Interrupt priority and the interrupt number are two different things. Interrupt priority can be changed by programming registers but the interrupt number is fixed. In all the chip manufacturers' documentation (TI, Atmel, Philips, etc) for 8051 variants RESET is listed as interrupt 0, with vector address 0. It would be useful to be able to program this vector with the interrupt statement in cases where the C startup code was not used. The Kiel manual section on interrupts is incomplete and misleading. It shows an interrupt as a stand-alone program, without the startup code or anything else. Normally the interrupt vector location would have a long jump (requiring all 3 bytes) to the body of the interrupt routine. That is what the compiler emits when interrupts are part of a larger program.
Please post a couple of specific examples.
"It would be useful to be able to program this vector with the interrupt statement"
That is not what the interrupt keyword does. The interrupt keyword does exactly what it says on the tin - nothing more, nothing less.
See: http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm
"...cases where the C startup code was not used"
If the standard C startup is not being used, then you will have to provide your own anyhow - and it will have to be in assembler. It is easy in assembler!
"Kiel (sic) manual section on interrupts is incomplete and misleading"
No, it isn't. It tells you exactly what it does. It would be impossible to list all the things it doesn't do!
"It shows an interrupt as a stand-alone program"
Which particular section are you looking at?
The one cited above shows an example of an interrupt function - no suggestion that it is a complete program.
Atmel 8-bit Flash Microcontroller AT89C51RD2 page 73 This page www.e8051.com/InterruptVectors.htm lists the vector addresses, starting with RESET. Here is the disassembled code from a program that uses the EX0 interrupt, with vector address 3 C:0x0000 020187 LJMP STARTUP1(C:0187) C:0x0003 020247 LJMP edge1(C:0247)
In the brief Keil manual section on interrupts there are no long jumps in the assembly listing - clarifying what I said earlier. Of course you can do whatever you want in assembly code but you shouldn't have to do that when you are using a C compiler. The Keil C compiler for 8051 doesn't provide a way of installing a reset vector.
Well, there you go!
I still say that the Reset is not really an interrupt.
I beleive that the Philips 80C51_FAM_*.pdf docs are just copies of the intel originals, and they clearly show Reset as distinct from the interrupt vectors:
www.semiconductors.philips.com/.../80C51_FAM_ARCH_1.pdf - Figure 3.
Unfortunately, the intel original is no longer available at developer.intel.com/.../272383.htm
"In the brief Keil manual section on interrupts there are no long jumps in the assembly listing"
That's because it's just the disassembly of the function - not the vector table!
As it says on that page, "...shows you what the code generated to enter and exit the interrupt function looks like" - it does not claim to show the vector table.
"clarifying what I said earlier"
Not at all!
"The Keil C compiler for 8051 doesn't provide a way of installing a reset vector."
Because it isn't meaningful to the Keil C51 compiler!
The Keil C51 compiler relies upon its main() being called from the startup code - see: http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm
The e8051 says it's used on the Dallas Semiconductor DS89C450, but their datasheet also treats Reset as distinct from the interrupts: datasheets.maxim-ic.com/.../DS89C430-DS89C450.pdf
lists the vector addresses, starting with RESET.