下面这段代码摘自某个程序,使用MSP430G2452实现电源电压检测部分。
其中ADC_Interrupt为宏定义,用于判断唤醒MCU的中断源确系ADC中断,说明ADC转换完成。
需要在ADC中断服务里将MCU从低功耗工作状态中唤醒。
- //测电压
- ADC10CTL1 = INCH_11;
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON+ ADC10IE;
- ADC10CTL0 |= ENC + ADC10SC;
- LPM3;
- if(ADC_Interrupt)
- {
- ADC_value = ADC10MEM;
- ADC10CTL0 &= ~ENC;
- if(ADC_value==0x3ff)
- {
- ADC10CTL0 &= ~ENC;
- ADC10CTL1 = INCH_11;
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + REF2_5V + ADC10IE;
- ADC10CTL0 |= ENC + ADC10SC;
- LPM3;
- if(ADC_Interrupt)
- {
- ADC_value = ADC10MEM;
- ADC10CTL0 &= ~ENC;
- Vcc=(ADC_value>>1)+(ADC_value<<1);
- }
- }
- else
- {
- ADC_value+=ADC_value>>1;
- Vcc=ADC_value;
- }
- }