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 00030 #include "pic24_all.h" 00031 00038 00039 #define CONFIG_LED1() CONFIG_RB14_AS_DIG_OUTPUT() 00040 #define LED1 _LATB14 //led1 state 00041 00042 //Interrupt Service Routine for Timer3 00043 void _ISRFAST _T3Interrupt (void) { 00044 LED1 = !LED1; //toggle the LED 00045 _T3IF = 0; //clear the timer interrupt bit 00046 } 00047 00048 #define ISR_PERIOD 300 // in ms 00049 00050 void configTimer3(void) { 00051 //ensure that Timer2,3 configured as separate timers. 00052 T2CONbits.T32 = 0; // 32-bit mode off 00053 //T3CON set like this for documentation purposes. 00054 //could be replaced by T3CON = 0x0030 00055 T3CON = T3_OFF | T3_IDLE_CON | T3_GATE_OFF 00056 | T3_SOURCE_INT 00057 | T3_PS_1_256 ; //results in T3CON= 0x0030 00058 PR3 = msToU16Ticks (ISR_PERIOD, getTimerPrescale(T3CONbits)) - 1; 00059 TMR3 = 0; //clear timer3 value 00060 _T3IF = 0; //clear interrupt flag 00061 _T3IP = 1; //choose a priority 00062 _T3IE = 1; //enable the interrupt 00063 T3CONbits.TON = 1; //turn on the timer 00064 } 00065 00066 int main (void) { 00067 configBasic(HELLO_MSG); 00069 CONFIG_LED1(); //config the LED 00070 LED1 = 1; 00072 configTimer3(); 00073 while (1) { 00074 //enter idle mode while waiting for timer to go off 00075 //Timer interrupt will wake us from idle mode 00076 IDLE(); //macro for __asm__ volatile ("pwrsav #1") 00077 } 00078 // End program 00079 return 0; 00080 }