This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello Software Masters. I'm just a beginner in using CCS and I was so confuse on how to program using this software.
I previously used the energia software. Kindly help me on how to program below. I need your expert ideas for me to learn on how to use this software.
Scene:
When I press the button in P1.3 the LED at P1.0 will turn on and will not turn off unless I press again the same button.
For those who will answer my inquiry, Thank you so much.
Hi Sharmaine!
This is a very simple task and I guess it would be the best if you try to solve it on your own, getting help here in the forum when something does not work as expected. So what do you already know? You can split this task into smaller ones, like first control only the LED without the button.
Configure P1.0 to output direction and set the output pin high or low to switch the LED on or off.
Are you able to do that? How would you have done it in Energia?
Dennis
OK, so although I do not know about those Energia functions, this doesn't look that bad at all. I would now recommend to read chapter 8 of the user's guide. It describes the Digital I/O of the microcontroller. If you know this, half of your project is already done. In addition you should learn about bitwise operations.
Hi Sharmaine!
Sounds good. If you share the code with us we can see what is wrong / missing.
(When posting code please use rich formatting which appears on the lower right when pressing on reply and then use the small </> icon)
Dennis
#include <msp430g2553.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT6; // Set P1.6 (green LED) to output direction, 1 is output
P1OUT &= ~BIT6; // Set the green LED off
P1DIR &= ~BIT3; // Port 1 P1.3 (push button) as input, 0 is input
P1REN |= BIT3; // Enable Port 1 P1.3 (push button) pull-up resistor
P1OUT |= BIT3; // The button is up
while(1)
{
if( (P1IN & BIT3 ) == 0) // Push button down when bit 3 == 0
{
if ((P1OUT | BIT6) == 0)
{
P1OUT &= ~BIT6;
}
else
{
P1OUT |= BIT6;
}
}
}
}
Hi Sharmaine!
Dennis Eichmann said:(When posting code please use rich formatting which appears on the lower right when pressing on reply and then use the small </> icon)
This is how it looks like when using rich formatting and the code insertion tool:
#include <msp430g2553.h> void main( void ) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= BIT6; // Set P1.6 (green LED) to output direction, 1 is output P1OUT &= ~BIT6; // Set the green LED off P1DIR &= ~BIT3; // Port 1 P1.3 (push button) as input, 0 is input P1REN |= BIT3; // Enable Port 1 P1.3 (push button) pull-up resistor P1OUT |= BIT3; // The button is up while( 1 ) { if( (P1IN & BIT3 ) == 0 ) // Push button down when bit 3 == 0 { if( (P1OUT | BIT6) == 0 ) { P1OUT &= ~BIT6; } else { P1OUT |= BIT6; } } } }
Now there are line numbers you can refer to, for example.
What do you want to do here?
if( (P1OUT | BIT6) == 0 )
I guess you want to test if P1.6 is actually low, right? The output register can be read equally to the input register:
if( (P1OUT & BIT6) == 0 )
Dennis
**Attention** This is a public forum