PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
timer1_sosc.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 #include "pic24_all.h"
31 
32 
33 /** \file
34 Program uses Timer0 and an external 32.768 kHZ crystal for timekeeping.
35 */
36 
37 volatile uint16_t u16_seconds = 0;
38 
39 //Interrupt Service Routine for Timer1
40 void _ISRFAST _T1Interrupt (void) {
41  u16_seconds++;
42  _T1IF = 0; //clear the timer interrupt bit
43 }
44 
45 void configTimer1(void) {
46  T1CON = T1_OFF | T1_IDLE_CON | T1_GATE_OFF
47  | T1_SYNC_EXT_OFF
48  | T1_SOURCE_EXT
49  | T1_PS_1_1 ; //
50  PR1 = 0x7FFF; //period is 1 second
51  _T1IF = 0; //clear interrupt flag
52  _T1IP = 1; //choose a priority
53  _T1IE = 1; //enable the interrupt
54  T1CONbits.TON = 1; //turn on the timer
55 }
56 
57 int main(void) {
58  __builtin_write_OSCCONL(OSCCON | 0x02); // OSCCON.SOSCEN=1;
59  configBasic(HELLO_MSG); //say Hello!
60  configTimer1();
61  while (1) {
62  outString("Seconds: ");
63  outUint16Decimal(u16_seconds);
64  outString("\n");
65  while (!IS_TRANSMIT_COMPLETE_UART1());
66  SLEEP();
67  }
68 }