#include <msp430.h>
#include <msp430F5529.h>
#include "driverlib.h"
/*************接线*******************/
//! MSP430F552x
//! -----------------
//! /|\| |
//! | | P6.0/A0|<- Vin0
//! --|RST P6.1/A1|<- Vin1
//! | P6.2/A2|<- Vin2
//! | P6.3/A3|<- Vin3
//! | |
/**************************************/
#define Num_of_Results 8
volatile unsigned int A0results[Num_of_Results];
volatile unsigned int A1results[Num_of_Results];
volatile unsigned int A2results[Num_of_Results];
volatile unsigned int A3results[Num_of_Results];
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // 停止看门狗定时器
OLED_Init(); //OLED初始化
OLED_Clear(); //OLED清屏
/*ADC初始化*/
P6SEL = 0x0F; // 使能 A/D
ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_8; // 打开ADC12,延长采样时间以避免结果溢出。
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3; // 使用采样定时器,多通道重复顺序转化。
ADC12MCTL0 = ADC12INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = ADC12INCH_1; // ref+=AVcc, channel = A1
ADC12MCTL2 = ADC12INCH_2; // ref+=AVcc, channel = A2
ADC12MCTL3 = ADC12INCH_3+ADC12EOS; // ref+=AVcc, channel = A3, end seq.
ADC12IE = 0x08; // Enable ADC12IFG.3
ADC12CTL0 |= ADC12ENC; // 启用转换
ADC12CTL0 |= ADC12SC; // 启用转换 -软件触发
while(1)
{
OLED_ShowString(30,1,"ADC",20);
OLED_ShowString(20,2,"ADC0=",20);
OLED_ShowNum(60,2,ADC12MEM0,4,20);
OLED_ShowString(20,3,"ADC1=",20);
OLED_ShowNum(60,3,ADC12MEM1,4,20);
OLED_ShowString(20,4,"ADC2=",20);
OLED_ShowNum(60,4,ADC12MEM2,4,20);
OLED_ShowString(20,5,"ADC3=",20);
OLED_ShowNum(60,5,ADC12MEM3,4,20);
//Enter LPM4, Enable interrupts
// __bis_SR_register(LPM4_bits + GIE);
//For debugger
//__no_operation();
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(ADC12_VECTOR)))
#endif
void ADC12ISR (void)
{
static unsigned int index = 0;
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: break; // Vector 6: ADC12IFG0
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: // Vector 12: ADC12IFG3
A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared
A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared
A2results[index] = ADC12MEM2; // Move A2 results, IFG is cleared
A3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared
index++; // Increment results index, modulo; Set Breakpoint1 here
if (index == 3)
{
(index = 0);
}
//Exit active CPU, SET BREAKPOINT HERE
// __bic_SR_register_on_exit(LPM4_bits);
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}