igendel

MSP430G2553 WDT Interrupt Blinky

Mar 7th, 2021
747
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Demo: Green LED blink from main code, red LED blink from WDT interrupt
  2. // Target: MSP430G2 Launchpad, with MSP430G2553 IC
  3.  
  4. #include <stdint.h>
  5. #include <msp430.h>
  6.  
  7. int main(void) {
  8.  
  9.     volatile uint16_t x;
  10.  
  11.     WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
  12.  
  13.     P1DIR = 0b01000001; // Pin P1.6 (green LED) and P1.0 (red LED) are Outputs
  14.  
  15.     BCSCTL3 |= 32; // ACLK from internal VLOCLK
  16.  
  17.     // Resume WDT in Timer Mode, from ACLK, /8192, Reset count.
  18.     WDTCTL = WDTPW | WDTTMSEL | WDTSSEL | WDTIS0 | WDTCNTCL;
  19.  
  20.     IE1 |= WDTIE; // Enable WDT interrupt
  21.     __enable_interrupt();
  22.  
  23.     // Regular code to blink the green LED
  24.     for ( ; ; ) {
  25.  
  26.         for (x = 25000; x; --x) {} // Poor man's delay
  27.         P1OUT ^= 0b01000000; // Toggle green LED
  28.  
  29.     }
  30.  
  31.     return 0;
  32. }
  33.  
  34.  
  35. #pragma vector=WDT_VECTOR
  36. __interrupt void WDT_ISR(void) {
  37.  
  38.     P1OUT ^= 0b00000001; // Toggle red LED
  39.  
  40. }
  41.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×