3-msp430 PIN Interrupt

Source: Internet
Author: User

In order to write an article to pave the mat-remind yourself,,,,,,

These two days have been looking for

#pragma vector = port1_vectorvoid p1_interrupt ()//P1 port Interrupt function {  }

For the explanation of these two sentences, at least let oneself feel can persuade oneself

After seeing a lot of my own understanding

#pragma vector = Port1_vector
In layman's terms, this is to tell the C compiler that the function below you is the interrupt function of the P1 port, and enters the following function when there is an interrupt in the P1 port.
__interrupt void P1_interrupt ()//p1 port interrupt function {  } 
What happened during that time?
In fact, there is an interrupt vector table inside MSP430----interrupt vector table is actually the storage unit space that holds the entry address of the interrupt function.
If you say, here is a paragraph of the table,,,, if,,,,,

So
#pragma vector = Port1_vector
You should understand that.
Tell the compiler that there is an interrupt service function for the P1 port, and you should put the address of the interrupt function in the

__interrupt//Tell the compiler this is an interrupt service function


One more example, suppose to write a serial port receive interrupt function

#pragma vector=uart0rx_vector

__interrupt void Uart_receive ()
{
  
}
In fact
#pragma vector=uart0rx_vector
Behind the
Uart0rx_vector is to tell the compiler, the following interrupt function is the serial port receive interrupt service function, you have to put its service function address to save the serial port to receive interrupt service function address

Right, back.
Port1_vector  P1 Mouth Interrupt
Port2_vector  P2 Mouth Interrupt

Uart0rx_vector Serial Receive Interrupt
Uart0tx_vector  Serial Send interrupt
Timer0_a0_vector Timer a interrupt
Steal a picture altogether

,,,,,,,,,

Business,

For pin interrupts, learning 51 knows nothing more than opening interrupts, then selecting the trigger mode, then writing the interrupt function, and then breaking the interrupt function to clear the interrupt flag (if said. It does not automatically clear the interrupt flag)

P1.2 Mouth has a drop along the P1.0 port of the pin reversal

#include"io430.h"voidMainvoid ){  //Stop watchdog timer to prevent time out resetWdtctl = Wdtpw +Wdthold; P1dir|= BIT0;//p1.0 Output ModeP1ie|= BIT2;//Enable p1.2 interruptP1ies |= BIT2;//Falling Edge TriggerP1IFG &= ~bit2;//Clear p1.2 Interrupt, feel dispensable, plus more looks like code is perfect__enable_interrupt ();  while(1)  {      }}#pragmaVector = Port1_vector__interruptvoidP1_interrupt ()//P1 Port Interrupt function{  if(p1ifg&BIT2)//p1.2 mouth to interrupt {P1IFG&= ~bit2;//clear the P1.2 PIN interrupt flag bitP1out ^= BIT0;//P1.0 pin Inversion  }}

What if I P1.2 and P1.3 want to interrupt?

P1.2 Mouth has a drop along the P1.0 port of the pin reversal

P1.3 Mouth has a drop along the P1.1 port of the pin reversal

#include"io430.h"voidMainvoid ){  //Stop watchdog timer to prevent time out resetWdtctl = Wdtpw +Wdthold; P1dir|= BIT0;//p1.0 Output ModeP1dir |= BIT1;//p1.1 Output ModeP1ie|= BIT2;//Enable p1.2 interruptP1ies |= BIT2;//Falling Edge TriggerP1IFG &= ~bit2;//Clear p1.2 InterruptsP1ie|= BIT3;//Enable p1.3 interruptP1ies |= BIT3;//Falling Edge TriggerP1IFG &= ~bit3;//Clear p1.3 Interrupts__enable_interrupt ();  while(1)  {      }}#pragmaVector = Port1_vector__interruptvoidP1_interrupt ()//P1 Port Interrupt function{  if(p1ifg&BIT2)//If P1.2 has interrupt {P1IFG&= ~bit2;//clear the P1.2 PIN interrupt flag bitP1out ^= BIT0;//P1.0 pin Inversion  }  if(p1ifg&BIT3)//If P1.3 has interrupt {P1IFG&= ~bit3;//clear the P1.3 PIN interrupt flag bitP1out ^= BIT1;//P1.1 pin Inversion  }}

In fact, I am a little puzzled,,, why the lights off at the same time! Simultaneous triggering, detection at the same time? P1 mouth is a whole, that is too good, at the same time with the interrupt detection multi-way, not afraid of the signal at the same time,,,,,,

3-msp430 PIN Interrupt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.