CCR Interrupt Mask Bit in C?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CCR Interrupt Mask Bit in C?

2,756 Views
BasePointer
Contributor II
Hi,
 
How can I move CCR to my local variable in C?
 
I have to test I bit:
 
void foo()
{
   unsigned char before = CCR_I <---
  
   DisableInterrupts;
   ....
   ....
   if(before) EnableInterrupts;
}
 
10x
BP.


Message Edited by BasePointer on 2008-04-04 12:39 PM
Labels (1)
0 Kudos
5 Replies

595 Views
fabio
Contributor IV
Hi BP,

Try the __isflag_int_enabled() function. It returns true if I = 0.

void foo()
{
   unsigned char before;
   before = __isflag_int_enabled();
  
   DisableInterrupts;
   ....
   ....
   if(before) EnableInterrupts;
}

Ps.: this is in my new book :smileywink:

Best regards,


Message Edited by fabio on 2008-04-04 12:03 PM
0 Kudos

597 Views
BasePointer
Contributor II
Hi fabio,
 
The code below works for me.
 
Code:
#include "intrinsics_hc08.h"void foo(void){  unsigned char before = __isflag_int_enabled();    DisableInterrupts; /* disable interrupts */  ..  ...  if(before) EnableInterrupts; /* enable interrupts */  }

 
Thank you so much.
BP.
0 Kudos

597 Views
admin
Specialist II

Hi all,

I have a query regarding Z bit in CCR. When the following is performed,

a= 10

b=10

if (a==b), then Z flag should be set to TRUE.

However as soon as the instruction is executed the Z flag is cleared, when any other statements in the code is executed. There are no decision statements which is executed after this.

As I am from a testing background, I expect Z flag to be set to TRUE, until next comparison is performed.

Please help me out on this.

Thanks,

Dharani

0 Kudos

597 Views
bigmac
Specialist III


Hello Dharani,

If you examine the reference manual for the device you are using, you should observe that a large proportion of the assembly instructions will affect the status of the Z-flag, not just the compare instructions.

You would seem to have two choices within your C code -

  1. Do the comparison each time a branch decision is required.
  2. Assign the comparison result to a variable, and then test the value within the variable for each decision.

For the latter method:

byte a, b, c;

...

c = (a == b);  // Result is true or false

...

if (c)  {

  // Do something

}

Regards,

Mac

0 Kudos

597 Views
peg
Senior Contributor IV
Hi,

As the CCR is stacked you could use a method similar to that proposed here.
Or you could add a little assembly like this:

PSHA
TPA
STA variable
PULA

0 Kudos