...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#include <msp430.h> // Include MSP430-specific defines int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1OUT &= ~BIT0; // Clear P1.0's output value P1DIR |= BIT0; // Set P1.0 as an output for (;;) { P1OUT ^= BIT0; // Toggle P1.0 using bitwise XOR __delay_cycles(100001000000); // Software delay } return 0; } |
...
This function delays the processor for x cycles (10,000 in our case). In our case, we chose 1,000,000 because MCLK runs at 1Mhz by default so it should be around 1 second of delay. So, in our loop, we toggle the state of the LED (if it's on, it turns off, and if it's off, it turns on) and then we wait for a little bit. This creates the effect of the LED blinking.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#include <msp430.h> /* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1OUT &= ~BIT0; P1DIR |= BIT0; TACTL |= TASSEL_2 | MC_2 | ID_3; TACCTL0 |= CCIE; TACCR0 = 65535; __enable_interrupt(); for (;;) { } return 0; } #pragma vector = PORT1TIMERA0_VECTOR __interrupt void PORT1_ISR(void) { P1OUT ^= BIT0; } |
...