msp430 timer interrupts and port interrupts

我与影子孤独终老i 提交于 2020-05-09 16:56:15

问题


I have written the following C code to trigger two port interrupts in order to blink a LED at different rates, I have used _delay_cycles(900000); instead I want to use a method delayMS(125); using timer interrpts, I tried as shown but Does not work , please help...

 #include <msp430.h>

 void initTimer_A(void);
 void delayMS(int msecs);

 unsigned int ofCount;


 int main(void) {

  WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog      timer
BCSCTL1 = CALBC1_1MHZ;      //Set DCO to 1Mhz
DCOCTL = CALDCO_1MHZ;

P1OUT=0X00;
P1DIR=0x01;         //P1.0 (LED) as output)
P1IES |= 0x08;      // high -> low is selected with IESx = 1.
P1IFG &= ~0x08;      // To prevent an immediate interrupt, clear the flag for
P1IE |= 0x08;        // Enable interrupts for P1.3
P1DIR &= ~0b00001000; // p1.3 as in


P2OUT=0X00;
P2DIR=0x01;   //P2.0 (LED) as output)
P2IES |= 0x08;   // high -> low is selected with IESx = 1.
P2IFG &= ~0x08;  // To prevent an immediate interrupt, clear the flag for
                   // P2.3 before enabling the interrupt.
P2IE |= 0x08;        // Enable interrupts for P1.3
P2DIR &= ~0b00001000; // p2.3 as in

    _enable_interrupt();
     // initTimer_A();

    ofCount = 0;


   P1OUT |= 0x01;          //Initially the led     will glow
   P2OUT |= 0x01;          //Initially the led will glow

    while(1)
    {

     }
    return 0;
  }

 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

   //configure timer

   void initTimer_A(void){

  TACCR0 = 0;
  TACCTL0 |= CCIE;
  TACTL = TASSEL_2 + ID_0 + MC_1;

  }

  void delayMS(int msecs){

  ofCount= 0;
  TACCR0 = 1000-1;

  while(ofCount<=msecs);

  TACCR0 = 0;//stp timer


 }

 #pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A_CCR0_ISR(void)
{

    ofCount++;

}

//+++++++++++++++++  port vectors       ++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  #pragma vector = PORT1_VECTOR     //PORT1     interupt vecotr name
  __interrupt void P1_ISR(void) {

while(P1IN == 1){
       P1OUT ^= BIT0;

This is the place where I want to change with delayMS() function using timer interrupts ….

       _delay_cycles(900000);
       //delayMS(125);
       P1OUT ^= BIT0;
      // delayMS(125);
       _delay_cycles(900000);
       P1IFG &= ~BIT3;  }         // clear the          interupt flag

     }


        #pragma vector = PORT2_VECTOR               
      __interrupt void P2_ISR(void) {

       while(P2IN == 1){

            P1OUT ^= BIT0;
           _delay_cycles(9000);
           //delayMS(125);
           P1OUT ^= BIT0;
           _delay_cycles(9000);
         //P2OUT ^= BIT0;
           P2IFG &= ~BIT3;     }      // clear    the interupt flag

       }

来源:https://stackoverflow.com/questions/61563418/msp430-timer-interrupts-and-port-interrupts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!