In: Electrical Engineering
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
1.
#include <msp430fr6989.h> // For the M430FR6989 chip,
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1REN |= 0x08; //Turn on PullUp on????? How do you turn it off?
P1DIR &= ~BIT3; // Push Port 1 P1.3 (push button) as input
//P1OUT &= 0x08; // Pull down resistor???
P1DIR |= BIT6; // Set (LED) to output direction
P1SEL &= ~(BIT3 | BIT6); // Select (push button)
P1OUT &= ~BIT6; // Set the LED off
int value = P1IN & BIT3;
while( 1 ) {
if( value == 0) // Push button down when bit 3 == 0
P1OUT |= BIT6; // Set LED on when button down
else
P1OUT &= ~BIT6; // Set LED off when button off
}
}
2.
#include <msp430fr6989.h> |
int main(void) { |
volatile int i; |
// stop watchdog timer |
WDTCTL = WDTPW | WDTHOLD; |
// set up bit 0 of P1 as output |
P1DIR = 0x01; |
// intialize bit 0 of P1 to 0 |
P1OUT = 0x00; |
// loop forever |
for (;;) { |
// toggle bit 0 of P1 |
P1OUT ^= 0x01; |
// delay for a while |
for (i = 0; i < 0x6000; i++); |
}
}