Question: HELP Write a program in C for MSP430: At the beginning the switch (P2.3) is turned off, and in low poer mode (LMP3); when the
HELP
Write a program in C for MSP430:
At the beginning the switch (P2.3) is turned off, and in low poer mode (LMP3); when the switchis turned on you leave low power mode (using Port I/O interrupt)
Using a timer every second the program does an A/D conversion (temperature). every 5 seconds the average temperature is calculated in F, and the temperature is displayed on the 7 segment display.
int main(void)
{
//Port Initializations
//Port Interrupt for switch at P1.X
//Set edge transition pattern
//Reset port interrupt flags
//Initial setting for the Timer
//Enable interrupt system
//Enter low power mode
}
void ConfigureAdc(void) { ADC10CTL1 = CONSEQ_0 + INCH_0; ADC10CTL0 = ADC10SHT_3 + MSC + ADC10ON;
while (ADC10CTL1 & BUSY); ADC10DTC1 = 5; ADC10AE0 |= BIT0; }
Port I/O ISR (assume that a pin in port 1 is used):
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
//Leave low power mode
//Enable WDT for 7-seg display
//Timer_A for timing of A/D conversions; 1 second intervals
//A/D Conversion setup
//reset Port I/O interrupt flags
}
In Timer A interrupt:
#pragma vector = TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
switch(TAIV)
{
case 0x02: break;
case 0x04: break;
case 0x0A:
//if the input switch is on, do
{
//Get an A/D sample,
//If 5 samples are collected, take an average and display it. //Else keep looping for more samples
}
break;
}
}
void getanalogvalues() { for (i=0;i<5;i++) { ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY); //Wait while ADC is busy ADC10SA = (unsigned)&ADCReading; //RAM Address of ADC Data, must be reset every conversion ADC10CTL0 |= (ENC | ADC10SC); //Start ADC Conversion while (ADC10CTL1 & BUSY); temp += ADCReading; __delay_cycles(00010); } temp= temp/5; // Average the 5 reading for the variable }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
