请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:TM4C123GH6PM 主题中讨论的其他器件:LM339
/*
* Comparator_Init.c
*
*模拟比较器的配置方式,关于输出 F0、1无反应的问题尚未解决
*创建日期:2019年7月30日
* 作者:管理员
*/
#include
#include
#include "inc/hw_gpio.h"
#include "comp/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/Gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib_gpin/define
#define #define #define #define "driverlib"#define #driverlib_gpine/gpio.h"#define #define #define #define #define #define #define #include "driverlib_gpin/driverlib_ine.h"#define #define #define #define #define #define #define
//uint32_t g_ui32SysClock;//系统时钟频率,单位为 Hz。
SysCtlClockSet (SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHz | SYSCTL_OSC_MAIN);
//g_ui32SysClock = SysCtlClockGet ();
IntMasterEnable();//启用处理器中断
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOC);//启用端口 C
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOF);//启用端口 F
/* HWREG (GPIO_PORTF_BASE + GPIO_LOCK)= GPIO_LOCK_KEY;
HWREG (GPIO_PORTF_BASE + GPIO_O_CR)= 0x01;
HWREG (GPIO_PORTF_BASE + GPIO_O_LOCK)= 0;*
SysCtlPeripheralEnable (SYSCTL_Periph_COMP0);//启用比较器0
while (!SysCtlPeripheralReady (SYSCTL_Periph_COMP0))//等待 COMP 模块准备就绪
{
}
GPIOPinTypeGPIOOutput (GPIO_PORTF_BASE、红色|蓝色|绿色);//为 LED 启用 GPIO 引脚(PF1红色、PF2蓝色、PF3绿色)
ComparatorRefSet (COMP_BASE、COMP_REF_0_275V);//配置内部电压基准
// GPIOPinTypeComparatorOutput (GPIO_PORTF_BASE、GPIO_PIN_0);//比较器输出
GPIOPinConfigure (GPIO_PF0_C0O);
HWREG (0x40025000 + 0x420)|= 0x01;
HWREG (0x40025000 + 0x52C)|= 0x09;
GPIOPinTypeComparator (GPIO_PORTC_BASE、GPIO_PIN_7);//比较器输入
比较器配置(COMP_BASE、0、(COMP_TRIG_NONE | COMP_INT_Both | COMP_ASRCP_REF | COMP_OUTPUT_NORMAL));//配置比较器0
while (1)
{
if (ComparatorValueGet (COMP_BASE、0)= true)
{
GPIOPinWrite (GPIO_PORTF_BASE、红色|蓝色|绿色、绿色);//< 0.275V
}
其他
{
GPIOPinWrite (GPIO_PORTF_BASE、红色|蓝色|绿色、红色);//> 0.275V
}
}