biza 0 Posted April 15, 2014 Share Posted April 15, 2014 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? Quote Link to post Share on other sites
Foghorn 8 Posted April 15, 2014 Share Posted April 15, 2014 _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. Quote Link to post Share on other sites
pabigot 355 Posted April 15, 2014 Share Posted April 15, 2014 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; } Quote Link to post Share on other sites
biza 0 Posted April 15, 2014 Author Share Posted April 15, 2014 already fix the mistakes you have detected, but still not flashing the LED every 500ms Quote Link to post Share on other sites
Foghorn 8 Posted April 16, 2014 Share Posted April 16, 2014 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 Quote Link to post Share on other sites
pabigot 355 Posted April 16, 2014 Share Posted April 16, 2014 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. 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.