Multisim and Ultiboard

cancel
Showing results for 
Search instead for 
Did you mean: 

C interrupt vectoring

Hi there

I am struggling to get an interrupt to vector for me in the 8051 compiler in multisim simulation.

 

I have a simple external interrupt on EXTI0  set to edge triggered and enabled.

my isr is declared "interrupt void ext0isr (void) {...}" having read the hi-tech c51 manual this isr should be used whatever I call it.

yet the interrupt doesnt seem to vector at all other than the voltage change on the line to the INT0-bar pin there seems to be no indication that an interrupt has occured at all...

 

Have been scratching my head on this for months

The people over at Hi-Tech have been bought out and refuse to talk about anything not involving PICs

 

so any help much appreciated

0 Kudos
Message 1 of 4
(4,049 Views)

Hey Wolf

 

This may seem daft but have you placed anything in the interrupt to run when called. I dont know whats connected to your 8051 but maybe attach an LED to it and set the interrupt to light it for a reasonable length of time. At least this way we can verify if the interrupt is been called or not with that command.

Matthew Trott
Applications Engineer
National Instruments UK
www.ni.com/ask
0 Kudos
Message 2 of 4
(4,023 Views)

Hi Matthew,

 

🙂 yeah Ive basically got a simple keypad circuit set up with a 7-seg display for output of a pushed button. 

I also had a breakpoint set at the first instuction inside the ISR.

The Hi-tech manual mentions two different methods:

1) Use the interrupt keyword on one function and all interrupts will vector to this ISR. This does not work as far as I can tell

2) Use the macros ROM_VECTOR() or RAM_VECTOR() that are in intrpt.h. intrpt.h has not been included in the Hi-tech installation (maybe its not in the lite version thats used in multisim?)

 

The manual however, Ive found, does give the equivalent asm code for the macro, so I can add this directly into my code using the #asm, #endasm directives....

	#asm
	GLOBAL _ext1isr// ISR name = ext1isr()
	PSECT vectors,ovrld
	ORG 0x34// Int vector
	LJMP _ext1isr// ISR function name again with a preceding underscore added.
	PSECT text
	#endasm

 

This works! (Though TBH I dont really know whats going on here)

 

But this is not dynamic, the variables in the asm portion are hardcoded eg ORG 0x34 instead of ORG vector_addr_var. I can circumvent this by moving variables to specific reigisters (like ACC) in the C preceding the asm and then referenceing those specific registers in the asm, however I have only been able to make this work for simple variables, pointers to functions Im having more trouble with, eg: LJUMP _intrIsrFuncName could be replaced with LJUMP ACC  where ACC is given the address of the function intsIsrFuncName()

 

I have had trouble trying to assign the address of the ISR to the pointer, using the code below:

int main (void) {
	void (*pisr)(void);
	pisr = &ext1isr;// Line 23
	ACC = ((int*)pisr);// Line 24

	#asm
	GLOBAL _ext1isr
	PSECT vectors,ovrld
	#endasm

	ACC = 0x34;

	#asm
	ORG ACC
	#endasm

	ACC = ((int*)pisr);// Line 33

	#asm
	LJMP _ext1isr
	PSECT text
	#endasm
.
.
.
}

 I receive one error:

Error: C:\Documents and Settings\tmole\My Documents\National Instruments\Circuit Design Suite 11.0\MCU Workspaces\8051_keypad\8051_keypad\main.c : 23 undefined identifier "ext1isr"


and three warnings:

Warning: C:\Documents and Settings\tmole\My Documents\National Instruments\Circuit Design Suite 11.0\MCU Workspaces\8051_keypad\8051_keypad\main.c : 23 illegal conversion between pointer types
Warning: C:\Documents and Settings\tmole\My Documents\National Instruments\Circuit Design Suite 11.0\MCU Workspaces\8051_keypad\8051_keypad\main.c : 24 illegal conversion of pointer to integer
Warning: C:\Documents and Settings\tmole\My Documents\National Instruments\Circuit Design Suite 11.0\MCU Workspaces\8051_keypad\8051_keypad\main.c : 33 illegal conversion of pointer to integer

 

Frankly void pointers to functions is outside my knowledge of C. 

Any help much appreciated, would love to make this into a macro but again outside my level of knowledge.

Thanks

 

0 Kudos
Message 3 of 4
(4,021 Views)

Ok In that last bit of code I think the issue is you need to pass the contents of the pointer instead of the pointer itself. I believe this is done using the '&' symbol. So on lines 23,24 and 33 you would put &pisr.

 

I would check the syntax of this on somewhere like http://www.cprogramming.com/reference/ as it has been a while since I have done any c programming.

 

Matthew Trott
Applications Engineer
National Instruments UK
www.ni.com/ask
0 Kudos
Message 4 of 4
(4,018 Views)