8737 views|28 replies

7249

Posts

192

Resources
The OP

[After-class Exercise] After-class Exercise 2 IO Interruption [Copy link]

After-class Exercise 2 IO Interruption

1. First look at the schematic diagram

2. Pin settings

PxDIR Input / Output Direction Register

PxIN Input Register

PxOUT Output Register

PxIFG Interrupt Flag Register

PxIE Interrupt Enable Register

PxSEL Function Selection Register

3. Application

Application 1: Key as interrupt

P1.3 —— key as interrupt

Reference books,

(1) If some pins of port P1 are used as interrupt mode, be sure to set the corresponding bits of the P1IFG , P1IES , and P1IE registers before opening the general interrupt , and ensure that the corresponding pins are in the input direction.

(2) To minimize power consumption, the connected pins should be set to IO functions and set to output.

(3) The interrupt flag needs to be cleared by software

Question 1 : Some people see the program saying that the general interrupt is __enable_interrupt

Some people say that the general interrupt is _EINT()

In fact, both are correct, look at the header file.

/* Deprecated, please use "__disable_interrupt" instead. */

#define _DINT() __disable_interrupt()

/* Deprecated, please use "__enable_interrupt" instead. */

#define _EINT() __enable_interrupt()

/* Deprecated, please use "__no_operation" instead. */

#define _NOP() __no_operation()

Question 2 : I used someone else's IO interrupt to light up , but it doesn't enter the interrupt every time

Later I found out that key interrupts also need to be debounced.

for(i=0;i<0x1fff;i++); // Debounce is essential!!

Question 3 : XOR negation

Question 4 : The interrupt flag needs to be cleared by software and needs to be cleared for each interrupt.

This post is from Microcontroller MCU

Latest reply

Just asking, I am using 2553, and it is said that some of the problems are probably caused by different interrupt initialization functions. I use IAR, and the interrupt initialization function is __enable_interrupt(); Now there is a problem, that is, each IO port of 430 can be used as an IO port interrupt, so if other IO ports generate interrupts when executing a certain IO interrupt, how to determine the priority?  Details Published on 2014-8-26 17:45

7249

Posts

192

Resources
2

  1. /***************************************************
    **** LAUNCH PAD Learning GPIOINT ***
    **** MCU: MSP430 ***
    **** Author: Chang Jianze***
    **** ***
    **** ***
    **** 2012.05.24.20:16 ***
    **** Experimental phenomenon: Press the button***
    **** Interrupt enable register only has P1P2***
    **** Press the button once, the LED turns on or off once***
    ***********************************************/

    #include

    void Key_init(void)
    {
    P1REN |= BIT3; //Turn on the pull-up, there is no pull-up resistor on the circuit board, and the trigger edge is from high level to low level
    P1IES |= BIT3; //Select the trigger edge, the falling edge triggers
    P1IE |= BIT3; //Turn on the interrupt of P1.3
    P1IFG &= 0x00;
    }

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Turn off the watchdog

    P1DIR |= BIT0; //Set the P1.0 pin to output
    P1OUT |= BIT0; //P1.0 pin outputs low level
    Key_init(); //Call IO interrupt initialization function

    _EINT(); //Turn on the total interrupt. Without this step, all interrupts cannot be triggered

    while(1); //Infinite loop

    }

    #pragma vector = PORT1_VECTOR //Interrupt vector declaration
    __interrupt void Key_interrput(void)
    {
    unsigned int i;
    for(i=0;i<0x1fff;i++); //Debounce is essential! !
    if(P1IFG&BIT3) //Judge whether the P1.3 IO port has an interrupt
    { //If an interrupt occurs, P1IFG.3 is set to 1
    P1OUT ^= BIT0; //LED2 is inverted
    P1IFG &= 0x00; //The interrupt flag needs to be cleared by software! ! !
    P1REN |= BIT3;
    }
    }

复制代码
This post is from Microcontroller MCU

Comments

I tried it with 2553, but it said there was no license or something like that. What's going on?  Details Published on 2012-7-6 14:20

16

Posts

0

Resources
3
:) Very good, very cool, thank you OP!
This post is from Microcontroller MCU

96

Posts

0

Resources
4
Learn more
This post is from Microcontroller MCU

79

Posts

0

Resources
5
The OP is awesome~~~~ Keep posting good stuff~~~
This post is from Microcontroller MCU

Comments

Thank you for your support:kiss:  Details Published on 2012-6-19 14:35

7249

Posts

192

Resources
6
Thank you for your support:kiss:
This post is from Microcontroller MCU

8

Posts

0

Resources
7

Thank you so much to the OP, I have been struggling with this for a long time :Cry: , I strongly support the OP! ! ! ! ! ! !

This post is from Microcontroller MCU

Comments

This program can be implemented with MSPG2231, but the launchpad I sent now does not have MSPG2231. I have tried MSPG2542 and MSPG2253. This program does not work and needs to be modified slightly.  Details Published on 2012-6-20 08:19

7249

Posts

192

Resources
8
This program can be implemented with MSPG2231, but the launchpad I sent now does not have MSPG2231. I have tried MSPG2542 and MSPG2253. This program does not work and needs to be modified slightly.
This post is from Microcontroller MCU

Comments

How to modify it?  Details Published on 2012-7-3 19:19

9

Posts

0

Resources
9
Why doesn't it work? My chip is mspg2231. After I copied it completely, I pressed P3.1 once and LED0 went from bright to dark. But after that, no matter how I pressed the button, it didn't work and the light never came on.
This post is from Microcontroller MCU

Comments

I can do it here. I have tried two boards and they all work. I just tried G2231 and it works perfectly. But I have tried MSPG2542 and MSPG2253. It is very confusing to make small modifications.  Details Published on 2012-6-20 21:04
I can do it here. I have tried two boards and they all work. I just tried G2231 and it works perfectly. But I have tried MSPG2542 and MSPG2253. It is very confusing to make small modifications.  Details Published on 2012-6-20 21:02

7249

Posts

192

Resources
10
I can do it here. I have tried two boards and they all work. I just tried G2231 and it works perfectly. But I have tried MSPG2542 and MSPG2253. It is very confusing to make small modifications.
This post is from Microcontroller MCU

Comments

MSP430G2553 is totally OK, thanks to the host, but why do we need to turn on the pull-up resistor?  Details Published on 2013-8-27 09:36
MSP430G2553 is totally OK, thanks to the host, but why do we need to turn on the pull-up resistor?  Details Published on 2013-8-1 22:05

7249

Posts

192

Resources
11
It works here, but the delay time is a little short and a little jittery, but multiple key presses are definitely effective. There is no problem with the G2231 chip.
This post is from Microcontroller MCU

8

Posts

0

Resources
12
What if I have two interrupts? How do I choose after turning on the master interrupt? One is TIMER and the other is IO interrupt.
This post is from Microcontroller MCU

Comments

The interrupt flags of the two terminals are different  Details Published on 2012-7-3 16:13

7249

Posts

192

Resources
13
The interrupt flags of the two terminals are different
This post is from Microcontroller MCU

172

Posts

0

Resources
14
How to modify it?
This post is from Microcontroller MCU

Comments

Which chip do you have? I have tried 2553. I can increase the delay to eliminate jitter.  Details Published on 2012-7-4 16:06

7249

Posts

192

Resources
15
Which chip do you have? I have tried 2553. I can increase the delay to eliminate jitter.
This post is from Microcontroller MCU

2

Posts

0

Resources
16
:kiss: :hug:
This post is from Microcontroller MCU

10

Posts

0

Resources
17
I tried it with 2553, but it said there was no license or something like that. What's going on?
This post is from Microcontroller MCU

Comments

No license? Are you using the Harmony version? Is it Harmony OK? Can other programs be compiled?  Details Published on 2012-7-6 15:23

7249

Posts

192

Resources
18
No license? Are you using the Harmony version? Is it Harmony OK? Can other programs be compiled?
This post is from Microcontroller MCU

Comments

Uninstall, download and install again, and it works. I would like to ask again~ Is it necessary to write P1REN=BIT3 in the program? In what circumstances must this be written?  Details Published on 2012-7-11 20:05

10

Posts

0

Resources
19
Uninstall, download and install again, and it works. I would like to ask again~ Is it necessary to write P1REN=BIT3 in the program? In what circumstances must this be written?
This post is from Microcontroller MCU

Comments

P1REN is set to internal pull-up. Look at the diagram in the manual. 1 is set to internal pull-up. If the port is connected to a button and no external pull-up is used, the internal pull-up should be turned on. As for whether this sentence can be omitted, look at the schematic diagram of the launchpad.  Details Published on 2012-7-11 23:04

7249

Posts

192

Resources
20

P1REN is set up internally. See a picture in the manual.

If the port is connected to a button and no external pull-up is used, the internal pull-up should be turned on.

As for whether this sentence can be omitted

See the launchpad schematic

There is an external pull-up on the schematic

But there will be a difference in the actual product because the resistor R34 is installed externally. The launchpad I received was not soldered on. You can check if yours is soldered on.

If there is an external pull-up resistor, it can be omitted

I have 2 launchpads. One was purchased in a group. The one I purchased in a group had R34de, but the R34 that came with it was not soldered.

[ This post was last edited by Changjianze1 on 2012-7-11 23:07]
This post is from Microcontroller MCU

Comments

My board has been soldered~~Thank you for your careful explanation~:kiss:  Details Published on 2012-7-12 21:41

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list