Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. #include <msp430.h>
  2.  
  3. int ta1_dir;
  4. int ta0_dir;
  5.  
  6. int main(void)
  7. {
  8. ADC10CTL1 = INCH_0 + ADC10DIV_3; // temp sensor
  9. ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
  10. BCSCTL3 |= LFXT1S_2; // ACLK = VLO
  11. BCSCTL2 |= SELM_3 + SELS; //Turning on M clock and SM clock
  12. WDTCTL = WDT_ADLY_16; // WDT 16ms, ACLK, interval timer
  13. IE1 |= WDTIE; // Enable WDT interrupt
  14.  
  15. P2DIR |= BIT1 + BIT4; // Set P2.1 (B) and P2.4 (G) as output
  16. P2SEL |= BIT1 + BIT4; // Set P2.1 and P2.4 to use timer A1
  17. P2SEL2 &= ~(BIT1 + BIT4); // Set P2.1 and P2.4 to use timer A1
  18.  
  19. P1DIR |= BIT2; // Set P1.2 (R) as output
  20. P1SEL |= BIT2; // Set P1.2 to use timer A0
  21. P1SEL2 &= ~BIT2; // Set P1.2 to use timer A0
  22.  
  23. TA1CCR0 = 10; // Set timer A1 CCR0 register as counter ceiling
  24. TA1CCR1 = 0; // (Green) Set timer A1-1 to have a starting duty cycle of 100%
  25. TA1CCR2 = 0; // (BLUE) Set timer A1-2 to have a starting duty cycle of 100%
  26. TA1CTL |= MC_1 + TASSEL_1 + ID_1; // Set timer A1 to count up to CCR0 and use ACKL
  27. TA1CCTL1 |= OUTMOD_7; // Set timer A1-1 to use PWM reset/set mode (off at CCR1-1, on at CCR0)
  28. TA1CCTL2 |= OUTMOD_7; // Set timer A1-2 to use PWM reset/set mode (off at CCR1-2, on at CCR0)
  29.  
  30. TA0CCR0 |= 10; // Set timer A0 CCR0 register as counter ceiling
  31. TA0CCR1 |= 0; // (RED) Set timer A0 to have a starting duty cycle of 100%
  32. TA0CTL |= MC_1 + TASSEL_1 + ID_1; // Set timer A0 to count up to CCR0 and use ACKL
  33. TA0CCTL1 |= OUTMOD_7; // Set timer A0 to use PWM reset/set mode (off at CCR1, on at CCR0)
  34.  
  35.  
  36. while (1) {
  37. ADC10CTL0 |= ENC + ADC10SC;
  38. __bis_SR_register(CPUOFF + GIE);
  39.  
  40. long temp = ADC10MEM;
  41.  
  42. if (temp > 950) //Cold - all blue
  43. {
  44. TA1CCR1 = TA1CCR0;
  45. TA1CCR2 = 0;
  46. TA0CCR1 = TA0CCR0;
  47. }
  48. else if (temp < 750) //Hot - all red
  49. {
  50. TA1CCR1 = TA1CCR0;
  51. TA1CCR2 = TA1CCR0;
  52. TA0CCR1 = 0;
  53. }
  54.  
  55. else
  56. {
  57. if (temp < 950 && temp > 850)
  58. {
  59. TA0CCR1 = (int)((0.05*temp)-37.5); //red
  60. TA1CCR2 = (int)((-0.05*temp)+47.5); //blue
  61. TA1CCR1 = (int)((0.1*temp)-85)/2; //green
  62. }
  63. else if (temp < 850 && temp > 750)
  64. {
  65. TA0CCR1 = (int)((0.05*temp)-37.5); //red
  66. TA1CCR2 = (int)((-0.05*temp)+47.5); //blue
  67. TA1CCR1 = (int)((-0.1*temp)+85)/2; //green
  68. }
  69.  
  70. __bis_SR_register(LPM3_bits + GIE);
  71. }
  72. }
  73. }
  74.  
  75.  
  76. // Watchdog Timer interrupt service routine
  77. #pragma vector=WDT_VECTOR
  78. __interrupt void watchdog_timer(void)
  79. {
  80. __bic_SR_register_on_exit(LPM3_bits + GIE); // Clear LPM3 bits from SR after exiting
  81. }
  82.  
  83. // ADC10 interrupt service routine
  84. #pragma vector=ADC10_VECTOR
  85. __interrupt void ADC10_ISR(void)
  86. {
  87. __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement