PIC24 Support Libraries
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
chap8
ledtoggle_nofsm.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 program that toggles an LED whenever a pushbutton switch is pressed
34
and released. Does not use a finite statement approach.
35
*/
36
37
38
/// LED1
39
#define CONFIG_LED1() CONFIG_RB14_AS_DIG_OUTPUT()
40
#define LED1 _LATB14 //led1 state
41
42
/// Switch1 configuration
43
inline
void
CONFIG_SW1
() {
44
CONFIG_RB13_AS_DIG_INPUT();
//use RB13 for switch input
45
ENABLE_RB13_PULLUP();
//enable the pullup
46
}
47
#define SW1 _RB13 //switch state
48
#define SW1_PRESSED() (SW1==0) //switch test
49
#define SW1_RELEASED() (SW1==1) //switch test
50
51
int
main
(
void
) {
52
configBasic
(HELLO_MSG);
// Set up heartbeat, UART, print hello message and diags
53
/** GPIO config ***************************/
54
CONFIG_SW1
();
//configure switch
55
CONFIG_LED1
();
//configure LED
56
DELAY_US
(1);
//give pullups a little time
57
LED1 = 0;
//LED off initially
58
while
(1) {
59
// wait for press
60
while
(SW1_RELEASED())
doHeartbeat
();
//loop (1)
61
DELAY_MS
(15);
//debounce
62
// wait for release
63
while
(SW1_PRESSED())
doHeartbeat
();
//loop (2)
64
DELAY_MS
(15);
// debounce
65
LED1 = !LED1;
//toggle the LED
66
}
67
}
Generated by
1.8.4