MSP430F5529 (I) General I/O port settings-2

Publisher:WhisperingGlowLatest update time:2015-08-20 Source: eefocusKeywords:MSP430F5529 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This section talks about external interrupts.
Reading the introduction and understanding the program is the best way.
External interrupts are the lowest priority interrupts of MSP430 and are maskable interrupts. They are relatively simple to use.
 
1.2.7 Simple port interrupts (external interrupts)
                     All ports of P1 and P2 have interrupt capabilities and can be configured through registers PxIFG, PxIE and PxIES. For other ports, please refer to the specific pin manual. All P1 interrupt flags are the highest priority (compared to external interrupts of other pins), and P1IFG.0 is the best.
                     PXIV interrupt vector register: only P1IV and P2IV. The highest priority enabled interrupt generates a sequence number in the P1IV register, which will be recognized or added to the program counter, and then automatically execute the appropriate interrupt service routine. Disabling the P1 port interrupt will not affect the value in the P1IV register. The P2 port has the same function. The PxIV register can only be accessed by word.
                     PxIFGx interrupt flag register: This register is valid only when the corresponding interrupt enable PXIE is turned on and the general interrupt GIE is turned on.
                                   A low level indicates that there is no interrupt request waiting for response;
                                   a high level indicates that there is an interrupt request waiting for response;
                            Note: During the use of the port's interrupt function, if PXIN, PXOUT and other operations are performed, the interrupt may change.
Note: The interrupt flag needs to be cleared by software. There is one exception: if two interrupts occur at the same time, respond to the interrupt with a higher priority first. When the interrupt service program ends, the interrupt flag of this bit will be automatically cleared, and then respond to another interrupt. The low level
 
of the PxIE interrupt enable register
                                   indicates that the interrupt is turned off;
              the high level indicates that the interrupt is allowed; The low level
of the PXIES interrupt trigger mode selection register
                                   indicates a rising edge trigger;
                                   the high level indicates a falling edge trigger;

External interrupt application example: /*Using the interrupt mode, switch S2 (connected to P2.2) controls the LEDs (connected to P1) to light up one by one (see the PCB diagram for wiring)*/
#include  
int s=0; //s is used to indicate the number of key presses
int num =0; //num indicates the LED value
void main(void){
   WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog
   P1DIR=0xff; //P1 is all connected to output
   P1OUT=0x00; //Connect the LEDs for initialization, so pull them all low, so the lights are off at the beginning
   P2DIR=0x00; //P2 is all set to input Because it needs to accept external interrupts
   P2IFG=0x00; //Clear the interrupt flag of port P2
   P2IE=BIT2; //P2.2 turns on interrupt
   P2IES=0xff; //P2 is triggered by a falling edge
   P2IN=BIT2; //P2.2 input is pulled high, so when the switch is closed it will be pulled low to generate a falling edge (i.e. an interrupt)
   P2OUT=0xff;
   P2REN=0xff; //When used as an input, be sure to configure a pull-up resistor (very important, easy to forget, I made a mistake here -_')
   __enable_interrupt(); //Turn on the total interrupt
   while(1)
{
      num=s%5;
      switch(num){
         case 0:P1OUT=BIT1; break; case 1:P1OUT=
         BIT2;break;
         case 2:P1OUT=BIT3;break;
         case 3:P1OUT=BIT4;break;
         case 4:P1OUT=BIT5;break;}}}
#pragma vector=PORT2_VECTOR //Fixed format, declare interrupt vector address__interrupt
void Port2_ISR(void) {//interrupt subroutineunsigned
      int temp; //local variableint
      i;
      for(i=0;i<12000;i++); //delay debounceif
      ((P2IN&0xff)!=0xff){ //if a key is pressedtemp
         =P2IFG; //read interrupt
         flagP2IFG=0x00; //clear flagif
         (temp==0x04) //if P2.2 generates interrupts
            ++;}} //This part actually has a few redundant sentences, mainly to reflect the knowledge of each port interrupt
RemarksInterrupt subroutine call format:
#pragma vector=interrupt vector address__interrupt
void interrupt service program name(void) 

//interrupt handler
 } 
1.2.8 Unused I/OUnused
                     I/O pins are best set to normal I/O function, output direction and do not connect these pins on the PCB board to prevent floating input and reduce power consumption. Since these pins are not connected, their output values ​​do not need to be considered. Alternatively, you can enable the high/low registers by setting the PxREN register of the unused pins to avoid interference from floating inputs.
Keywords:MSP430F5529 Reference address:MSP430F5529 (I) General I/O port settings-2

Previous article:MSP430F5529 (II) Watchdog settings
Next article:MSP430F5529 (I) General I/O port settings-1

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号