📄 iar-
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: Analog_Comparators_in.c
** Last modified Date: 2007-09-20
** Last Version: v1.0
** Description: Stellaris系列单片机模拟比较器的操作
**
**--------------------------------------------------------------------------------------------------------
** Created By: Zhou Hai Xin
** Created date: 2007-09-20
** Version: v1.0
** Descriptions: 将 VIN1 连接到模拟比较器的输入脚 PB4,模拟比较器使用内部参考电压 1.1V,
** 比较的结果在 PB5 上输出,PB6 连接到 LED3 以便观察实验现象。
** 同时读取比较寄存器的结果,从PB5输出显示.
**
**--------------------------------------------------------------------------------------------------------
** Modified by: Kang qinhua
** Modified date: 2008.01.13
** Version: v1.1
** Description:
**
*********************************************************************************************************/
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "systick.h"
#include "comp.h"
#define PB4 GPIO_PIN_4 /* PB4为VIN- */
#define PB6 GPIO_PIN_6 /* PB6为连接LED3 */
#define PB5 GPIO_PIN_5 /* PB5为VOUT */
/*********************************************************************************************************
** 函数原形:int main(void)
** 功能描述:通过外部VIN1与内部参考电压进行比较,通过比较的结果来控制LED3和LED4的状态
LED4将显示比较结果:亮:输入值<基准值;灭:输入值>基准值。
LED3将显示比较结果:亮:输入值>基准值;灭:输入值<基准值。
** 参数说明:无
** 返回值: 0
*********************************************************************************************************/
int main(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); /* 使能GPIO PB口 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); /* 使能GPIO PF口 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0); /* 使能模拟比较器0 */
GPIODirModeSet(GPIO_PORTB_BASE, PB6, GPIO_DIR_MODE_OUT); /* 设置 PB6为输出 */
GPIOPadConfigSet(GPIO_PORTB_BASE, PB6, /* 设置 PB6强度和类型 */
GPIO_STRENGTH_4MA, /* 4mA的输出驱动强度 */
GPIO_PIN_TYPE_STD); /* 设置为推挽管脚 */
GPIOPinTypeComparator(GPIO_PORTB_BASE, PB4); /* 设置 PB4 为C0- */
GPIODirModeSet(GPIO_PORTB_BASE, PB5, GPIO_DIR_MODE_HW); /* 设置为硬件外部功能 */
GPIOPadConfigSet(GPIO_PORTB_BASE, PB5,GPIO_STRENGTH_4MA, /* 设置为4mA驱动和推挽使能 */
GPIO_PIN_TYPE_STD);
ComparatorConfigure(COMP_BASE, 0, (COMP_TRIG_NONE | COMP_ASRCP_REF |
COMP_OUTPUT_NORMAL)); /* 配置模拟比较器0 */
ComparatorRefSet(COMP_BASE, COMP_REF_1_1V); /* 配置内部参考电压为 1.1V */
while (1) {
if (ComparatorValueGet(COMP_BASE, 0) == 1 ) { /* 读取比较结果. 1:点亮LED3;
0: 熄灭LED3 */
GPIOPinWrite(GPIO_PORTB_BASE, PB6, ~ PB6); /* 点亮LED3 */
} else {
GPIOPinWrite(GPIO_PORTB_BASE, PB6, PB6); /* 熄灭LED3 */
}
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -