Editing A Tutorial on PIC interrupts using BoostC including Example Programs

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 35: Line 35:
  
 
===== Setup: =====  
 
===== Setup: =====  
 
Setup occurs in the main-line code, before the main loop.
 
  
 
The RBO interrupt -- Clear the flag, set for rising edge, and enable the interrupt.  
 
The RBO interrupt -- Clear the flag, set for rising edge, and enable the interrupt.  
 
    int main(void){
 
        ....
 
  
 
  clear_bit( intcon, INTF );  
 
  clear_bit( intcon, INTF );  
 
  set_bit( option_reg, INTEDG );  // set for rising edge
 
  set_bit( option_reg, INTEDG );  // set for rising edge
 
  set_bit( intcon, INTE ); // set to enable the interrupt
 
  set_bit( intcon, INTE ); // set to enable the interrupt
 
        ....
 
 
        // main loop
 
        while(1){ // forever
 
            ....
 
        };
 
    }
 
  
 
Here we assume the interrupt is originally off ( or the global interrupt is off ).  If you are not sure then turn them off at the beginning.
 
Here we assume the interrupt is originally off ( or the global interrupt is off ).  If you are not sure then turn them off at the beginning.
Line 60: Line 47:
  
 
In interrupts we almost always make sure that the interrupt is the one we think it is, clear the flag, and do the processing.  A key to the post processing is setting the counts and the  MinAct flag.
 
In interrupts we almost always make sure that the interrupt is the one we think it is, clear the flag, and do the processing.  A key to the post processing is setting the counts and the  MinAct flag.
 
The interrupt routine handles stuff we absolutely must deal with immediately during the interrupt (the "foreground task").
 
  
 
       if ( intf ) {  // are we in the external interrupt.
 
       if ( intf ) {  // are we in the external interrupt.
Line 97: Line 82:
 
When you get around to it ( but at least every minute ) check the MinAct flag, then do what you have to.  We assume that this process takes a bit of time, and you always try to take as little time in the interrupt as possible ( this usually makes the interrupts work better and lets you use more than one interrupt at a time).  In fact if you do not get around to executing your code within a minute it may not matter much, the time will still be kept correctly and the flag MinAct will still be set, you will miss executing "what you have to do" once but that may not matter.
 
When you get around to it ( but at least every minute ) check the MinAct flag, then do what you have to.  We assume that this process takes a bit of time, and you always try to take as little time in the interrupt as possible ( this usually makes the interrupts work better and lets you use more than one interrupt at a time).  In fact if you do not get around to executing your code within a minute it may not matter much, the time will still be kept correctly and the flag MinAct will still be set, you will miss executing "what you have to do" once but that may not matter.
  
Post-interrupt processing occurs in the main loop (the "background task").
+
if ( MinAct == 1 ) {
 
 
    int main(void){
 
        ...
 
 
 
        // main loop
 
        while(1){ // forever
 
            ....
 
 
 
            if ( MinAct == 1 ) {
 
 
                 MinAct = 0;  // clear the flag
 
                 MinAct = 0;  // clear the flag
                ........ what you have to do .....
+
........ what you have to do .....
            };
+
}
  
            ....
 
 
        };
 
    }
 
  
 
In the full code you also have to have code to move the hands of the clock, set it, etc.  It is in there: [[PIC based Stepper Motor Dancing Analog Clock]]
 
In the full code you also have to have code to move the hands of the clock, set it, etc.  It is in there: [[PIC based Stepper Motor Dancing Analog Clock]]

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)