//平台:msp430launchpad仿真, IAR V5.50.2, MCU:msp430g2231
//说明:使用VLO作为CPU、ADC的时钟源 并关闭其它时钟,使用ADC10,引脚连接如下
// Vin –> P1.0–> A/D P1.6–> LED
#include "msp430g2452.h"
main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0XFF;
P2DIR = 0XFF;
//开VLO,关其它时钟
BCSCTL3 = LFXT1S_2; //低高频选OLV,并作为ACLK时钟源
BCSCTL2 = SELM_3 + DIVM_0; //MCLK时钟源选VLO(或LFXT1),MCLK不分频
IFG1 &= ~OFIFG; //清时钟失效中断标志
_BIS_SR(SCG0 + SCG1 + OSCOFF); //关DCO、SMCLK、LFXT1等
//ADC10初始化
ADC10AE0 = BIT0; //P1.0为ADC输入端
ADC10CTL0 = ADC10SR + ADC10ON + ADC10IE; //启动ADC,开中断
ADC10CTL1 = INCH_0 + ADC10SSEL_1 + CONSEQ_0; //ADC时钟为ACLK, 单通道单次模式
for(;;)
{
ADC10CTL0 |= ENC + ADC10SC; //开始A/D
_BIS_SR( GIE ); //开全局中断
_BIS_SR( CPUOFF ); //关CPU
asm("nop");
if(ADC10MEM > 500)
{
P1OUT = BIT6;
}
else
{
P1OUT &= ~BIT6;
}
}
}
//****************************************************************
//ADC10中断
#pragma vector = ADC10_VECTOR
__interrupt void ADC10INT()
{
_BIC_SR_IRQ( CPUOFF ); //清CPUOFF
}
//以上程序执行后就停在asm("nop");这里,无法往下执行,中断能正常工作,中断返回后怎样CPUOFF还是“1”呢? 能只手工单步才能往下执行, 如果把_BIS_SR( CPUOFF ); 去掉就能正常工作了。
Maka Luo:
/* Low Power Modes coded with Bits 4-7 in SR */
#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define LPM0 (CPUOFF)#define LPM1 (SCG0+CPUOFF)#define LPM2 (SCG1+CPUOFF)#define LPM3 (SCG1+SCG0+CPUOFF)#define LPM4 (SCG1+SCG0+OSCOFF+CPUOFF)/* End #defines for assembler */
#else /* Begin #defines for C */#define LPM0_bits (CPUOFF)#define LPM1_bits (SCG0+CPUOFF)#define LPM2_bits (SCG1+CPUOFF)#define LPM3_bits (SCG1+SCG0+CPUOFF)#define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
#include "in430.h"
#define LPM0 _bis_SR_register(LPM0_bits) /* Enter Low Power Mode 0 */#define LPM0_EXIT _bic_SR_register_on_exit(LPM0_bits) /* Exit Low Power Mode 0 */#define LPM1 _bis_SR_register(LPM1_bits) /* Enter Low Power Mode 1 */#define LPM1_EXIT _bic_SR_register_on_exit(LPM1_bits) /* Exit Low Power Mode 1 */#define LPM2 _bis_SR_register(LPM2_bits) /* Enter Low Power Mode 2 */#define LPM2_EXIT _bic_SR_register_on_exit(LPM2_bits) /* Exit Low Power Mode 2 */#define LPM3 _bis_SR_register(LPM3_bits) /* Enter Low Power Mode 3 */#define LPM3_EXIT _bic_SR_register_on_exit(LPM3_bits) /* Exit Low Power Mode 3 */#define LPM4 _bis_SR_register(LPM4_bits) /* Enter Low Power Mode 4 */#define LPM4_EXIT _bic_SR_register_on_exit(LPM4_bits) /* Exit Low Power Mode 4 */#endif /* End #defines for C */
参见msp430g2231.h文件,退出LPM0 写法。
user1223687:
回复 Maka Luo:
不是LPM0, 我现在是要退出LPM4(系统时钟源VLO下)。
user1223687:
回复 Hardy Hu:
谢谢!
我的程序中有 _BIS_SR(SCG0 + SCG1 + OSCOFF); 和 _BIS_SR(CPUOFF); 即等于 LPM4 ,所以问题应该是所有的时钟源都被关掉了,没有时钟源,CPU也就停止。