|
|
View previous topic :: View next topic |
Author |
Message |
kalas
Joined: 30 Sep 2008 Posts: 2
|
INTCON bit check |
Posted: Fri Feb 08, 2013 3:51 pm |
|
|
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
|
|
Posted: Fri Feb 08, 2013 4:00 pm |
|
|
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
|
|
Posted: Fri Feb 08, 2013 4:46 pm |
|
|
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
|
|
Posted: Fri Feb 08, 2013 5:57 pm |
|
|
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
|
|
Posted: Sat Feb 09, 2013 1:44 am |
|
|
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 |
|
|
|
|
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
|