STM8S207的AD转换

来源:互联网 发布:域名注册通官网 编辑:程序博客网 时间:2024/05/13 06:51
void ADC_Init(void)
{
    GPIO_Init(GPIOE, GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT);//通道9,

    CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC,ENABLE);//开启时钟

//通道9,单次转换,右对齐

    ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_9, ADC2_PRESSEL_FCPU_D2, ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT,   ADC2_SCHMITTTRIG_CHANNEL9, DISABLE);
    ADC2_ITConfig(ENABLE);    //中断使能
    ADC2_Cmd(ENABLE); //ADC2使能


}
void AD_Manage(void) //定时执行
{
  ADC2_StartConversion(); //开启一次转换,在中断函数处理

}




中断函数


#ifdef _IAR_SYSTEMS_
#pragma vector=0x18
__interrupt void ADC2_IRQHandler(void)
#endif
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
    u16 Conversion_Value;
    Conversion_Value = ADC2_GetConversionValue();
    
    printf("ADC2_Value:%u\n",Conversion_Value);
    ADC2_ClearITPendingBit();
  
  
}

0 0