-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushcount.c
69 lines (54 loc) · 1.39 KB
/
pushcount.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// See http://homepages.ius.edu/rwisman/C335/html/Syllabus.htm
//
// A push of the button P1.3 increases the stored value by 1. Output is binary.
// Note: The button bounces
#include <msp430.h>
#include <legacymsp430.h>
#define SLEEP (15000U)
#define LED1 (1<<0)
#define LED2 (1<<6)
#define BTN (1<<3)
volatile unsigned int count;
int main(void) {
#define CBITS (6)
volatile unsigned int i;
int n;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= LED1; // Set P1.0 (red LED) to output
P1OUT &= ~LED1; // Turn LED off
P1DIR |= LED2; // Set P1.6 (green LED) to output
P1OUT &= ~LED2; // Turn LED off
P1SEL &= ~BTN; // Select Button
P1DIR &= ~BTN; // Select as Input (in = 0, out = 1)
P1REN |= BTN; // Pull-Up Resistor
P1IE |= BTN; // Generate interrupt
P1IFG &= ~BTN; // Clear Interrupt
_BIS_SR(GIE); // Enable Interrupts
count = 0;
while (1) {
// sync: 2 SLEEP green, red off
P1OUT |= LED2;
//P1OUT &= ~LED1;
for (i=0; i<2*SLEEP; i++);
// output C binary
for (n = (CBITS-1); n >= 0; n--) {
// toggle red LED
if (count & (1<<n)) {
P1OUT |= LED1;
} else {
P1OUT &= ~LED1;
}
// toggle green LED (clock)
P1OUT &= ~LED2;
for (i=0; i<SLEEP; i++);
P1OUT |= LED2;
for (i=0; i<SLEEP; i++);
}
}
return 0;
}
#pragma vector=PORT1_VECTOR
__interrupt void incrementor(void) {
P1IFG &= ~BTN; // Clear Interrupt
count = count + 1;
}