-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinout.c
51 lines (40 loc) · 905 Bytes
/
binout.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
// See http://homepages.ius.edu/rwisman/C335/html/Syllabus.htm
#include <msp430.h>
#include <legacymsp430.h>
#define SLEEP (3000U)
#define LED1 (1<<0)
#define LED2 (1<<6)
int main(void) {
volatile unsigned int i;
unsigned int c;
int n;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdoc 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
c = 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 = 15; n >= 0; n--) {
// toggle red LED
if (c & (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++);
}
// increment c
c++;
}
return 0;
}