|
我是用tiva c TM4C123GH6PM 这款板子,现在想用ADC模块测量外界直流电压。然后我是用PD0引脚连接外界待测电压值,然后GND引脚和待测电路地相连。但是测不出值来。就算我改变外界电压,ADC模块的测量值始终是一个固定值。主程序如下。希望大家可以帮忙!!
#include
#include
#include
#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_adc.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/ssi.h"
#include "uc1701.h"
//ADC 初始化程序
void ADC_Init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0);
ADCSequenceConfigure(ADC0_BASE,1,ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
}
uint32_t ui32ADC0Value[4];
uint32_t num0;
int main()
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
ADC_Init();
UC1701Init(60000);
UC1701Clear();
while(1)
{
UC1701CharDispaly(0, 1, "I love tiva-pb?");
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{ }
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
num0 = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
UC1701DisplayN(1,1,num0);
UC1701Clear();
}
}
|
|