00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 00040 #include "pic24_all.h" 00041 00042 //Interrupt Service Routine for MathError 00043 void _ISRFAST _MathError (void) { 00044 //do not anything, just clear the error and continue 00045 _MATHERR = 0; //clear the _MATHERR flag to signal trap is handled 00046 RCOUNT = 0; //clear the RCOUNT to break repeat loop 00047 } 00048 00049 int main (void) { 00050 // If not volatile, then the compiler will optimize out 00051 // the 1/u8_zero code, NOT producing a divide by zero! 00052 volatile uint8 u8_zero; 00053 00054 configBasic(HELLO_MSG); 00056 while (1) { 00057 outString("Hit a key to start divide by zero test..."); 00058 inChar(); 00059 outString("OK. Now dividing by zero.\n" 00060 "The _MathError ISR should prevent the chip\n" 00061 "from resetting or reporting this error.\n\n"); 00062 u8_zero = 0; 00063 u8_zero = 1/u8_zero; 00064 doHeartbeat(); 00065 }// end while (1) 00066 }