Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Where is a good place to start for C tutorials? And challenges with button push led program

$
0
0

Well I am definately a newbie at this, I have tried to use CCS6 to get rolling with my launchpads but am getting my butt handed to me.  I have been able to get some odds and ends done in Energia, but I want to use and learn CCS.  I can't even get a stupid button push to get a led to turn on to work. 

 

I know learning C will help with this as many of the operators just have me at a loss right now. 

 

I have tried soome pre written codes such as

/* pushy_G2211: a simple demo of configuring push-buttons on
 * input pins.
 */

#include <msp430g2553.h>

#define red_LED   BIT0
#define grn_LED   BIT6
#define BTN       BIT3

void delay(void);

void main(void) {
    unsigned int flash;
    WDTCTL = WDTPW + WDTHOLD;

    P1OUT = 0;
    P1DIR |= red_LED + grn_LED;  // LED pins to outputs, BTN is
                                 // still an input by default.

    for (;;) {

        for (flash=0; flash<7; flash++) {
            P1OUT |= red_LED;    // red LED on
            delay();             // call delay function
            P1OUT &= ~red_LED;   // red LED off
            delay();             // delay again
        }

        while ((P1IN & BTN) == BTN);  // wait for button press

        for (flash=0; flash<7; flash++) {
            P1OUT |= grn_LED;    // green LED on
            delay();
            P1OUT &= ~grn_LED;   // green LED off
            delay();
        }

        while ((P1IN & BTN) == BTN);  // wait for button press

    }
} // main

void delay(void) {
    unsigned int count;
    for (count=0; count<60000; count++);
} // delay


I can not get anything to work correctly,    both LED's are on at the same time, do I need to add a line in there to set the LED's at 0 for the initial ?   I thought the     P1OUT = 0 would set that at 0 to start??  I am so lost. 

 

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Viewing all articles
Browse latest Browse all 2077

Trending Articles