|
|
View previous topic :: View next topic |
Author |
Message |
Fro_Guy
Joined: 26 Apr 2006 Posts: 12
|
Context saving with #int global |
Posted: Thu Jun 15, 2006 2:25 pm |
|
|
I am working on my own intrupt handler for a PIC16F877, and it seems like i am having problems with the context saving. I can get the interupts to work fine if say for the serial, timers and ect. if i use the compiler to do it for me. Looking at the context saving when it goes into the intrupt it saves the @SCRATCH memory registers (shown in the symbol file) put there by the compiler. I am thinking it is the @SCRATCH registers that is causing flakey behavior in my ISR, and i was wondering if anyone know exactly what the compiler uses it for as well as what built in functions would use these registers. Also if it is at all possible to set where these @scratch registers are located in the ram.
Thanks for the help
Fro Guy |
|
|
Ttelmah Guest
|
|
Posted: Thu Jun 15, 2006 2:46 pm |
|
|
The scratch area, defaults to the bottom 4 to 5 locations of the useable RAM. This can be seen/set in device editor, memory, where the 'C scratch RAM' setting, says where it starts. On 16 chips, it'll normally be 0x20 (above the basic registers in the first bank), while on the 18 chips, it'll be at 0.
You can save these yourself, by using code like:
Code: |
#byte scratch0=0
#byte scratch1=1
#byte scratch2=2
#byte scratch3=3
//and then use in the interrupt handler:
static int INT_scratch[10];
#asm
MOVFF scratch0,INT_scratch+0
MOVFF scratch1,INT_scratch+1
MOVFF scratch2,INT_scratch+2
MOVFF FSR0L,INT_scratch+3
MOVFF FSR0H,INT_scratch+4
MOVFF FSR1L,INT_scratch+5
MOVFF FSR1H,INT_scratch+6
MOVFF TBLPTRL,INT_scratch+7
MOVFF TBLPTRH,INT_scratch+8
MOVFF TBLPTRU,INT_scratch+9
#endasm
|
Various ones are used for different things. The return value from a function call, will use up to four locations, arithmetic, printf, long delays etc., all use one or more locations. Looking through the listing, is the only way to really be sure...
The save shown above, saved three scratch locations, the FSR registers, and the TBLPTR registers. The latter were needed for an array access, while the first scratch location was used in a SSP call, and the latter two locations were used for a return value.
Best Wishes |
|
|
Fro_Guy
Joined: 26 Apr 2006 Posts: 12
|
|
Posted: Fri Jun 16, 2006 6:38 am |
|
|
Thanks for the help!!!
Fro Guy |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|