[技术问答] N76E003 SPI ADC / Bandgap input demo code

[复制链接]
731|8
 楼主| darklighttt 发表于 2020-3-30 19:44 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Website: http://www.nuvoton.com
  8. //  E-Mail : MicroC-8bit@nuvoton.com
  9. //  Date   : Jan/21/2017
  10. //***********************************************************************************************************

  11. //***********************************************************************************************************
  12. //  File Function: N76E003 SPI ADC / Bandgap input demo code
  13. //***********************************************************************************************************
  14. #include "N76E003.h"
  15. #include "SFR_Macro.h"
  16. #include "Function_define.h"
  17. #include "Common.h"
  18. #include "Delay.h"

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

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

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

  43. /******************************************************************************
  44. The main C function.  Program execution starts
  45. here after stack initialization.
  46. ******************************************************************************/
  47. void main (void)
  48. {
  49.                 P12_Quasi_Mode;                                                                                                                        //For GPIO1 output, Find in "Function_define.h" - "GPIO INIT"
  50.                 InitialUART0_Timer1(115200);
  51.                 Enable_ADC_BandGap;                                                                                                        //Find in "Function_define.h" - "ADC INIT"

  52.                 while(1)
  53.     {
  54.                         clr_ADCF;
  55.                         set_ADCS;                                                                                                                                        // Each time ADC start trig signal
  56.       while(ADCF == 0);
  57.                         printf ("\n Value = 0x%bx",ADCRH);
  58.                         printf ("\n Value = 0x%bx",ADCRL);
  59.                         clr_GPIO1;
  60. //                        Timer0_Delay1ms(100);
  61.                         set_GPIO1;
  62.     }
  63. }




jiekou001 发表于 2020-3-30 22:01 | 显示全部楼层
003非常好用
antusheng 发表于 2020-3-31 21:49 | 显示全部楼层
测电压 应用?
heimaojingzhang 发表于 2020-4-6 16:03 | 显示全部楼层
非常感谢楼主分享
keaibukelian 发表于 2020-4-6 16:03 | 显示全部楼层
非常感谢楼主分享
labasi 发表于 2020-4-6 16:04 | 显示全部楼层
非常感谢楼主分享
paotangsan 发表于 2020-4-6 16:04 | 显示全部楼层
非常感谢楼主分享
renzheshengui 发表于 2020-4-6 16:04 | 显示全部楼层
非常感谢楼主分享
antusheng 发表于 2020-4-7 20:15 | 显示全部楼层
不清楚这个功能是干啥
您需要登录后才可以回帖 登录 | 注册

本版积分规则

21

主题

132

帖子

0

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