Jump to content
Sign in to follow this  
Fizzel

Initialising Interrupt For Pic18f4520 With Sourceboost

Recommended Posts

Hello there,

 

i cant find this information in Sourceboost neither in the PIC-datasheet: How do i set up a interrupt with pragma-derictive. I saw a lot of examples in the net like

#pragma code HIGH_INTERRUPT_VECTOR = 0x8, but nothings works (unknown pragma in sourceboost). I do not want to use flag-query like

 

while( 1 )

{

if(flag1)

{

led1 = 1;

}

}

 

I want a true interrupt where my main-prog is interruptet imidiately to a defined adress.

 

Only thing I found in the datasheet is how to set the intcon-registers.

 

Would be very nice when somebody can help me!

Share this post


Link to post
Share on other sites
Hello there,

 

i cant find this information in Sourceboost neither in the PIC-datasheet: How do i set up a interrupt with pragma-derictive. I saw a lot of examples in the net like

#pragma code HIGH_INTERRUPT_VECTOR = 0x8, but nothings works (unknown pragma in sourceboost). I do not want to use flag-query like

Sound like code for a different compiler.

 

With BoostC use the following two function:

 

void interrupt()
{
...
}

// for PIC18 low priority interrupts
void interrupt_low()
{
...
}

Put the code to handle the interrupt within these functions.

 

if you want the function at a fixed address, say 0x200, use:

 

void interrupt() @ 0x200
{
...
}

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thx Dave!

 

ok here is my test-code:

 

main()

{	
porta.4=1;
	trisb.0=1;		//Input -> RB0 -> interrupt on falling edge (do i have to set RB0 as input when i want to use it as interrupt-source???)
	trisb.2=0;

inter_set();

while(1)
{
}

} 

void inter_set()
{
intcon.INT0IE=1; //enable external interrupt 1 on B0
intcon.INT0IF=0; //clear external interrupt flag
intcon2.RBPU=0; //turn off pull-ups
intcon.PEIE=0; //peripheral enable bit set false
intcon.INTEDG0=0; //active on falling edge (RB0)
intcon.GIE=1; //global interrupt enable on
}

void interrupt()
{
  	intcon.INT0IF=0; //clear flag
portb.2=1;		 //set RB1 to high wenn interrupt occours
intcon.GIE=1;

}

 

i can't test the code at the moment directly on the chip but do you think this should work or do i forget something?

 

as i remember this was the code i already tested and it ahsn't work??!

Share this post


Link to post
Share on other sites
ok here is my test-code:

....

void interrupt()

{

intcon.INT0IF=0; //clear flag

portb.2=1; //set RB1 to high wenn interrupt occours

intcon.GIE=1; <<< this is not needed

}

 

No need to re-enable the GIE bit in the interrupt service routine. The ISR automatically disables the GIE bit at the start of the interrupt event. This is done to prevent other interrupts from interfering with the main ISR and cause reentrancy problems (unless you are using hi/lo priority ISR's.. which is another thing all together). When the ISR exits the GIE bit is then re-enabled for the next interrupt event.

Edited by Sparky1039

Share this post


Link to post
Share on other sites

thanks for RE!

 

one more further question abot the #pragma-derictives:

 

#pragma DATA 0x300000,0x00,0x02

#pragma DATA 0x300002,0x1a,0x0e

#pragma DATA 0x300004,0x00,0x83

#pragma DATA 0x300006,0x85,0x00

#pragma DATA 0x300008,0x0f,0xc0

#pragma DATA 0x30000a,0x0f,0xe0

#pragma DATA 0x30000c,0x0f,0x40

 

i have to reprogramm a code and didnt understand what this exactly means...i havent found a good example about unsing #pragma data in this way. Could somebody please give me an example explanation about this form of using #pragma data. Is it a kind EEPROm settings?

 

Thanks and Regards

Share this post


Link to post
Share on other sites

Fizzel,

thanks for RE!

 

one more further question abot the #pragma-derictives:

 

#pragma DATA 0x300000,0x00,0x02

#pragma DATA 0x300002,0x1a,0x0e

#pragma DATA 0x300004,0x00,0x83

#pragma DATA 0x300006,0x85,0x00

#pragma DATA 0x300008,0x0f,0xc0

#pragma DATA 0x30000a,0x0f,0xe0

#pragma DATA 0x30000c,0x0f,0x40

 

i have to reprogramm a code and didnt understand what this exactly means...i havent found a good example about unsing #pragma data in this way. Could somebody please give me an example explanation about this form of using #pragma data. Is it a kind EEPROm settings?

 

Thanks and Regards

The addresses you specify here are for the devices configuration words. You can work out exactly what is being set by looking in the data sheet to see what all the bits are for.

 

For this device it's much more readable to use the configuration pragma ( "#prgama config" ), you can find what all the setting options are in the devices header file (ie in PIC18F4520.h) at the end.

 

Regards

Dave

Share this post


Link to post
Share on other sites

#pragma DATA 0x300000,0x00,0x02
#pragma DATA 0x300002,0x1a,0x0e
#pragma DATA 0x300004,0x00,0x83
#pragma DATA 0x300006,0x85,0x00
#pragma DATA 0x300008,0x0f,0xc0
#pragma DATA 0x30000a,0x0f,0xe0
#pragma DATA 0x30000c,0x0f,0x40

The following uses #pragma config and should produce the same configuration as above:-

/* 18F4520 Configuration Words */

/* Internal/External Oscillator config */

#pragma config OSC = HS, FCMEN = OFF, IESO = OFF

/* Power & Brown-out Reset Voltage config */

#pragma config PWRT = ON, BOREN = ON, BORV = 3

/* Watchdog Timer config */

#pragma config WDT = OFF, WDTPS = 128

/* Miscellaneous config */

#pragma config CCP2MX = PORTC
#pragma config PBADEN = ON
#pragma config LPT1OSC = OFF
#pragma config DEBUG = OFF
#pragma config MCLRE = ON
#pragma config STVREN = ON
#pragma config LVP = ON
#pragma config XINST = OFF

/* Code protection config */

#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
#pragma config CPB = OFF, CPD = OFF

/* Write block protection config */

#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF

/* Table read block protection config */

#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
#pragma config EBTRB = OFF

Regards

 

davidb

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...