GeekDoc 226 Posted August 24, 2010 Share Posted August 24, 2010 I made the following up as an exercise/proof of concept and as the start of a project for my kids. They love their cars and Legos, and I thought they might like some police-style flashing lights. I got a lot of the info from TI's Low Power mode demo. The one thing I couldn't include was putting the 430 in a low power mode between watchdog interrupts. I'll have to look into that a bit more. This will be one portion, I want different flash modes, and other light sets (headlights, rear lights...), probably using other timers/counters, selectable by a button, as long as I have enough pins (this one just uses the built-in LEDs on the LaunchPad). Critiques appreciated. //************************************************************************ // MSP430G2211 "Police Light" Demo - WDT // // Description: This program uses the WDT to generate an interrupt every // ~8ms. A counter and if/else logic is used to determine which LED to // access, and whether to turn the LED on or off. This should result in // the typical double-flash on one side, then the other of emergency // vehicles. // // Carlton Dodd - http://blog.DocsTech.net // //************************************************************************ #include "msp430g2231.h" unsigned int wdtCounter = 0; void main(void) { //SETUP WDTCTL = WDT_MDLY_8; // Set Watchdog Timer interval to ~8ms IE1 |= WDTIE; // Enable WDT interrupt P1DIR |= BIT0 + BIT6; // P1.0 and 1.6 to output P1OUT = 0; // P1 all off __enable_interrupt(); } // Watchdog Timer interrupt #pragma vector=WDT_VECTOR __interrupt void watchdog_timer(void) { // multiplied all checks by 10 to get 80ms flashes/delays if(wdtCounter < 40) // first half of cycle, use LED1 { if(wdtCounter % 20 == 0) { P1OUT = BIT0; // P1.0 on (yes, I meant to just use '=' to clear all others) } else if (wdtCounter % 10 == 0) { P1OUT = 0; // Turn all of P1 output off } } else // second half of cycle, use LED2 { if(wdtCounter % 20 == 0) { P1OUT = BIT6; // P1.6 on (yes, I meant to just use '=') } else if (wdtCounter % 10 == 0) { P1OUT = 0; // Turn all of P1 output off } } wdtCounter++; if(wdtCounter > 80) //cycle is complete, start over { wdtCounter = 0; } } -Doc Quote Link to post Share on other sites
bluehash 1,581 Posted August 24, 2010 Share Posted August 24, 2010 Just got my Launchpad today and this was the first project I tried. +1 for your demo. Keep going. Will comment as I code. Quote Link to post Share on other sites
GeekDoc 226 Posted August 24, 2010 Author Share Posted August 24, 2010 Just got my Launchpad today and this was the first project I tried. I am honored, sir. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.