[DemoCode下载] ML51的模拟比较器的几种应用方法

[复制链接]
1119|9
 楼主| mintspring 发表于 2019-7-26 00:28 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Website: http://www.nuvoton.com
  8. //  E-Mail : MicroC-8bit@nuvoton.com
  9. //***********************************************************************************************************

  10. //***********************************************************************************************************
  11. //  File Function: ML51 simple GPIO toggle out demo code
  12. //***********************************************************************************************************

  13. #include "ML51.h"
  14. /**
  15. * [url=home.php?mod=space&uid=247401]@brief[/url]       ACMP interrupt subroutine
  16. * @param       None
  17. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  18. * [url=home.php?mod=space&uid=1543424]@Details[/url]     None
  19. */
  20. void ACMP_ISR (void) interrupt 23
  21. {
  22.   SFRS=0;
  23.   if ((ACMPSR&SET_BIT2)==SET_BIT2)
  24.   {
  25.     ACMPSR&=CLR_BIT2;
  26.     P13 ^=1;
  27.   }
  28.   else if ((ACMPSR&SET_BIT0)==SET_BIT0)
  29.   {
  30.     ACMPSR&=CLR_BIT0;
  31.     P14 ^=1;
  32.   }  
  33. }

  34. /**
  35. * @brief       ACMP negative input use CRV voltage
  36. * @param       None
  37. * @return      None
  38. * @details     None
  39. */
  40. void main (void)
  41. {
  42. /* Setting Multi function pin setting for GPIO toggle
  43.    * include gipo.c in Common for GPIO mode setting
  44. */  MFP_P13_GPIO;
  45.     P13_QUASI_MODE;
  46.     MFP_P14_GPIO;
  47.     P14_QUASI_MODE;
  48.   
  49.     MFP_P23_ACMP0_P1;   
  50.     MFP_P41_ACMP0_O;
  51.    
  52. /* ACMP intial
  53.    * include acmp.c in Library for ACMP initial and interrupt setting.
  54. */
  55.     VREF_Open(2);
  56. /* Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1 */
  57.     ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_CRV, ACMP_CTL_CRV_VREF, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
  58. /* CRV Value = CRV source voltage * (2/12+CRV1CTL/12). so for this example = VREF/2.*/
  59.     ACMP_CRVValue(ACMP0, 4);  
  60. /* Initial ACMP interrupt enable, wakeup function disable.*/
  61.     ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_DISABLE, ACMP_CTL_INT_ENABLE);
  62.     ENABLE_GLOBAL_INTERRUPT;                //after individal setting enable interrupt must enable global interrupt.

  63.     while(1);
  64. }





 楼主| mintspring 发表于 2019-7-26 00:29 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Website: http://www.nuvoton.com
  8. //  E-Mail : MicroC-8bit@nuvoton.com
  9. //***********************************************************************************************************

  10. //***********************************************************************************************************
  11. //  File Function: ML51 simple GPIO toggle out demo code
  12. //***********************************************************************************************************

  13. #include "ML51.h"
  14. /**
  15. * @brief       ACMP interrupt subroutine
  16. * @param       None
  17. * @return      None
  18. * @details     None
  19. */
  20. void ACMP_ISR (void) interrupt 23
  21. {
  22.   SFRS=0;
  23.   if ((ACMPSR&SET_BIT2)==SET_BIT2)
  24.   {
  25.     ACMPSR&=CLR_BIT2;
  26.     P14 ^=1;
  27.   }
  28.   else if ((ACMPSR&SET_BIT0)==SET_BIT0)
  29.   {
  30.     ACMPSR&=CLR_BIT0;
  31.     P14 ^=1;
  32.   }
  33. }

  34. /**
  35. * @brief       ACMP negtive input use Bandgap voltage
  36. * @param       None
  37. * @return      None
  38. * @details     None
  39. */
  40. void main (void)
  41. {
  42. /* Setting Multi function pin setting for GPIO toggle
  43.    * include gipo.c in Common for GPIO mode setting
  44. */
  45.     MFP_P13_GPIO;
  46.     P13_QUASI_MODE;
  47.     MFP_P14_GPIO;
  48.     P14_QUASI_MODE;
  49.   
  50.     MFP_P23_ACMP0_P1;   
  51.     MFP_P41_ACMP0_O;
  52.     P41_QUASI_MODE;
  53.    
  54. /* ACMP intial
  55.    * include acmp.c in Library for ACMP initial and interrupt setting.
  56. */
  57. /* Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1 */
  58.     ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_VBG,0, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
  59. /* Initial ACMP interrupt enable, wakeup function disable. */
  60.     ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_DISABLE, ACMP_CTL_INT_ENABLE);
  61. /*To use interrupt function, must enable blobal interrupt after all setting. */
  62.     ENABLE_GLOBAL_INTERRUPT;                     

  63.     while(1);
  64. }



 楼主| mintspring 发表于 2019-7-26 00:29 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Website: http://www.nuvoton.com
  8. //  E-Mail : MicroC-8bit@nuvoton.com
  9. //***********************************************************************************************************

  10. //***********************************************************************************************************
  11. //  File Function: ML51 simple GPIO toggle out demo code
  12. //***********************************************************************************************************

  13. #include "ML51.h"
  14. /**
  15. * @brief       ACMP interrupt subroutine
  16. * @param       None
  17. * @return      None
  18. * @details     None
  19. */
  20. void ACMP_ISR (void) interrupt 23
  21. {
  22.   if ((ACMPSR&SET_BIT2)==SET_BIT2)
  23.   {
  24.     ACMPSR&=CLR_BIT2;
  25.     SFRS = 0x00;
  26.     P13 ^=1;
  27.   }
  28.   else if ((ACMPSR&SET_BIT0)==SET_BIT0)
  29.   {
  30.     ACMPSR&=CLR_BIT0;
  31.     SFRS = 0x00;
  32.     P14 ^=1;
  33.   }  
  34. }


  35. /**
  36. * @brief       ACMP negtive input use Bandgap voltage main loop
  37. * @param       None
  38. * @return      None
  39. * @details     None
  40. */
  41. void main (void)
  42. {
  43. /* Setting Multi function pin setting for GPIO toggle
  44.    * include gipo.c in Common for GPIO mode setting
  45. */  MFP_P13_GPIO;
  46.     P13_QUASI_MODE;
  47.   
  48.     MFP_P23_ACMP0_P1;   
  49.     MFP_P24_ACMP0_N0;
  50.     MFP_P41_ACMP0_O;
  51.    
  52. /* ACMP intial
  53.    * include acmp.c in Library for ACMP initial and interrupt setting.
  54. */
  55. // Initial ACMP0 P2.3 as positive and Bandgap as negetive input, Output to P4.1
  56.     ACMP_Open(ACMP0, ACMP_CTL_POSSEL_P1, ACMP_CTL_NEGSEL_PIN_N0,0, ACMP_CTL_ACMP0_OUTPUT_ENABLE, ACMP_CTL_HYSTERESIS_ENABLE);
  57. /* Initial ACMP interrupt enable, wakeup function disable.*/
  58.     ACMP_INTEnable(ACMP0, ACMP_CTL_WAKEUP_ENABLE, ACMP_CTL_INT_ENABLE);
  59. /*To use interrupt function, must enable blobal interrupt after all setting.*/
  60.     ENABLE_GLOBAL_INTERRUPT;                     
  61.   
  62.     while (1)
  63.     {
  64.       set_PCON_PD;
  65.       Timer3_Delay(24000000,128,100,10000);
  66.     }

  67. }



 楼主| mintspring 发表于 2019-7-26 00:30 | 显示全部楼层
这个比较器非常好用,有多种使用方式,可以跟内部比较,跟外边比较,而且还可以中断。
 楼主| mintspring 发表于 2019-7-26 00:30 | 显示全部楼层
还可以输出比较结果,非常方便。
yiyigirl2014 发表于 2019-7-26 00:58 | 显示全部楼层
这个开发板多少钱
玛尼玛尼哄 发表于 2019-7-28 21:29 | 显示全部楼层
貌似比N76E 003的更多功能啊
天灵灵地灵灵 发表于 2019-7-28 22:16 | 显示全部楼层
三种用法,非常方便参考。
xixi2017 发表于 2019-7-28 23:15 | 显示全部楼层
模拟比较器还这么多使用方法。
捉虫天师 发表于 2019-7-28 23:30 | 显示全部楼层
比较器的中断经常使用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

303

主题

4972

帖子

24

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