MSP430G2553 beginner design experience sharing
[Copy link]
The MSP430g2553 is a 16-bit MCU with a supply voltage as low as 1.8V. It includes the peripherals shown in the figure below and has a variety of low-power modes for developers to use flexibly.
MSP430G2553, I personally think: low power consumption is its biggest highlight. It is very deliberate. Therefore, the interrupt/low power mode is very charming and attractive in the application of 430!
msp430g2553 example, msp430g2553 beginner design experience sharing
The MSP430G2x13 and MSP430G2x53 families are ultra-low-power mixed-signal microcontrollers with built-in 16-bit timers, up to 24 I/O pins with touch sensing support, a multi-purpose analog comparator, and built-in communication capabilities using a universal serial communication interface.
MSP430G2553 is widely used. Here, let's take a look at the interrupt situation.
#include《msp430g2553.h》
#include "in430.h"
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Disable watchdog counting
P1DIR=BIT0+BIT1; //P1.0\1 is set as output, P1.4/5 is input
P1OUT=BIT0+BIT1+BIT4+BIT5; //P1.0\1 is high, P.4/5 is pulled up
P1REN=BIT4+BIT5; //P1.4 pull-up enable
P1IE=BIT4+BIT5; //P1.4 turns on interrupt
P1IES=BIT4+BIT5; //interrupt edge selection
__enable_interrupt(); //enable interrupt
while(1); //nothing to do
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1() //P1 port interrupt service routine
{
unsigned int i=0;
unsigned char PushKey=0;
PushKey=P1IFG&(BIT4+BIT5); //Read which key is pressed
for (i = 0; i < 65535; i++); // make a judgment after delay to avoid jitter
if (!(P1IN&PushKey)) //Not pressed, then it is shaking, the flag is cleared
P1IFG=0;
if ((P1IN&PushKey)) // Determine if a key is pressed
{
for (i=0;i<65535;i++);
if ((P1IN & PushKey))
{
if ((PushKey & BIT4))
P1OUT^=BIT0;
if ((PushKey & BIT5))
P1OUT^=BIT1;
}
P1IFG&=~(BIT4+BIT5);
}
}
The most outstanding part of this program is the waiting statement “while (1);”.
Before the interrupt occurs, the program stops here and waits, which is equivalent to the CPU stopping here and doing nothing, perhaps waiting for Godot. Once the interrupt condition occurs, here it is a key press, it will enter the interrupt as if it has caught something and execute the code in the interrupt program.
Here, we can see that before the interrupt comes, the CPU is doing nothing, but it is not shut down and is still consuming power. After the interrupt comes, it rushes to process the interrupt program. Back and forth, it is always tossing and turning. It must be very tired.
msp430g2553 routines, msp430g2553 beginner design experience sharing
|