Jump to content
43oh

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?

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.

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;
 }
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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...