9070|3

4

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

关于STM8的ADC转换 [复制链接]

在使用STM8的AD功能时,数据寄存器有左对齐和右对齐模式。我见很多人的处理方法是:左对齐模式下,在读取时,DRH数据向左移动两位。这种处理方式在高位不是零时,高两位不是被覆盖掉了么;右对齐时,也用移位处理方式,不是很理解。希望大虾们能指点一下。
此帖出自stm32/stm8论坛

最新回复

在ADC模块中,怎样进行初始化! 我使用的是库函数设置的但是不能正确转化。 程序如下: #include "stm8s208rb.h" #include "stm8s_gpio.h" #include "stm8s_adc2.h" void GPIO_Config(void); void ADC_Config(void); void delay(u32 ch) {         while(ch--); } main() {         u8 port_value=0;         u16 u16_ADC2_value=0;                 GPIO_Config();                 ADC_Config();                 while(1)         {                 port_value = GPIO_ReadInputData(GPIOF);   //扫描ADC管脚,准备进行转化                 port_value=port_value&0x20;                 if(port_value==0x20)   //如果ADC管脚为高电平,则进行转化,并进行点灯动作                 {                         delay(5);                         port_value = GPIO_ReadInputData(GPIOF);                         port_value=port_value&0x20;                         if(port_value==0x20)                         {                         ADC2_StartConversion();                         u16_ADC2_value = ADC2_GetConversionValue();                         //ADC2_ClearFlag();                         //ADC2_Cmd(DISABLE);                                 while( ADC2_GetFlagStatus()==RESET);                                 if(u16_ADC2_value > 906 && u16_ADC2_value < 1024)                                 {                                         GPIO_WriteHigh(GPIOB, GPIO_PIN_3);                                 }                                 if(u16_ADC2_value > 0 && u16_ADC2_value < 905 )                                 {                                         GPIO_WriteHigh(GPIOB, GPIO_PIN_2);                                 }                         }                 }           delay(500);                 GPIO_Write(GPIOB, 0x00);         } } void GPIO_Config(void) {         GPIO_Init(GPIOB, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_HIGH_FAST);  //LED灯的管脚         GPIO_Write(GPIOB, 0x00); } void ADC_Config(void) {         GPIO_Init(GPIOF, GPIO_PIN_5, GPIO_MODE_IN_FL_NO_IT); //ADC模拟信号输入管脚         ADC2_DeInit();         ADC2_Init(ADC2_CONVERSIONMODE_CONTINUOUS, ADC2_CHANNEL_0, ADC2_PRESSEL_FCPU_D2,                 ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL0, DISABLE);         ADC2_Cmd(ENABLE); } #ifdef USE_FULL_ASSERT /**   * @brief  Reports the name of the source file and the source line number   *   where the assert_param error has occurred.   * @param file: pointer to the source file name   * @param line: assert_param error line source number   * @retval None   */ void assert_failed(uint8_t* file, uint32_t line) {   /* User can add his own implementation to report the file name and line number,      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */   /* Infinite loop */   while (1)   {   } } #endif  详情 回复 发表于 2012-4-5 18:11
点赞 关注
 

回复
举报

4008

帖子

0

TA的资源

版主

沙发
 
循环移位吧,废除低两位
此帖出自stm32/stm8论坛
 
 

回复

30

帖子

0

TA的资源

一粒金砂(中级)

板凳
 
只表示关注。
此帖出自stm32/stm8论坛
 
 

回复

10

帖子

0

TA的资源

一粒金砂(中级)

4
 

回复 楼主 Qsfgvnkl 的帖子

在ADC模块中,怎样进行初始化!
我使用的是库函数设置的但是不能正确转化。
程序如下:
#include "stm8s208rb.h"
#include "stm8s_gpio.h"
#include "stm8s_adc2.h"

void GPIO_Config(void);
void ADC_Config(void);

void delay(u32 ch)
{
        while(ch--);
}
main()
{
        u8 port_value=0;
        u16 u16_ADC2_value=0;
       
        GPIO_Config();
       
        ADC_Config();
       
        while(1)
        {

                port_value = GPIO_ReadInputData(GPIOF);   //扫描ADC管脚,准备进行转化
                port_value=port_value&0x20;
                if(port_value==0x20)   //如果ADC管脚为高电平,则进行转化,并进行点灯动作
                {
                        delay(5);
                        port_value = GPIO_ReadInputData(GPIOF);
                        port_value=port_value&0x20;
                        if(port_value==0x20)
                        {
                        ADC2_StartConversion();
                        u16_ADC2_value = ADC2_GetConversionValue();
                        //ADC2_ClearFlag();
                        //ADC2_Cmd(DISABLE);
                                while( ADC2_GetFlagStatus()==RESET);
                                if(u16_ADC2_value > 906 && u16_ADC2_value < 1024)
                                {
                                        GPIO_WriteHigh(GPIOB, GPIO_PIN_3);
                                }
                                if(u16_ADC2_value > 0 && u16_ADC2_value < 905 )
                                {
                                        GPIO_WriteHigh(GPIOB, GPIO_PIN_2);
                                }
                        }
                }
          delay(500);
                GPIO_Write(GPIOB, 0x00);
        }
}

void GPIO_Config(void)
{
        GPIO_Init(GPIOB, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_HIGH_FAST);  //LED灯的管脚
        GPIO_Write(GPIOB, 0x00);
}
void ADC_Config(void)
{
        GPIO_Init(GPIOF, GPIO_PIN_5, GPIO_MODE_IN_FL_NO_IT); //ADC模拟信号输入管脚
        ADC2_DeInit();
        ADC2_Init(ADC2_CONVERSIONMODE_CONTINUOUS, ADC2_CHANNEL_0, ADC2_PRESSEL_FCPU_D2,
                ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL0, DISABLE);
        ADC2_Cmd(ENABLE);
}
#ifdef USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif
此帖出自stm32/stm8论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表