static void ConfigADCInit(void)
{
// 复位GPIO
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,GPIO_PIN0);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,GPIO_PIN1);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,GPIO_PIN2);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,GPIO_PIN5);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,GPIO_PIN6);
// 配置ADC参数
ADC12_A_init(ADC12_A_BASE,ADC12_A_SAMPLEHOLDSOURCE_SC, ADC12_A_CLOCKSOURCE_ADC12OSC, ADC12_A_CLOCKDIVIDER_1);
// 启用ADC12_A模块
ADC12_A_enable(ADC12_A_BASE);
// 配置ADC12_A模块的采样计时器,以控制采样/保持信号的持续时间以及采样过程中的时钟周期数
ADC12_A_setupSamplingTimer(ADC12_A_BASE,ADC12_A_CYCLEHOLD_128_CYCLES,ADC12_A_CYCLEHOLD_4_CYCLES,ADC12_A_MULTIPLESAMPLESENABLE);
// 配置ADC P6.0
ADC12_A_configureMemoryParam ADCA0_InitStructure = {
.inputSourceSelect = ADC12_A_INPUT_A0, // A0作为输入通道
.endOfSequence = ADC12_A_NOTENDOFSEQUENCE, // 不是序列结束
.memoryBufferControlIndex = ADC12_A_MEMORY_0, // 内存0
.negativeRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC, // 参考电压为AVCC
.positiveRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS, // 参考电压为AVSS
};
// 配置ADC P6.1
ADC12_A_configureMemoryParam ADCA1_InitStructure = {
.inputSourceSelect = ADC12_A_INPUT_A1,
.endOfSequence = ADC12_A_NOTENDOFSEQUENCE,
.memoryBufferControlIndex = ADC12_A_MEMORY_1,
.negativeRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC,
.positiveRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS,
};
// 配置ADC P6.2
ADC12_A_configureMemoryParam ADCA2_InitStructure = {
.inputSourceSelect = ADC12_A_INPUT_A2,
.endOfSequence = ADC12_A_NOTENDOFSEQUENCE,
.memoryBufferControlIndex = ADC12_A_MEMORY_2,
.negativeRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC,
.positiveRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS,
};
// 配置ADC P6.5
ADC12_A_configureMemoryParam ADCA5_InitStructure = {
.inputSourceSelect = ADC12_A_INPUT_A5,
.endOfSequence = ADC12_A_NOTENDOFSEQUENCE,
.memoryBufferControlIndex = ADC12_A_MEMORY_5,
.negativeRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC,
.positiveRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS,
};
// 配置ADC P6.6
ADC12_A_configureMemoryParam ADCA6_InitStructure = {
.endOfSequence = ADC12_A_ENDOFSEQUENCE,
.inputSourceSelect = ADC12_A_INPUT_A6,
.memoryBufferControlIndex = ADC12_A_MEMORY_6,
.negativeRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC,
.positiveRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS,
};
// 配置ADC
ADC12_A_configureMemory(ADC12_A_BASE ,&ADCA0_InitStructure);
ADC12_A_configureMemory(ADC12_A_BASE ,&ADCA1_InitStructure);
ADC12_A_configureMemory(ADC12_A_BASE ,&ADCA2_InitStructure);
ADC12_A_configureMemory(ADC12_A_BASE ,&ADCA5_InitStructure);
ADC12_A_configureMemory(ADC12_A_BASE ,&ADCA6_InitStructure);
// 开始转换
ADC12_A_startConversion(ADC12_A_BASE, ADC12_A_MEMORY_0, ADC12_A_REPEATED_SEQOFCHANNELS);
ADC12_A_startConversion(ADC12_A_BASE, ADC12_A_MEMORY_1, ADC12_A_REPEATED_SEQOFCHANNELS);
ADC12_A_startConversion(ADC12_A_BASE, ADC12_A_MEMORY_2, ADC12_A_REPEATED_SEQOFCHANNELS);
ADC12_A_startConversion(ADC12_A_BASE, ADC12_A_MEMORY_3, ADC12_A_REPEATED_SEQOFCHANNELS);
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_interrupt (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: break; //Vector 12: ADC12IFG3
case 14: break; //Vector 14: ADC12IFG4
case 16: break; //Vector 16: ADC12IFG5
case 18:
A0results[index] = ADC12_A_getResults(ADC12_A_BASE, ADC12_A_MEMORY_0); // Move A0 results, IFG is cleared
UART_printf(USCI_A1_BASE,"%f",A0results[index] / 0xffff * 3.3);
A1results[index] = ADC12_A_getResults(ADC12_A_BASE, ADC12_A_MEMORY_1); // Move A1 results, IFG is cleared
UART_printf(USCI_A1_BASE,"%f",A1results[index] / 0xffff * 3.3);
A2results[index] = ADC12_A_getResults(ADC12_A_BASE, ADC12_A_MEMORY_2); // Move A2 results, IFG is cleared
UART_printf(USCI_A1_BASE,"%f",A2results[index] / 0xffff * 3.3);
A5results[index] = ADC12_A_getResults(ADC12_A_BASE, ADC12_A_MEMORY_5); // Move A5 results, IFG is cleared
UART_printf(USCI_A1_BASE,"%f",A5results[index] / 0xffff * 3.3);
A6results[index] = ADC12_A_getResults(ADC12_A_BASE, ADC12_A_MEMORY_6); // Move A6 results, IFG is cleared
UART_printf(USCI_A1_BASE,"%f",A6results[index] / 0xffff * 3.3);
index++;
if (index == 8)
{
(index = 0);
}
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;
}
}
串口无法打印ADC值
|