PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ledflash_nomacros.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 /** \file
33 A simple program that flashes the power LED, does not use I/O macros.
34 RB15 is configured as an open drain output, and drives an LED at
35 the junction between the LED and a pullup resistor to VDD. When
36 RB15 is driven low, the LED is off. When RB15 is driven high,
37 the RB15 output floats because of the open drain, and so the
38 LED is turned on by the pullup resistor to VDD. This allows
39 the power LED to function as a 'blinky' LED in addition to serving
40 as a power indicator.
41 */
42 
43 //a naive software delay function
44 void a_delay(void) {
45  uint16_t u16_i,u16_k;
46  // change count values to alter delay
47  for (u16_k=1800; --u16_k;) {
48  for (u16_i = 1200 ; --u16_i ;);
49  }
50 }
51 
52 
53 int main(void) {
54  configClock(); //clock configuration
55  /********** GPIO config **********/
56 #ifdef _ODB15 //PIC24F CPU header files define this instead of ODCB15
57  _ODB15 = 1; //enable open drain
58 #else
59  _ODCB15 = 1; //enable open drain
60 #endif
61  _TRISB15 = 0; //Config RB15 as output
62  _LATB15 = 0; //RB15 initially low
63  while (1) { //infinite while loop
64  a_delay(); //call delay function
65  _LATB15 = !_LATB15; //Toggle LED attached to RB15
66  } // end while (1)
67 }