打印
[STM8]

STM8S ADC中断 求解

[复制链接]
2171|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
pidan678|  楼主 | 2015-2-6 18:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "stm8s.h"
#include "main.h"

void main(void)
{
    /*  Init GPIO for ADC2 */
    GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT);

    /* Init GPIO for LED  */
GPIO_Init(LEDS_PORT, LED1_PIN, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(LEDS_PORT, LED2_PIN, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(LEDS_PORT, LED3_PIN, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(LEDS_PORT, LED4_PIN, GPIO_MODE_OUT_PP_LOW_FAST);

    ADC1_DeInit();

    enableInterrupts();

    /* Configure the conversion mode and the channel to convert  */
    ADC1_ConversionConfig(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_9, ADC1_ALIGN_RIGHT);

    /* Configure the schmitt trigger channel and state */
    ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL9, DISABLE);

    /* Enable the ADC2 peripheral */
    ADC1_Cmd(ENABLE);

    /* Enable EOC interrupt */
   // ADC1_ITConfig(ENABLE);
    ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE);

    /* Configure the TIM1 Master/Slave mode */
    TIM1_SelectMasterSlaveMode(ENABLE);

    /*Configure the ADC2 external trigger */
    ADC1_ExternalTriggerConfig(ADC1_EXTTRIG_TIM, ENABLE);

    /* Trigger the conversion */
    TIM1_SelectOutputTrigger(TIM1_TRGOSOURCE_ENABLE);
    TIM1_Cmd(ENABLE);
    //ADC1_StartConversion();
          /* The LEDs are changed in the interrupt routine */

    while (1);
    {

        GPIO_WriteLow(GPIOA, GPIO_PIN_0);//为何进不了 while?
    }
}


INTERRUPT_HANDLER(ADC1_IRQHandler, 22)///ADC 中断函数
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
u16 Conversion_Value = 0;

    /* Get converted value */
    Conversion_Value = ADC1_GetConversionValue();

    if (Conversion_Value == 0x0)
    {
        ……
    }
    else if ((Conversion_Value <= 0xFF) && (Conversion_Value > 0x0))
    {
        ……
    }
    else if ((Conversion_Value >= 0x100) && (Conversion_Value <= 0x1FF))
    {
        ……
    }
    else if ((Conversion_Value >= 0x200) && (Conversion_Value <= 0x2FF))
    {
        ……

    }
    else
    {
        ……
    }
    //ADC1_ClearITPendingBit();
    //ADC1_ClearITPendingBit(ADC1_IT_AWS6);
    ADC1_ClearITPendingBit(ADC1_IT_EOC);

///清除ADC中断怎么写?  为什么一直在  中断函数里循环?


stm8S 中断ADC 是怎么样一个过程?

以定时器(TIM1中断)为例,while(1) 开始执行, TIM也同时开始运行,计数num++;清除中断一下,TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
当while(1)中 num==10(假设1秒);num=0;a=!a; 所以 a 每秒取反。

ADC中断方式  是一个类似的过程么?

还请明示,实在不理解。
}


发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

223

主题

404

帖子

5

粉丝