From 9c47fe195e767136eb16ccd12a6a1d93a6ececf1 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Thu, 17 Nov 2016 05:39:21 -0500
Subject: [PATCH] As done of a program as I can figure out how to do, at the
 current time.

I just don't understand how interupts work. Why does this magically break as soon as I attempt to interupt?
Only way to fix it seems to be to reset.
---
 a8.c | 56 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/a8.c b/a8.c
index c6df2fd..c0ad6d2 100644
--- a/a8.c
+++ b/a8.c
@@ -1,38 +1,58 @@
 #include <msp430.h>
 
+char colorChange = 'r';
+
 int main(void)
 {
     WDTCTL  = WDTPW | WDTHOLD;              // Watchdog timer setup.
     BCSCTL1 = CALBC1_1MHZ;                  // Set cpu clock thingy.
     DCOCTL  = CALDCO_1MHZ;                  // More of above.
 
-    P1DIR = BIT6;                           // BIT6 alternate output
+    P1DIR = BIT6;                           // Set P2.6 for output.
     P1SEL = BIT6|BIT4;                      // BIT4 analog input (channel 4)
+    P2DIR = BIT1|BIT5;                      // Set P2.1 and 2.2 for output.
+
+    // Set interupts.
+    P1REN = BIT3;                           // Sets pullup state. Helps make button pushing be more consistent.
+    P1OUT |= BIT3;                          // Sets default output state to 1.
+    P1IE |= BIT3;                           // Allows interupts on 1.3 pin at all?
+    P1IES |= BIT3;                          // Sets interupt type for 1.3 pin?
+    P1IFG &= ~BIT3;                         // Enable interupts on 1.3
 
-    TA0CTL   = TASSEL_2 | MC_1 | ID_3;      // use TA0.1 for PWM on P1.6
+    TA0CTL   = TASSEL_2 | MC_1 | ID_3;      // Timer 1 controller.
     TA0CCR0  = 0x3FF;                       // 10-bit maximum value
     TA0CCR1  = 0;                           // start off
     TA0CCTL1 = OUTMOD_7;                    // reset/set output mode
 
-    ADC10CTL1 = INCH_4 | ADC10DIV_3;        // ADC10 channel 4, clock divider 3
-    ADC10CTL0 = SREF_0 | ADC10SHT_3 |       // VCC/VSS ref, 64 x ADC10CLKs
-               ADC10ON | ADC10IE;           // ADC10 enable, ADC10 interrupt enable
-    ADC10AE0  = BIT4;                       // analog enable channel 4
+    TA1CTL   = TASSEL_2 | MC_1 | ID_3;      // Timer 2 controller.
+    TA1CCR0  = 0x3FF;                       // 10-bit maximum value
+    TA1CCR1  = 0;                           // start off
+    TA1CCTL1 = OUTMOD_7;                    // reset/set output mode
 
-    // __enable_interrupt();                // interrupts enabled
+    ADC10CTL1 = INCH_4 | ADC10DIV_3;        // ??ADC10 channel 4, clock divider 3
+    ADC10CTL0 = SREF_0 | ADC10SHT_3 |       // ??VCC/VSS ref, 64 x ADC10CLKs
+               ADC10ON | ADC10IE;           // ??ADC10 enable, ADC10 interrupt enable
+    ADC10AE0  = BIT4;                       // ??analog enable channel 4
+
+    //__enable_interrupt();                // interrupts enabled
     while(1)
     {
         __delay_cycles(10000);              // wait for ADC ref to settle
-        ADC10CTL0 |= ENC + ADC10SC;         // sampling and conversion start
+        ADC10CTL0 |= ENC + ADC10SC;         // Sample from resistor knob thing.
         // Turns cpu register off and waits for interupts.
+        //__BIS_SR(LMP4_bits | GIE);
         __bis_SR_register(CPUOFF | GIE);    // go to sleep with interrupts enabled
 
 
-        // Can change this line to do the color interupt routines (regarding a8)? Everything else can mostly stay the same??
-        // Set a variable which determines what color to change. Then if, to select other statements similar to this one?
         // ADC10MEM is a 10 bit number. &-ing with 0x3F8 somehow just throws away the bottom 3 bits?
-            // As they might vary too much to provide useful data, or something.
-        TA0CCR1 = ADC10MEM & 0x3F8;         // assigns the value held in ADC10MEM to the TA0CCR1 register
+        if (colorChange = 'r') {
+            TA0CCR1 = ADC10MEM & 0x3F8;     // ADC10MEM is probably a value set from sampling, a few lines above?
+                                            // This will assign that value to the TA0CCR1 register, which corresponds to red?
+        } else if (colorChange == 'g') {
+            TA1CCR1 = ADC10MEM & 0x3F8;     // assigns the value held in ADC10MEM to the TA0CCR1 register
+        } else {
+            //TA0CCR1 = ADC10MEM & 0x3F8;     // assigns the value held in ADC10MEM to the TA0CCR1 register
+        }
     }
 
     return 0;
@@ -42,7 +62,19 @@ int main(void)
 #pragma vector=ADC10_VECTOR
 __interrupt void ADC10_ISR (void)
 {
+
     // Turns cpu register back on.
     __bic_SR_register_on_exit(CPUOFF);      // wake up
+
+    // If red, change to green. If green, change to blue. If blue, change to red.
+    if (colorChange == 'r') {
+        colorChange = 'g';
+    } else if (colorChange == 'g') {
+        colorChange = 'b';
+    } else {
+        colorChange = 'r';
+    }
+    P1IFG &= ~BIT3;                         // Enable interupts on 1.3
+
 }
 
-- 
GitLab