msp430x54x_mpy_13.c

来自「MSP430的开发程序的例子+中文注释」· C语言 代码 · 共 53 行

C
53
字号
//******************************************************************************
//   msp430FG5438 Demo - Saturation mode overflow test
//
//   Description: The example illustrates a special case showing overflow.
//   The addition result of 2 positive numbers may exceed the highest positive 
//   number (0x7FFF FFFF for 32 bit result) due to overflow indicaing a negative
//   result. By having the saturation mode enabled, this result can be truncated 
//   off to this highest positive number. Results with and without saturation mode 
//   are shown. 
//
//   ACLK = 32.768kHz, MCLK = SMCLK = default DCO
//
//                msp430FG5438
//             -----------------
//         /|\|                 |
//          | |                 |
//          --|RST              |
//            |                 |
//            |                 |
//
//   M Smertneck
//   Texas Instruments Inc.
//   April 2008
//   Built with CCEv3.2 IAR Embedded Workbench Version: 3.42A
//******************************************************************************

#include <msp430x54x.h>

unsigned int Result_lower16;
unsigned int Result_upper16;

void main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT
  
  MPY32CTL0 = MPYSAT;                       // Enable saturation mode
  
  RES3 = 0;
  RES2 = 0;
//------32-bit Result of a multiply operation (not shown) in RES0 and RES1------
  RES1 = 0x7FFF;                            // Pre-load result registers   
  RES0 = 0xFFFD;
 
  MACS = 0x05;                              // Add 5 to previous result
  OP2 = 0x01;                            
  
  Result_upper16 = RESHI;                   // Result_upper15 = 0x7FFF
  Result_lower16 = RESLO;                   // Result_lower15 = 0xFFFF
  
  MPY32CTL0 &= ~MPYSAT;                     // Clear saturation mode
  _BIS_SR(LPM4_bits);                       // LPM4
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?