[DemoCode下载] 外部中断的使用方法

[复制链接]
885|6
 楼主| 捉虫天师 发表于 2019-8-31 23:49 | 显示全部楼层 |阅读模式
  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. #include "ML51.h"

  11. /**
  12. * [url=home.php?mod=space&uid=247401]@brief[/url]              External pin interrupt INT0 demo
  13. * @param       None
  14. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  15. * [url=home.php?mod=space&uid=1543424]@Details[/url]     None
  16. */


  17. void INT0_ISR(void) interrupt 0          // Vector [url=home.php?mod=space&uid=72445]@[/url]  0x03
  18. {
  19. /* Clear INT0 interrupt flag */
  20.                 clr_TCON_IE0;
  21.                 printf ("\n INT0 interrupt");
  22. }


  23. void main (void)
  24. {
  25.                 MFP_P31_UART0_TXD;
  26.                 P31_QUASI_MODE;
  27.                 UART_Open(24000000,UART0_Timer1,115200);
  28.                 ENABLE_UART0_PRINTF;       
  29.        
  30. /* Define P25 multi-function pin as External pin interrupt INT0 source*/
  31.                 MFP_P25_INT0;                                                                                                                               
  32.                 P25_INPUT_MODE;
  33. /* Enable internal pull up function to wait falling edge*/
  34.                 GPIO_Pull_Enable(Port2,SET_BIT5,PullUp);
  35. /* Include exint.c in library */
  36.                 ExternPinInterrupt_Enable(INT0,Edge,Enable);
  37.                 ENABLE_GLOBAL_INTERRUPT;                                                                       
  38.                 while(1);
  39.        
  40. }








 楼主| 捉虫天师 发表于 2019-8-31 23:49 | 显示全部楼层
  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. #include "ML51.h"

  11. /**
  12. * @brief              External pin interrupt INT1 demo
  13. * @param       None
  14. * @return      None
  15. * @details     None
  16. */


  17. void INT1_ISR(void) interrupt 2          // Vector @  0x13
  18. {
  19. /* Clear INT1 interrupt flag */
  20.     clr_TCON_IE1;
  21. /* check tiny board LEDG1 to confirm into interrupt */
  22.                 P31 = ~P31;
  23. }

  24. void main (void)
  25. {
  26.                 MFP_P31_GPIO;
  27.                 P31_PUSHPULL_MODE;
  28. /* Define P24 multi-function pin as External pin interrupt INT1 source*/
  29.                 MFP_P24_INT1;                                                                                                                               
  30.                 P24_INPUT_MODE;       
  31. /* Enable P2.4 internal pull high to wait falling edge*/       
  32.                 GPIO_Pull_Enable(Port2,SET_BIT4,PullUp);       
  33. /* Include exint.c in library */
  34.                 ExternPinInterrupt_Enable(INT1,Edge,Enable);
  35. /* Include sys.c */
  36.                 ENABLE_GLOBAL_INTERRUPT;                                                                       
  37.                 while(1);
  38. }






 楼主| 捉虫天师 发表于 2019-8-31 23:50 | 显示全部楼层
这两个特别的外部中断也是为了保持跟传统51兼容而留下的。
 楼主| 捉虫天师 发表于 2019-9-10 23:59 | 显示全部楼层
这个功能很强。
yiyigirl2014 发表于 2019-9-11 00:25 | 显示全部楼层
和GPIO中断比,这种是不是更快
wanduzi 发表于 2019-9-16 23:43 | 显示全部楼层
跟51的使用方法一样。
玛尼玛尼哄 发表于 2019-9-16 23:48 | 显示全部楼层
这个还可以GPIO中断。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

216

主题

3284

帖子

7

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