Jump to content
Sign in to follow this  
biza

Bliking a LED every 500ms

Recommended Posts

Hi, people I need some help,I do this code:

#include <msp430g2553.h>/*MCU */
#define LED_VERMELHA    BIT0
int SS = 0;
int main(void){
   WDTCTL = WDTPW + WDTHOLD;
P1DIR |= (LED_VERMELHA);
   P1OUT &= ~(LED_VERMELHA);


 if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
   BCSCTL1 = CALBC1_1MHZ;
   DCOCTL = CALDCO_1MHZ;

 TA0CCR0 = 65500;
   TA0CCTL0 = CCIE;
   TA0CTL = TASSEL_2 + MC_1 + ID_3;  
   _BIC_SR(GIE); /*ENABLE INTERRUPT*/


   while(1){
   }
}

#pragma vector=TIMER0_A0_VECTOR
   __interrupt void Timer_A(void) {	/*TIMER0_A0 INTERRUPT SERVICE ROUTINE*/

	SS++;
	P1OUT ^= LED_VERMELHA;

}

I would like to flash the LED every 500ms, but I can not make it work, can someone help me?

Share this post


Link to post
Share on other sites
_BIC_SR(GIE); /*ENABLE INTERRUPT*/

That line actually "disables" interrupts. The function stands for "Bit Clear Status Register." It clears the GIE or General Interrupt Enable bit in the status register in this instance. What you want is:

_BIS_SR(GIE); /*ENABLE INTERRUPT*/

This enables interrupts. It stands for "Bit Set Status Register." This sets the GIE bit in the status register, which will then enable interrupts.

Share this post


Link to post
Share on other sites

 

 if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
   BCSCTL1 = CALBC1_1MHZ;
   DCOCTL = CALDCO_1MHZ;


 

That looks wrong too; if either the BC1 or DCO calibrations for 1MHz are invalid you'll initialize BCSCTL1, then unconditionally you initialize DCOCTL.

Maybe something like:

 if ((CALBC1_1MHZ != 0xFF)  && (CALDCO_1MHZ != 0xFF)) {
   BCSCTL1 = CALBC1_1MHZ;
   DCOCTL = CALDCO_1MHZ;
 }

Share this post


Link to post
Share on other sites

I have attached a zipped file to the bottom of this post. It shows some examples of how to use Timer A. Read the "!README" file first. It will tell you what all of the example files are referring to. Then, look specifically at the msp430g2xx3_ta_*  examples. They'll be helpful guides.

MSP430g2xx3 Examples.zip

Share this post


Link to post
Share on other sites

I have attached a zipped file to the bottom of this post.

That material is from TI and can also be found, along with other examples and documentation, on the microcontroller homepage at http://www.ti.com/product/msp430g2553

 

@biza: I agree that starting with working examples is the best approach to solving this problem. Change something that blinks until it blinks at 500ms, then see what you did wrong in your original version.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×