在线时间0 小时
UID230822
ST金币0
蝴蝶豆0
注册时间2010-10-15
新手上路
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2012-12-5 16:50:53
|
显示全部楼层
a0a.1 0b0c
回复:STM32比较器
不好意思,刚才发的代码有问题,下面的是正确的。
还请各位多多帮忙,拜谢。
void COMP_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//COMP_InitTypeDef COMP_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA4 in analog mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;----------------------------------------更改
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);---------------------------------------------更改
/* COMP Peripheral clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, ENABLE);
COMP_Cmd(ENABLE); /* Enable the Comparator 1 */
Delay(1);
SYSCFG_RISwitchControlModeCmd(ENABLE);/* Enable the switch control mode */
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_VCOMP, ENABLE);/* Close the ADC analog switch VCOMP */
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_CH4, ENABLE); /* Close the I/O analog switch number 4 */----------------------------------------更改
/* Configure and enable EXTI21 */
EXTI_InitStructure.EXTI_Line = EXTI_Line21;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Configure and enable COMP interrupt */
NVIC_InitStructure.NVIC_IRQChannel = COMP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0f;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |
|