[技术问答] N76E003的ADC程序怎么写?

[复制链接]
8156|24
 楼主| rwbycc 发表于 2017-1-12 11:02 | 显示全部楼层 |阅读模式
例程里怎么没有初始化设置通道,要怎么转换数据
cybers 发表于 2017-1-12 13:16 | 显示全部楼层

/******************************************************************************
The main C function.  Program execution starts
here after stack initialization.
******************************************************************************/
void main (void)
{
    Set_All_GPIO_Quasi_Mode;
                InitialUART0_Timer1(115200);
          
/*-------------------------------------------
        ADC simply initial setting
--------------------------------------------*/
//                Enable_ADC_AIN3;                                                                                                                // Enable AIN0 P1.7 as ADC input
                Enable_ADC_BandGap;

                while(1)
    {
                        clr_ADCF;
                        set_ADCS;                                                                                                                                        // Each time ADC start trig signal
      while(ADCF == 0);
                        printf ("\n Value = 0x%bx",ADCRH);
                                printf ("\n Value = 0x%bx",ADCRL);
                        Timer0_Delay1ms(100);
    }
}

评论

大师:我是初学好的,我试验这个程序在编译时有两处错误, InitialUART0_Timer1(115200)和Timer0_Delay1ms(100)说没有定义,这两个头文件我已经加上。  发表于 2018-7-17 16:16
 楼主| rwbycc 发表于 2017-1-12 14:22 | 显示全部楼层
Enable_ADC_BandGap这是什么意思,ADCRH,ADCRL怎么转换成实际测量出的数据
643757107 发表于 2017-1-12 22:54 | 显示全部楼层
应该看看源程序,看看那个是什么函数,怎么实现。
dongnanxibei 发表于 2017-1-12 23:35 | 显示全部楼层
这个去官方下载例程开发包啊。
huangcunxiake 发表于 2017-1-13 23:57 | 显示全部楼层
这个看手册啊,就是51单片机,很容易弄。
zhuotuzi 发表于 2017-1-14 12:32 | 显示全部楼层
那个例程是没法看出来门道的。
dongnanxibei 发表于 2017-1-14 18:55 | 显示全部楼层
确认一下参考电压,按等比例的形式转换。
14小瑞 发表于 2017-10-14 14:49 | 显示全部楼层
可是数据手册里好像没有教怎么确定参考电压,请指教
Andy003 发表于 2017-10-14 15:18 | 显示全部楼层
欢迎来勾搭,代理新唐产品、技术大力支持
zhuomuniao110 发表于 2017-10-14 22:11 来自手机 | 显示全部楼层
参考电压看手册啊,看例程也行
秦川牛 发表于 2018-1-11 15:38 | 显示全部楼层
我的问题是ADC 数值不稳定,测试的是个很稳定的电压源,2.5v,还没头绪:
0C17
0C15
0C1C
0C1B
0C15
0C19
0C0F
0C18
0C16
0C13
0C16
0C19
0C16
0C16
0C1E
0C19
0C18
0C1F
0C1B
0C0D
0C28
0C18
0C1E
0C13
0C09
0C0F
0C13
0C26
0BFD
0C13
0C15
0C16
smilefenfen 发表于 2018-4-17 11:17 | 显示全部楼层
同感,有相关资料的伙伴可以分享一下吗,谢谢了
捉虫天师 发表于 2018-4-17 22:46 | 显示全部楼层
使能通道那个不是吗
停车说爱枫林晚 发表于 2018-6-5 14:42 | 显示全部楼层
找到规格书,写的也不是很清楚。
huangcunxiake 发表于 2018-6-6 20:40 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2017
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 ADC demo code
  14. //***********************************************************************************************************

  15. #include "N76E003.h"
  16. #include "SFR_Macro.h"
  17. #include "Function_define.h"
  18. #include "Common.h"
  19. #include "Delay.h"


  20. //*****************  The Following is in define in Fucntion_define.h  ***************************
  21. //****** Always include Function_define.h call the define you want, detail see main(void) *******
  22. //***********************************************************************************************
  23. #if 0
  24. //#define Enable_ADC_AIN0                        ADCCON0&=0xF0;P17_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT0;ADCCON1|=SET_BIT0                                                                        //P17
  25. //#define Enable_ADC_AIN1                        ADCCON0&=0xF0;ADCCON0|=0x01;P30_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT1;ADCCON1|=SET_BIT0                //P30
  26. //#define Enable_ADC_AIN2                        ADCCON0&=0xF0;ADCCON0|=0x02;P07_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT2;ADCCON1|=SET_BIT0                //P07
  27. //#define Enable_ADC_AIN3                        ADCCON0&=0xF0;ADCCON0|=0x03;P06_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT3;ADCCON1|=SET_BIT0                //P06
  28. //#define Enable_ADC_AIN4                        ADCCON0&=0xF0;ADCCON0|=0x04;P05_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT4;ADCCON1|=SET_BIT0                //P05
  29. //#define Enable_ADC_AIN5                        ADCCON0&=0xF0;ADCCON0|=0x05;P04_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT5;ADCCON1|=SET_BIT0                //P04
  30. //#define Enable_ADC_AIN6                        ADCCON0&=0xF0;ADCCON0|=0x06;P03_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT6;ADCCON1|=SET_BIT0                //P03
  31. //#define Enable_ADC_AIN7                        ADCCON0&=0xF0;ADCCON0|=0x07;P11_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT7;ADCCON1|=SET_BIT0                //P11
  32. //#define Enable_ADC_BandGap        ADCCON0|=SET_BIT3;ADCCON0&=0xF8;                                                                                                                                                                                                                                                        //Band-gap 1.22V

  33. //#define PWM0_FALLINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
  34. //#define PWM2_FALLINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
  35. //#define PWM4_FALLINGEDGE_TRIG_ADC                ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
  36. //#define PWM0_RISINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1
  37. //#define PWM2_RISINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1
  38. //#define PWM4_RISINGEDGE_TRIG_ADC                ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1

  39. //#define P04_FALLINGEDGE_TRIG_ADC                ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6
  40. //#define P13_FALLINGEDGE_TRIG_ADC                ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6
  41. //#define P04_RISINGEDGE_TRIG_ADC                        ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6
  42. //#define P13_RISINGEDGE_TRIG_ADC                        ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6
  43. #endif

  44. /******************************************************************************
  45. The main C function.  Program execution starts
  46. here after stack initialization.
  47. ******************************************************************************/
  48. void main (void)
  49. {
  50.                 InitialUART0_Timer1(115200);

  51.                 Enable_ADC_AIN3;                                                // Enable AIN0 P1.7 as ADC input, Find in "Function_define.h" - "ADC INIT"
  52.                 while(1)
  53.     {
  54.                         clr_ADCF;
  55.                         set_ADCS;                                                                        // ADC start trig signal
  56.       while(ADCF == 0);
  57.                         printf ("\n Value = 0x%bx",ADCRH);
  58.                         printf ("\n Value = 0x%bx",ADCRL);
  59.                         Timer0_Delay1ms(100);
  60.     }
  61. }


huangcunxiake 发表于 2018-6-6 20:40 | 显示全部楼层
这个是单通道的例子,通道3
yiyigirl2014 发表于 2018-6-7 16:45 | 显示全部楼层
这个ADC不是很容易用吗
捉虫天师 发表于 2018-6-7 23:08 | 显示全部楼层
使能不就是初始化吗
mintspring 发表于 2018-6-8 17:26 | 显示全部楼层
一个使能指令就搞定了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

32

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部