Initial commit
This commit is contained in:
commit
836a7983c1
4 changed files with 136 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
*.elf
|
||||
23
Makefile
Normal file
23
Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
CC = msp430-gcc
|
||||
CFLAGS = -Os -Wall -g -mmcu=msp430x2012
|
||||
LD = $(CC)
|
||||
LDFLAGS =
|
||||
|
||||
PROGRAMS = led1.elf led2.elf
|
||||
|
||||
.PHONY : clean distclean
|
||||
|
||||
all : $(PROGRAMS)
|
||||
|
||||
led1.elf : led1.o
|
||||
led2.elf : led2.o
|
||||
|
||||
%.elf :
|
||||
$(LD) -o $@ $^
|
||||
|
||||
clean :
|
||||
$(RM) *.o
|
||||
|
||||
distclean : clean
|
||||
$(RM) $(PROGRAMS)
|
||||
34
led1.c
Normal file
34
led1.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
#include <msp430.h>
|
||||
|
||||
/*
|
||||
* P1 bit 0 = red led.
|
||||
* P1 bit 6 = green led.
|
||||
* P1 bit 3 = button.
|
||||
*/
|
||||
|
||||
int main(void) {
|
||||
/* Init watchdog timer to off */
|
||||
WDTCTL = WDTPW | WDTHOLD;
|
||||
|
||||
/* set all P1 direction to input. */
|
||||
P1DIR = 0x0;
|
||||
|
||||
/* set red led to output */
|
||||
P1DIR |= BIT0;
|
||||
|
||||
P1OUT = 0x0;
|
||||
|
||||
for(;;) {
|
||||
/*
|
||||
* P1.3 bit set -> button _not_ pressed.
|
||||
*/
|
||||
if (P1IN & BIT3) {
|
||||
P1OUT &= ~BIT0;
|
||||
} else {
|
||||
P1OUT |= BIT0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
77
led2.c
Normal file
77
led2.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
#include <msp430.h>
|
||||
|
||||
/*
|
||||
* P1 bit 0 = red led.
|
||||
* P1 bit 6 = green led.
|
||||
* P1 bit 3 = button.
|
||||
*/
|
||||
|
||||
#define N_STATES 4
|
||||
|
||||
int state = 0;
|
||||
|
||||
/* G | R | state (dec)
|
||||
* 0 | 0 | 0
|
||||
* 0 | 1 | 1
|
||||
* 1 | 0 | 2
|
||||
* 1 | 1 | 3
|
||||
*/
|
||||
|
||||
void update(void) {
|
||||
|
||||
static unsigned in_progress = 0;
|
||||
|
||||
if (in_progress)
|
||||
return;
|
||||
in_progress = 1;
|
||||
|
||||
state = (state + 1) % N_STATES;
|
||||
|
||||
/* first bit set, enable red */
|
||||
if (state & BIT0)
|
||||
P1OUT |= BIT0;
|
||||
else
|
||||
P1OUT &= ~BIT0;
|
||||
|
||||
/* second bit set, enable green */
|
||||
if (state & BIT1)
|
||||
P1OUT |= BIT6;
|
||||
else
|
||||
P1OUT &= ~BIT6;
|
||||
|
||||
in_progress = 0;
|
||||
}
|
||||
|
||||
void delay(void) {
|
||||
|
||||
int i = 0x6fff;
|
||||
|
||||
while(i--)
|
||||
nop();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
/* Init watchdog timer to off */
|
||||
WDTCTL = WDTPW | WDTHOLD;
|
||||
|
||||
/* set all P1 direction to input. */
|
||||
P1DIR = 0x0;
|
||||
|
||||
/* set direction to output on both leds */
|
||||
P1DIR |= (BIT0 | BIT6);
|
||||
|
||||
P1OUT = 0x0;
|
||||
|
||||
for(;;) {
|
||||
/*
|
||||
* P1.3 bit set -> button _not_ pressed.
|
||||
*/
|
||||
if (!(P1IN & BIT3))
|
||||
update();
|
||||
|
||||
delay();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in a new issue