CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

INTCON bit check

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kalas



Joined: 30 Sep 2008
Posts: 2

View user's profile Send private message

INTCON bit check
PostPosted: Fri Feb 08, 2013 3:51 pm     Reply with quote

Hi

I would like to check the RBIF bit in INTCON. I don't want use the ISR because this check is done in an init part of my project, the ISR have another job to do in the main part of the program.

In the PIC mcu datasheet we can see this:

" Interrupt flag bits are set when an interrupt
condition occurs, regardless of the state of
its corresponding enable bit or the global
enable bit."

But if I do a test loop on the flag, it is never set.

If I enable ext_int, the bit is set and the isr is executed.
Code:
#BYTE intcon = 0xFF2
...
        t = input_b();
   bit_clear(intcon,0);

   while (!bit_test(intcon,0));    // Endless Loop :(
   {}
...


What wrong with my direct check ?

Compiler 4.057
MPLAB 8.84
Simulation Proteus
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Fri Feb 08, 2013 4:00 pm     Reply with quote

First, use the #bit directive, or the compiler functions:

Code:

clear_interrupts("INT_RB");
while (!interrupt_active("INT_RB");

//or
#bit RBIF=getenv("BIT:RBIF")

RBIF=FALSE;
while(!RBIF);


Neater, easier, and more likely to work. The 'byte wide' operations, involve reading the whole register, masking the individual bit, and testing/clearing this, when the bit wide operations use the processors bit set/reset operations.

However remember that you need to turn _off_ one or both of the the interrupt enables, before this can work. Otherwise the ISR will be called, and the bit will never test as 'true', since the ISR will clear it.

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 08, 2013 4:46 pm     Reply with quote

also be well aware that Proteus is full of bugs,errors and faulty RDCs !! Just because you cut 'good' code doesn't mean it will work right !!!!!
kalas



Joined: 30 Sep 2008
Posts: 2

View user's profile Send private message

PostPosted: Fri Feb 08, 2013 5:57 pm     Reply with quote

Ttelmah wrote:
First, use the #bit directive, or the compiler functions:

Code:

clear_interrupts("INT_RB");
while (!interrupt_active("INT_RB");

//or
#bit RBIF=getenv("BIT:RBIF")

RBIF=FALSE;
while(!RBIF);



For clear the flag the 2 ways are good.
But for the test, none of them do the job.
INTCON:RBIF stay low.

If I enable the interrupt, INTCON:RBIF is set, the ISR is executed.

@temtronic: I don't know if my question/problem is in the MPLAB,VSM or Proteus "layer".

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Feb 09, 2013 1:44 am     Reply with quote

Probably Proteus.
What you are trying to do, certainly does work in real chips. This is why we 'hate Proteus', since it has three big problems:
1) It'll tell you things can't work, that do in the real chips.
2) It'll tell you other things do work, that won't in the real chips.
3) It doesn't know about all the oddities with individual PIC's....

If you have MPLAB, use MPLAB SIM. Program a stimulus to set/reset a pin on port B, and see what happens.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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