[技术问答] N76E003 ADC_IO_Trig demo code

[复制链接]
656|7
 楼主| darklighttt 发表于 2020-3-30 19:47 | 显示全部楼层 |阅读模式
  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 "Common.h"
  17. #include "Delay.h"
  18. #include "SFR_Macro.h"
  19. #include "Function_define.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|=0x0F;ADCCON1|=SET_BIT0                                                                                                                                                                                                                                                                //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. * FUNCTION_PURPOSE: ADC interrupt Service Routine
  46. ******************************************************************************/
  47. void ADC_ISR (void) interrupt 11
  48. {
  49.     clr_ADCF;                               //clear ADC interrupt flag
  50.                 printf ("\n Value = 0x%bx",ADCRH);
  51. }

  52. /******************************************************************************
  53. The main C function.  Program execution starts
  54. here after stack initialization.
  55. ******************************************************************************/
  56. void main (void)
  57. {
  58.     Set_All_GPIO_Quasi_Mode;
  59.                 InitialUART0_Timer1(115200);
  60. /*---------------------------------------------------------------
  61.         ADC port trig initial setting toggle P0.4 to start ADC
  62. ----------------------------------------------------------------*/
  63.                 Enable_ADC_AIN0;                                                                                                                        // Enable AIN0 P1.7 as ADC pin
  64.                 P04_FALLINGEDGE_TRIG_ADC;                                                                                        // P0.4 falling edge as adc start trig signal
  65. // find ADC result in ADC interrupt
  66.     set_EADC;                                                                                                                                                        // Enable ADC interrupt (if use interrupt)
  67.                 EA = 1;                                                                                                                                                                // Enable global interrupt
  68. //        set_ADCS;                                                                                                                                                        // Trig P04 falling edge to start adc, no need set ADCS bit
  69.                 while(1);                                                                                                                                                        // Wait ADC interrupt


  70. }




jiekou001 发表于 2020-3-30 21:49 | 显示全部楼层
没看太明白
keaibukelian 发表于 2020-4-6 16:06 | 显示全部楼层
非常感谢楼主分享
labasi 发表于 2020-4-6 16:06 | 显示全部楼层
非常感谢楼主分享
paotangsan 发表于 2020-4-6 16:06 | 显示全部楼层
非常感谢楼主分享
renzheshengui 发表于 2020-4-6 16:06 | 显示全部楼层
非常感谢楼主分享
wakayi 发表于 2020-4-6 16:07 | 显示全部楼层
非常感谢楼主分享
Harvard 发表于 2020-4-6 21:47 | 显示全部楼层
搞啥 bsp里面的半吊子例程 有啥好发帖的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

21

主题

132

帖子

0

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