MSP430 MCU IO Overview

Publisher:sky0001Latest update time:2016-08-02 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Overview of MSP430 MCU ports

        P1~P6 each group has 8 I/O ports, P3, P4, P5, P6 have I/O and other on-chip peripheral functions, each group has 4 registers. In addition to the above functions, P1 and P2 also have interrupt capabilities, each group has 7 registers.

2. Px port

1. P1, P2 ports

(1) PxDIR input/output direction register (x represents 1, 2)

        The eight independent bits define the input and output directions of the eight pins Px7~Px0.

        0 Input mode, read only.

        1 Output mode, readable and writable.

        All 8 bits are reset and set to 0 after PUC.

        Eg: P1DIR = 0x0F;

        Here, 0x0F is represented in hexadecimal, and the corresponding binary is 0000 1111, that is, the upper 4 bits of P1DIR are set to 0, and the lower 4 bits are set to 1, that is, P1.7, P1.6, P1.5, P1.4 (the upper 4 bits of P1) are set to input mode; and P1.3, P1.2, P1.1, P1.0 (the lower 4 bits of P1) are set to output mode.

(2) PxIN input register

        Each bit corresponds to an input port, such as: the second bit corresponds to Px.2, which records the data input to the corresponding bit, 0 or 1. The input register is a read-only register, and the user cannot write to it, but can only read data from it.

        For example:

        char a;

        a = P1IN;

        Assign the data input by P1 to a, or read one or several bits of it.

        eg: if((P1IN&0x01) == 1) a = b;

        This sentence means that if the lowest bit of P1IN is 1, that is, the input of P1.0 is 1, b will be assigned to a; the '&' means the bitwise AND operation, that is, the 8-bit data in P1IN and 0x01 are bitwise ANDed.

(3) PxOUT output register

        This register is the output buffer register of the I/O port. Each bit corresponds to an output port, such as: the second bit corresponds to Px.2. When the user writes data to the corresponding bit, the corresponding port will output the corresponding data.

        For example:

        P1OUT = 0x01;

        Set the lowest position of P1OUT to 1 and the other positions to 0, that is, P1.7, P1.6, P1.5, P1.4, P1.3, P1.2, and P1.1 output 0, and P1.0 outputs 1;

        P1OUT = BIT0;

        By consulting the header file of the MSP430 microcontroller, we can know that BIT0 is 0x01. This sentence is equivalent to the previous one. The reason for writing it this way is to make the program easier to understand and more concise.

(4) PxIFG interrupt flag register

        0 means no interrupt request

        1 indicates an interrupt request

        The interrupt flags PxIFG.0~PxIFG.7 share an interrupt vector and are multi-source interrupts. When a rising edge or falling edge appears on the corresponding I/O port, the corresponding flag bit will be set. If the interrupt is enabled and the system total interrupt is enabled, an interrupt will be generated and the interrupt handler will be executed.

        Note: 1. After PxIFG.0~PxIFG.7 are set, they will not be reset automatically. You must use software to determine which I/O has an interrupt event and reset the corresponding flag.

        2. The external interrupt event must be maintained for no less than 1.5 times the MCLK time to ensure that the interrupt request is accepted and the corresponding interrupt flag is set.

(5) PxIE interrupt enable register

        0 Disable interrupts

        1 Enable interrupts

        Only a transition can cause an interrupt request, while a static level cannot.

(6) PxIES interrupt trigger edge selection register

        0 A rising edge sets the corresponding flag

        1 Falling edge sets the corresponding flag

(7) PxSEL function selection register

        0 Select pin as I/O function

        1 Select pin as peripheral module function

        There are also abundant peripheral modules in the microcontroller, which usually need to communicate with the outside world. However, the microcontroller has limited pins, so the method of multiplexing P1 and P2 pins is used to achieve this.

        For example:

        P5SEL |= 0x10; // P5.4 is used as MCLK output

2. Ports P3, P4, P5, P6

(1) Ports P3, P4, P5, and P6 have the same functions as P1 and P2 except that they do not have interrupt capability, including input/output functions and peripheral module functions.

(2) Since ports P3, P4, P5, and P6 do not have interrupt capabilities, they do not have interrupt-related registers. Each port group has four registers: PxDIR input/output direction register, PxIN input register, PxOUT input register, and PxSEL function selection register.

3. Port COM and S

        Used to realize direct interface with LCD, only MSP430F4XX series of microcontrollers have it.

———————————————————————————————————————

#include "msp430x26x.h"

void main( void )

{

    // Stop watchdog timer to prevent time out reset

    WDTCTL = WDTPW + WDTHOLD; //Stop the watchdog, WDTPW is the watchdog write command, WDTHOLD is the watchdog stop bit.

    P1DIR = 0x0f; //PxDIR direction register, 0 is input mode, 1 is output mode.

    //After all PUCs are reset. When used as input, it can only be read; when used as output, it can be read and written.

    P1OUT = 0xff;

    P1IE |= 0xf0; // P1.4, 5, 6, 7 interrupt enable (0 disables interrupt, 1 enables interrupt)

    P1IES |= 0xf0; // P1.4, 5, 6 IO port edge interrupt trigger mode, lower edge is valid (0 rising edge is valid, 1 falling edge is valid)

    P1IFG &= 0x00; // P1.4, 5, 6 clear IO interrupt flag

    P2DIR |= BIT3+BIT4;

    P2OUT = 0xff;

    P2IE |= BIT0+BIT1;

    P2IES |= 0x00;

    P2IFG &= 0x00;

    _EINT(); //Enable general interrupt

    LPM4; // (LOW POWER MODE) Enter low power mode 4, at this time the microcontroller power consumption is the lowest

}

//************************************************ ***************

//P1 port interrupt service routine

#pragma vector=PORT1_VECTOR

__interrupt void p1int(void)

{

    if((P1IFG&0xf0)==0x10) P1OUT=0xf1;

    else if((P1IFG&0xf0)==0x20) P1OUT=0xf2;

    else if((P1IFG&0xf0)==0x40) P1OUT=0xf4;

    else if((P1IFG&0xf0)==0x80) P1OUT=0xf8;

    P1IFG &= 0x00;

}

#pragma vector=PORT2_VECTOR

__interrupt void p2_port(void)

{

    if((P2IFG&0x0f)==0x01) P2OUT=0x04;

    else if((P2IFG&0x0f)==0x02) P2OUT=0x08;

    P2IFG &= 0x00;

}

Keywords:MSP430 Reference address:MSP430 MCU IO Overview

Previous article:A comprehensive look at the MSP430 MCU timer
Next article:Keil Memory Model Selection Problem

Recommended ReadingLatest update time:2024-11-16 23:57

Liyuan Information: SiC/IGBT and other products have the most limited production capacity, and the company's self-developed MCU chips are mass-produced
 On January 26, Liyuan Information said in a conference call that the most tense products at present include SiC, IGBT, MOS tubes, various automotive chips, Image Sensors and other products, mainly due to insufficient production capacity and strong demand. It believes that this phenomenon is closely related to the upg
[Mobile phone portable]
Detailed explanation of crystal oscillator connection for PIC microcontroller
PIC microcontroller has 4 oscillation modes: Blocked Ad The specific meaning of the translation is up to you to figure out. Here are the meanings of two words to help you understand: Crystal: Crystal Oscillator: Oscillator Crystal Oscillator: Crystal oscillator, referred to a
[Microcontroller]
New LPC Microcontroller Simplifies Motor Control
NXP Semiconductors (NASDAQ: NXPI) recently announced the launch of the LPC1500 microcontroller family, which is optimized for fast, easy and high-precision motor control. The new microcontroller integrates all the functions required for high-precision sensored and sensorless motor control, and can control two motors s
[Power Management]
Tip 2 -- Summary of MCU C51 & A51 Programming Key Points
C51: 1. Header file: #include reg52.h (I use STC 89C54RD+) 2. Predefined: sbit LED = P1^0 // Define bit 0 of port P1 as LED    Note: The writing of "P1^0" is different from A51 (A51 is P1.0). P1 is a group of ports, and the port number range is 0~7.    Note 2: sbit is used to define the bit variable of SFR (Spec
[Microcontroller]
C51 MCU Study Notes - IO Expansion (Serial to Parallel) Experiment - 74HC595
Purpose: To control the LED matrix to display in a row loop through the 74HC595 module. Compiler software: keil5 process: (1) First define the 74HC595 control pins and the dot array control port //Define 74HC595 control pins sbit SRCLK=P3^6; //Shift register clock input sbit RCLK=P3^5; //Storage register clock
[Microcontroller]
C51 MCU Study Notes - IO Expansion (Serial to Parallel) Experiment - 74HC595
Motorcycle electronic ignition solution based on Renesas MCU
    The motorcycle electronic igniter has the characteristics of sufficient high-voltage reserve, large ignition energy, high reliability, and no mechanical wear. NEC Electronics' 78K0/Kx1+ series microcontrollers have built-in oscillators, built-in watchdogs, and use built-in oscillators as frequency, making the entir
[Microcontroller]
Motorcycle electronic ignition solution based on Renesas MCU
MCU infrared communication (infrared encoding transmission and infrared receiving decoding code)
Regarding infrared communication, there are many MCU codes and videos about decoding on the Internet, but the transmission coding part is not easy to find. It took a lot of time to write the transmission code, so I would like to share it with you. The following is the information I found on the Internet: I. Character
[Microcontroller]
MCU infrared communication (infrared encoding transmission and infrared receiving decoding code)
51 MCU external interrupt trigger mode
There are two triggering modes for the external interrupt of the 51 MCU: level triggering and edge triggering. When the level triggering is selected, the MCU checks the interrupt source line in each machine cycle, and when it detects a low level, it sets the interrupt request flag and requests an interrupt from the CPU
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号