问题已解决,原来是函数调用时参数错了,重贴一下程序,能正常运行,供大家参考。
有关Stellaris的管脚复用问题可参考TI官方文档:Configuring Stellaris® Microcontrollers with Pin Multiplexing
#include "hw_memmap.h"
#include "hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/comp.h"
#include "driverlib/interrupt.h"
#include "drivers/set_pinout.h"
//#include "inc/lm3s9b96.h"
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
void comparator_init ()
{
//使能GPIO PB口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//使能模拟比较器0
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
//设置PB5的复用功能为模拟器0的输出
GPIOPinConfigure(GPIO_PB5_C0O);
// 设置 PB4 为C0-
GPIOPinTypeComparator(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 );
// GPIOPinTypeComparator(GPIO_PORTB_BASE, GPIO_PIN_4 );
// 配置模拟比较器0
ComparatorConfigure(COMP_BASE, 0, (COMP_TRIG_NONE | COMP_ASRCP_REF | COMP_INT_HIGH |
COMP_OUTPUT_NORMAL));
// 配置内部参考电压为 1.65V
ComparatorRefSet(COMP_BASE, COMP_REF_1_65V);
// 设置为硬件外部功能
GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_5,GPIO_DIR_MODE_HW);
// 设置为4mA驱动和推挽使能
GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_5,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
//使能比较器中断
ComparatorIntEnable(COMP_BASE, 0);
//使能比较器0中断
IntEnable(INT_COMP0);
}
void led_init()
{
//使能GPIO PF口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
// GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); //设置管脚类型
// GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_DIR_MODE_OUT);//设置输入输出
// PF3为推挽输出模式
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_3);
//LED亮
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, GPIO_PIN_3);
//延时
SysCtlDelay(SysCtlClockGet()/6);
//LED灭
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, 0);
}
void Analog_Comparator_0_ISR(void)
{
unsigned long ulStatus;
//读取比较器状态
ulStatus = ComparatorIntStatus(COMP_BASE,0, true);
//清除比较器中断标志
ComparatorIntClear(COMP_BASE, 0);
if (ulStatus)
{
if (ComparatorValueGet(COMP_BASE, 0))
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, GPIO_PIN_3); // 点亮LED
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, 0); // 熄灭LED
}
}
}
int main(void)
{
//
// Set the system clock to run at 16MHz from the PLL
//
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Set the device pinout appropriately for this board.
// 必需
PinoutSet();
//比较器初始化
comparator_init();
//LED管脚初始化
led_init();
//
// 处理器总中断必须最后开
//
IntMasterEnable();
while (1)
{
}
}