#include // Deklaration Variablen typedef unsigned char byte; float calculate; float result[4] = {0}; byte chan = 0; // Deklaration Funktionen void voltage (byte chan); void main(void) { volatile unsigned int i; // Use volatile to prevent removal // by compiler optimization WDTCTL = WDTPW + WDTHOLD; // Stop WDT FLL_CTL0 |= XCAP14PF; // Configure load caps for (i = 0; i < 5000; i++); // Delay for 32 kHz crystal to // stabilize SD16CTL = SD16REFON; // 1.2V ref, MCLK TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode for (i = 0; i < 1; i++); // Delay for 1.2V ref startup 0x3600 //**************************************************************************** for (;;) { if (chan <= 3) // Einstellung für 2-Kanäle // (Kanal A0-A3) { voltage ((chan)); for ( i=0; i<30500; i++); // wait for ADC (ohne gehts irgenwie // gar nicht) } else chan=0; } } //**************************************************************************** void voltage(byte chan) { SD16INCTL0 |= (chan & 0x03) + SD16INTDLY_0; // Interrupt on 4th sample SD16CCTL0 |= SD16IE + SD16SNGL; // Single conv, enable interrupt, 1024 OSR SD16CCTL0 |= SD16SC; // SET BREAKPOINT HERE _EINT(); // Enable general interrupts } //**************************************************************************** #pragma vector=SD16_VECTOR __interrupt void SD16ISR(void) { switch (SD16IV) { case 2: // SD16MEM Overflow break; case 4: // SD16MEM0 IFG { calculate = SD16MEM0; // Save CH0 results (clears IFG) calculate -= 0x8000; //------------------- calculate /= 32768; // errechnen der Spannung(muß nicht drin sein!!) calculate *= .6; //------------------- result[chan++] = calculate; break; } } }