MSP430 Learning notes-io and low power consumption

Source: Internet
Author: User

Reference: Http://bbs.ednchina.com/BLOG_ARTICLE_3013511.HTM

The msp430f149 has 6 8-bit IO ports, of which P1,P2 share population two interrupt vectors, which can be connected to 16 interrupt sources. can also directly use the input and output registers of the P port, direct external communication. Because all IO ports are multiplexed with other peripherals, it is necessary to use the function selection register in front of the port to select whether the function is peripheral or P port, and whether the input or output is determined in the direction register

msp430f149 Port function

Port Function
P1,p2 I/O, interrupt function, other on-chip peripheral functions
P3,p4,p5,p6 I/O, other on-chip peripheral functions

Register:

Pxdir Direction Register: 0 is input, read only, 1 is output

Pxin Input Register: can read only its IO content

Pxout Output Registers: output buffers for IO ports,

Pxsel Feature Selection Register: 0 for I/O function, 1 for peripheral module function

Interrupt function registers such as interrupt when in detail.

Example: P1dir = 0xFF; Set all p1.x ports to output

p1out = 0; P1. X Port output 0, reset

unsigned char Temp

P6dir = 0x00; Set all p6.x ports as input

temp = p6in;//assigns the value of p6.x to Temp

P6. X's 8-bit IO port simultaneously multiplexing the input of the 8-bit ADC (IO ports do on-chip peripherals are also directional, such as P1.1 timer A is the input, comparator is output, first determine the direction of the correct use, the direction of determination see data Sheet)

P6dir = 0x00;

P6sel = 0xFF;

The msp430f149 has 5 operating modes, including 4 low-power modes, such as:

The low power mode is different, the working part of the shutdown is also different, such as LMP3, CPU,MCLK,SMCLK all stop working, the DC generator is also closed, only ACLK is still active.

The SCG1, SCG2, Oscoff , and Cpuoff bits in the in-CPU status register SR are important low-power control bits. As long as an arbitrary interrupt is responded to, the above control bit is pressed onto the stack to be saved, and after the interrupt is processed, the previous mode of operation can be resumed. During interrupt processing subroutine execution, these bits can be manipulated by indirectly accessing the stack data, allowing the program to continue running in another power mode after an interrupt return (RETI). Each control bit functions as follows:

SCG1: When the SCG1 is reset, the Enable SMCLK;SCG1 set prevents the SMCLK from being placed.

SCG0: When the SCG0 is reset, the DC generator is activated, only the SCG0 is set and the DCOCLK signal is not used for MCLK or SMCLK, the DC generator can be banned.

Oscoff: When Oscoff is reset, the LFXT crystal oscillator is activated and MCLK crystal oscillator can only be banned if the Oscoff is set and not used for SMCLK or LFXT.

Cpuoff: When Cpuoff is reset, the clock signal used for the CPU MCLK is activated, and MCLK stops when the Cpuoff is placed.

The control bits SCG1, SCG2, Oscoff , and Cpuoff can be configured in 6 different operating modes: 1 active modes and 5 low power modes. As shown in the following table:

Working mode

Control bits

CPU status, oscillator and clock

Active mode
(AM)

Scg1=0
Scg0=0
Oscoff=0
Cpuoff=0
CPU is active
MCLK Activities
SMCLK Activities
ACLK Activities
Low Power mode 0
(LPM0)
Scg1=0
Scg0=0
Oscoff=0
Cpuoff=1
CPU is in a forbidden state
MCLK is forbidden
SMCLK Activities
ACLK Activities
Low Power Mode 1
(LPM1)
Scg1=0
Scg0=1
Oscoff=0
Cpuoff=1
CPU is in a forbidden state
If DCO is not used as a mclk or Smckl, the DC generator is banned or remains active
MCLK is forbidden
SMCLK Activities
ACLK Activities
Low Power Mode 2
(LPM2)
Scg1=1
Scg0=0
Oscoff=0
Cpuoff=1
CPU is in a forbidden state
If DCO is not used as a mclk or Smckl, it is automatically banned
MCLK is forbidden
SMCLK is forbidden
ACLK Activities
Low Power Mode 3
(LPM3)
Scg1=1
Scg0=1
Oscoff=0
Cpuoff=1
CPU is in a forbidden state
DCO is banned and DC generators are banned
MCLK is forbidden
SMCLK is forbidden
ACLK Activities
Low Power Mode 4
(LPM4)
Scg1=x
Scg0=x
Oscoff=1
Cpuoff=1

CPU is in a forbidden state
DCO is banned and DC generators are banned
All oscillators stop working
MCLK is forbidden
SMCLK is forbidden
ACLK is forbidden

Routines:

#include

  void main (void) {    BCSCTL1 |= diva_2                 &NBSP ;      //ACLK/4, 4 frequency    wdtctl = wdt_adly_1000;      //WDT 1s*4 interval timer    IE1 |= wdtie;                                //open-door dog interrupt Enable & nbsp;     while (1)   {    UINT i;     _BIS_SR (lpm3_bits + GIE);   & nbsp          //Enter LPM3 and enable (global) masking interrupt      p3out &= ~bit5;                          // p3.5 LED Lighting      for (i = 18000; i>0; i--);              //delay      p3out |= BIT5;                        // p3.5 led off  }}  #pr Agma VECTOR=WDT_VECTOR&Nbsp;__interrupt void Watchdog_timer (void) {    _BIC_SR_IRQ (lpm3_bits);           &NBSP ;    //Exit lmp3} 

Open Door Dog timer 4s (4 frequency, t=1s*4), enter lmp3,cpu,mclk,smclk into sleep state, other instructions can not be executed, open Door Dog module is in the auxiliary system clock ACLK driver (430 internal each function module and CPU is independent of each other, As long as the clock of this module is set up to work independently of the CPU), continue to work count to overflow (4s) A watchdog interrupt occurs and the exit Lpm3,cpu is awakened. After exiting the interruption, from P3out &= ~bit5; Start execution, LED lights flashing and then into the LMP3, has been circulating.

At the same time, using the Eigen function of MSP430, the upper program can be written as:

while (1) {UINT I;                         _eint ();                             Turn on global interrupt LMP3;                          Enter LMP3 p3out &= ~bit5;               P3.5 LED light on for (i = 18000; i>0; i--);                         Delay P3out |= BIT5;                 P3.5 LED light Off}} #pragma vector=wdt_vector __interrupt void Watchdog_timer (void) {lmp3_exit; Exit LMP3}

MSP430 Learning notes-io and low power consumption

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.