Other Parts Discussed in Thread: MSP430F5529
Hello everyone,
I am doing ADC programming in msp430f5529. But I have some doubt in the Program which I pasted below.
Whenever an interrupt is generated the CPU comes out of the Low Power Mode 0 and jumps to the ISR, in ISR CPU is in active state so why we have use this instruction " __bic_SR_register_on_exit(LPM0_bits)"
as because the CPU is present in active state only.
#include <msp430.h>
//unsigned int value=0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
P6SEL |= 0x01; // P6.0 ADC option select
P1DIR |= 0x01; // P1.0 output
while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
// Vector 6: ADC12IFG0
int value=ADC12MEM0;
if (ADC12MEM0 >= 2048) // ADC12MEM = A0 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
}
#include <msp430.h>//unsigned int value=0;int main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop WDT ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on ADC12CTL1 = ADC12SHP; // Use sampling timer ADC12IE = 0x01; // Enable interrupt ADC12CTL0 |= ADC12ENC; P6SEL |= 0x01; // P6.0 ADC option select P1DIR |= 0x01; // P1.0 output
while (1) { ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit __no_operation(); // For debugger }
}
#pragma vector = ADC12_VECTOR__interrupt void ADC12_ISR(void){ // Vector 6: ADC12IFG0
int value=ADC12MEM0; if (ADC12MEM0 >= 2048) // ADC12MEM = A0 > 0.5AVcc? P1OUT |= BIT0; // P1.0 = 1 else P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
}