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 00032 00037 volatile uint16 u16_seconds = 0; 00038 00039 //Interrupt Service Routine for Timer1 00040 void _ISRFAST _T1Interrupt (void) { 00041 u16_seconds++; 00042 _T1IF = 0; //clear the timer interrupt bit 00043 } 00044 00045 void configTimer1(void) { 00046 T1CON = T1_OFF | T1_IDLE_CON | T1_GATE_OFF 00047 | T1_SYNC_EXT_OFF 00048 | T1_SOURCE_EXT 00049 | T1_PS_1_1 ; // 00050 PR1 = 0x7FFF; //period is 1 second 00051 _T1IF = 0; //clear interrupt flag 00052 _T1IP = 1; //choose a priority 00053 _T1IE = 1; //enable the interrupt 00054 T1CONbits.TON = 1; //turn on the timer 00055 } 00056 00057 int main(void) { 00058 __builtin_write_OSCCONL(OSCCON | 0x02); // OSCCON.SOSCEN=1; 00059 configBasic(HELLO_MSG); //say Hello! 00060 configTimer1(); 00061 while (1) { 00062 outString("Seconds: "); 00063 outUint16Decimal(u16_seconds); 00064 outString("\n"); 00065 while (!IS_TRANSMIT_COMPLETE_UART1()); 00066 SLEEP(); 00067 } 00068 }