Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430.h>
- int ta1_dir;
- int ta0_dir;
- int main(void)
- {
- ADC10CTL1 = INCH_0 + ADC10DIV_3; // temp sensor
- ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
- BCSCTL3 |= LFXT1S_2; // ACLK = VLO
- BCSCTL2 |= SELM_3 + SELS; //Turning on M clock and SM clock
- WDTCTL = WDT_ADLY_16; // WDT 16ms, ACLK, interval timer
- IE1 |= WDTIE; // Enable WDT interrupt
- P2DIR |= BIT1 + BIT4; // Set P2.1 (B) and P2.4 (G) as output
- P2SEL |= BIT1 + BIT4; // Set P2.1 and P2.4 to use timer A1
- P2SEL2 &= ~(BIT1 + BIT4); // Set P2.1 and P2.4 to use timer A1
- P1DIR |= BIT2; // Set P1.2 (R) as output
- P1SEL |= BIT2; // Set P1.2 to use timer A0
- P1SEL2 &= ~BIT2; // Set P1.2 to use timer A0
- TA1CCR0 = 10; // Set timer A1 CCR0 register as counter ceiling
- TA1CCR1 = 0; // (Green) Set timer A1-1 to have a starting duty cycle of 100%
- TA1CCR2 = 0; // (BLUE) Set timer A1-2 to have a starting duty cycle of 100%
- TA1CTL |= MC_1 + TASSEL_1 + ID_1; // Set timer A1 to count up to CCR0 and use ACKL
- TA1CCTL1 |= OUTMOD_7; // Set timer A1-1 to use PWM reset/set mode (off at CCR1-1, on at CCR0)
- TA1CCTL2 |= OUTMOD_7; // Set timer A1-2 to use PWM reset/set mode (off at CCR1-2, on at CCR0)
- TA0CCR0 |= 10; // Set timer A0 CCR0 register as counter ceiling
- TA0CCR1 |= 0; // (RED) Set timer A0 to have a starting duty cycle of 100%
- TA0CTL |= MC_1 + TASSEL_1 + ID_1; // Set timer A0 to count up to CCR0 and use ACKL
- TA0CCTL1 |= OUTMOD_7; // Set timer A0 to use PWM reset/set mode (off at CCR1, on at CCR0)
- while (1) {
- ADC10CTL0 |= ENC + ADC10SC;
- __bis_SR_register(CPUOFF + GIE);
- long temp = ADC10MEM;
- if (temp > 950) //Cold - all blue
- {
- TA1CCR1 = TA1CCR0;
- TA1CCR2 = 0;
- TA0CCR1 = TA0CCR0;
- }
- else if (temp < 750) //Hot - all red
- {
- TA1CCR1 = TA1CCR0;
- TA1CCR2 = TA1CCR0;
- TA0CCR1 = 0;
- }
- else
- {
- if (temp < 950 && temp > 850)
- {
- TA0CCR1 = (int)((0.05*temp)-37.5); //red
- TA1CCR2 = (int)((-0.05*temp)+47.5); //blue
- TA1CCR1 = (int)((0.1*temp)-85)/2; //green
- }
- else if (temp < 850 && temp > 750)
- {
- TA0CCR1 = (int)((0.05*temp)-37.5); //red
- TA1CCR2 = (int)((-0.05*temp)+47.5); //blue
- TA1CCR1 = (int)((-0.1*temp)+85)/2; //green
- }
- __bis_SR_register(LPM3_bits + GIE);
- }
- }
- }
- // Watchdog Timer interrupt service routine
- #pragma vector=WDT_VECTOR
- __interrupt void watchdog_timer(void)
- {
- __bic_SR_register_on_exit(LPM3_bits + GIE); // Clear LPM3 bits from SR after exiting
- }
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement