Created
October 15, 2011 13:54
-
-
Save ss23/1289596 to your computer and use it in GitHub Desktop.
Launchpad Fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*********************************************************** | |
// Lab5.c Temperature sampling example using ADC10 | |
// Clocking: MCLK and SMCLK = 1.1MHz DCO/8 | |
// ACLK = 12kHz VLO | |
// | |
// SFB 9/2010 | |
//*********************************************************** | |
#include <msp430g2231.h> | |
volatile long tempRaw; | |
void FaultRoutine(void); | |
void ConfigWDT(void); | |
void ConfigClocks(void); | |
void ConfigPins(void); | |
void ConfigADC10(void); | |
void ConfigTimerA2(void); | |
void main(void) { | |
ConfigWDT(); | |
ConfigClocks(); | |
ConfigPins(); | |
ConfigADC10(); | |
ConfigTimerA2(); | |
while(1) { | |
_bis_SR_register(LPM3_bits + GIE); // Enter LPM3 with interrupt | |
} | |
} | |
void ConfigWDT(void) { | |
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer | |
} | |
void ConfigClocks(void) { | |
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) | |
FaultRoutine(); // If calibration data is erased | |
// run FaultRoutine() | |
BCSCTL1 = CALBC1_1MHZ; // Set range | |
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation | |
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO | |
IFG1 &= ~OFIFG; // Clear OSCFault flag | |
BCSCTL2 = 0; | |
} | |
void FaultRoutine(void) { | |
P1OUT = BIT0; // P1.0 on (red LED) | |
while(1); // TRAP | |
} | |
void ConfigPins(void) { | |
P1DIR = ~BIT3; // P1.3 input, others output | |
P1OUT = 0; // Clear output pins | |
P2SEL = ~(BIT6 + BIT7); // P2.6 and 7 GPIO | |
P2DIR |= BIT6 + BIT7; // P2.6 and 7 Outputs | |
P2OUT = 0; // Clear outputs on P2 | |
} | |
void ConfigADC10(void) { | |
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK | |
} | |
void ConfigTimerA2(void) { | |
CCTL1 = CCIE + OUTMOD_3; // CCR1 int. enabled set/reset mode | |
CCR1 = 36000; // three seconds | |
CCTL0 = CCIE; // CCR0 int. enabled | |
CCR0 = 36100; // three seconds + settling time | |
TACTL = TASSEL_1 + MC_1; // ACLK, up mod | |
} | |
// Timer_A2 CCR0 interrupt service routine | |
#pragma vector=TIMERA0_VECTOR | |
__interrupt void Timer_A0 (void) { | |
//CCTL0 &= ~CCIFG; // Clear CCR0 int flag (Not needed, but helpful for other chips) | |
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start | |
P1OUT |= BIT6; // P1.6 on (green LED) | |
_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit | |
} | |
// Timer_A2 CCR1 interrupt service routine | |
#pragma vector=TIMERA1_VECTOR | |
__interrupt void Timer_A1 (void) { | |
//CCTL1 &= ~CCIFG; // Clear CCR1 int flag (Not needed, but helpful for other chips) | |
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE; | |
_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit | |
} | |
// ADC10 interrupt service routine | |
#pragma vector=ADC10_VECTOR | |
__interrupt void ADC10 (void) { | |
//ADC10CTL0 &= ~ADC10IFG; // Clear interrupt flag | |
ADC10CTL0 &= ~ENC; // Disable ADC conversion | |
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off | |
tempRaw = ADC10MEM; // Read conversion value | |
P1OUT &= ~BIT6; // green LED off | |
//CCR0 += 36000; // Add one second to CCR0 | |
_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment