工具/软件:Code Composer Studio
大家好、我正在编写模拟比较器的代码、其中电位计用作外部基准、在比较器的处理程序中、我必须读取比较器的值。 请、有人可以帮我解决这个问题吗? 我的代码不在中断处理程序中。
#include
#include
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/gpio.h"
#include "inc/hw_comp.h"
#include "driverlib/comp.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"
uint32_t comp_value;
空 compinthandler (空)
{
COMP_VALE=比较器 ValueGet (COMP_BASE、0);
ComparatorIntClear (COMP_BASE、0);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
SysCtlDelay (5000000);
GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、0);
SysCtlDelay (5000000);
}
int main (空)
{
volatile uint32_t ui32Loop;
uint32_t ui32ADC0Value[4];
//设置时钟频率。
SysCtlClockSet (SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHz);
//启用 GPIO PORTF。
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOF);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOE);
//启用 ADC0。
SysCtlPeripheralEnable (SYSCTL_Periph_ADC0);
//启用比较器 COMP0。
SysCtlPeripheralEnable (SYSCTL_Periph_COMP0);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOC);
GPIOPinTypeGPIOOutput (GPIO_PORTF_BASE、GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3);
GPIOPinTypeComparator (GPIO_PORTC_BASE、GPIO_PIN_6);
GPIOPinTypeADC (GPIO_Porte _BASE、GPIO_PIN_3);
ADCSequenceConfigure (ADC0_BASE、1、ADC_TRIGGER_PROCESSOR、0);
ADCSequenceEnable (ADC0_BASE、1);
ADCProcessorTrigger (ADC0_BASE、1);
ADCSequenceDataGet (ADC0_BASE、1、ui32ADC0Value);
ComparatorRefSet (COMP_BASE、COMP_REF_1_65V);
比较器配置(COMP_BASE、0、(COMP_TRIG_NONE | COMP_INT_Both |COMP_ASRCP_REF| COMP_OUTPUT_NORMAL));
ComparatorIntEnable (COMP_BASE、0);
IntEnable (INT_COMP0);
IntMasterEnable();
while (1)
{
// comp_value=比较器 ValueGet (COMP_BASE、0);
//
// GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、GPIO_PIN_1);
// SysCtlDelay (5000000);
// GPIOPinWrite (GPIO_PORTF_BASE、GPIO_PIN_1、0);
// SysCtlDelay (5000000);
}
}