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: ===== | ||
− | |||
− | |||
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. | ||
− | |||
− | |||
− | |||
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 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
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. | ||
− | |||
− | |||
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. | ||
− | + | if ( MinAct == 1 ) { | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
MinAct = 0; // clear the flag | MinAct = 0; // clear the flag | ||
− | + | ........ 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]] |