[技术问答] 第一次接触新唐,NANO100请问为什么进不去外部中断

[复制链接]
2507|6
 楼主| 周大侠的 发表于 2017-11-20 21:21 | 显示全部楼层 |阅读模式
uint8_t flagbit=0;


void NVIC_GPIO_Init(void)
{
//        GPIO_SetMode(PA,BIT10|BIT11,GPIO_INT_LOW);//
        GPIO_SetMode(PA,BIT10,GPIO_INT_LOW);//
}
void NVIC_Init(void)
{
        NVIC_GPIO_Init();
        NVIC_EnableIRQ(GPABC_IRQn);//ʹÄÜ
        NVIC_SetPriority(GPABC_IRQn,3);//ÓÅÏȼ¶ÉèÖÃ
}

void GPABC_IRQHandler(void)
{
        if(INIT1_PRES==0)
        {
                Delay_ms(10);
        }
        if(INIT1_PRES)flagbit=1;
        while(INIT1_PRES==0);

        NVIC_ClearPendingIRQ(GPABC_IRQn);


}


 楼主| 周大侠的 发表于 2017-11-20 21:28 | 显示全部楼层
没有大婶吗
643757107 发表于 2017-11-21 08:46 | 显示全部楼层
用的哪个型号啊,这个好像分A和B
643757107 发表于 2017-11-21 08:58 | 显示全部楼层
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V2.10
  4. * $Date: 15/07/20 9:38a $
  5. * [url=home.php?mod=space&uid=247401]@brief[/url]    Use GPIO driver to control the GPIO pin direction and the high/low state,
  6. *           and show how to use GPIO interrupts.
  7. *
  8. * @note
  9. * Copyright (C) 2012 Nuvoton Technology Corp. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. #include <stdio.h>
  13. #include "nano100series.h"

  14. /**
  15. * @brief       PortA/PortB/PortC IRQ
  16. *
  17. * @param       None
  18. *
  19. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  20. *
  21. * [url=home.php?mod=space&uid=1543424]@Details[/url]     The PortA/PortB/PortC default IRQ, declared in startup_nano100series.s.
  22. */
  23. void GPABC_IRQHandler(void)
  24. {
  25.     /* To check if PB.5 interrupt occurred */
  26.     if (PB->ISRC & BIT5) {
  27.         PB->ISRC = BIT5;
  28.         PD0 = PD0 ^ 1;
  29.         printf("PB.5 INT occurred. \n");

  30.     } else {
  31.         /* Un-expected interrupt. Just clear all PORTA, PORTB, PORTC interrupts */
  32.         PA->ISRC = PA->ISRC;
  33.         PB->ISRC = PB->ISRC;
  34.         PC->ISRC = PC->ISRC;
  35.         printf("Un-expected interrupts. \n");
  36.     }
  37. }


  38. /**
  39. * @brief       PortD/PortE/PortF IRQ
  40. *
  41. * @param       None
  42. *
  43. * @return      None
  44. *
  45. * @details     The PortD/PortE/PortF default IRQ, declared in startup_nano100series.s.
  46. */
  47. void GPDEF_IRQHandler(void)
  48. {
  49.     /* To check if PE.2 interrupt occurred */
  50.     if (PE->ISRC & BIT2) {
  51.         PE->ISRC = BIT2;
  52.         PD0 = PD0 ^ 1;
  53.         printf("PE.2 INT occurred. \n");
  54.     } else {
  55.         /* Un-expected interrupt. Just clear all PORTD, PORTE and PORTF interrupts */
  56.         PD->ISRC = PD->ISRC;
  57.         PE->ISRC = PE->ISRC;
  58.         PF->ISRC = PF->ISRC;
  59.         printf("Un-expected interrupts. \n");
  60.     }
  61. }


  62. /**
  63. * @brief       External INT0 IRQ
  64. *
  65. * @param       None
  66. *
  67. * @return      None
  68. *
  69. * @details     The External INT0(PA.2) default IRQ, declared in startup_nano100series.s.
  70. */
  71. void EINT0_IRQHandler(void)
  72. {
  73.     /* For PB.14, clear the INT flag */
  74.     PB->ISRC = BIT14;
  75.     PD0 = PD0 ^ 1;
  76.     printf("PB.14 EINT0 occurred. \n");
  77. }


  78. /**
  79. * @brief       External INT1 IRQ
  80. *
  81. * @param       None
  82. *
  83. * @return      None
  84. *
  85. * @details     The External INT1(PF.2) default IRQ, declared in startup_Nano100series.s.
  86. */
  87. void EINT1_IRQHandler(void)
  88. {
  89.     /* For PB.15, clear the INT flag */
  90.     PB->ISRC = BIT15;
  91.     PD0 = PD0 ^ 1;
  92.     printf("PB.15 EINT1 occurred. \n");
  93. }

  94. void SYS_Init(void)
  95. {
  96.     /* Unlock protected registers */
  97.     SYS_UnlockReg();

  98.     /* Enable external 12MHz HXT */
  99.     CLK_EnableXtalRC(CLK_PWRCTL_HXT_EN_Msk);
  100.     CLK_EnablePLL(CLK_PLLCTL_PLL_SRC_HXT, 96000000);
  101.     /* Waiting for clock ready */
  102.     CLK_WaitClockReady(CLK_CLKSTATUS_HXT_STB_Msk | CLK_CLKSTATUS_PLL_STB_Msk);

  103.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_HCLK_CLK_DIVIDER(3));

  104.     /* Select IP clock source */
  105.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_UART_CLK_DIVIDER(1));
  106.     /* Enable IP clock */
  107.     CLK_EnableModuleClock(UART0_MODULE);

  108.     /*---------------------------------------------------------------------------------------------------------*/
  109.     /* Init I/O Multi-function                                                                                 */
  110.     /*---------------------------------------------------------------------------------------------------------*/
  111.     /* Set PA multi-function pins for UART0 RXD and TXD */
  112. //    SYS->PA_H_MFP &= ~( SYS_PA_H_MFP_PA15_MFP_Msk | SYS_PA_H_MFP_PA14_MFP_Msk);
  113. //    SYS->PA_H_MFP |= (SYS_PA_H_MFP_PA15_MFP_UART0_TX|SYS_PA_H_MFP_PA14_MFP_UART0_RX);
  114.     SYS->PB_L_MFP &= ~( SYS_PB_L_MFP_PB0_MFP_Msk | SYS_PB_L_MFP_PB1_MFP_Msk);
  115.     SYS->PB_L_MFP |= (SYS_PB_L_MFP_PB1_MFP_UART0_TX|SYS_PB_L_MFP_PB0_MFP_UART0_RX);

  116.     /* Lock protected registers */
  117.     SYS_LockReg();
  118. }

  119. void UART0_Init(void)
  120. {
  121.     /* Reset IP */
  122.     SYS_ResetModule(UART0_RST);
  123.     UART0->BAUD = 0x67;              /* Baud Rate:115200  OSC:12MHz */
  124.     UART0->TLCTL = 0x03;             /* Character len is 8 bits */
  125. }

  126. /*---------------------------------------------------------------------------------------------------------*/
  127. /* MAIN function                                                                                           */
  128. /*---------------------------------------------------------------------------------------------------------*/
  129. int main (void)
  130. {
  131.     int32_t i32Err;

  132.     /* Init System, IP clock and multi-function I/O */
  133.     SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

  134.     /* Init UART for printf */
  135.     UART0_Init();

  136.     printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);

  137.     printf("+--------------------------------------+ \n");
  138.     printf("|    NANO100 GPIO Driver Sample Code   | \n");
  139.     printf("+--------------------------------------+ \n");

  140.     /*-----------------------------------------------------------------------------------------------------*/
  141.     /* GPIO Basic Mode Test --- Use Pin Data Input/Output to control GPIO pin                              */
  142.     /*-----------------------------------------------------------------------------------------------------*/
  143.     printf("  >> Please connect PA.0 and PA.1 first << \n");
  144.     printf("     Press any key to start test by using [Pin Data Input/Output Control] \n\n");
  145.     getchar();

  146.     /* Configure PA.0 as Output mode and PA.1 as Input mode then close it */
  147.     GPIO_SetMode(PA, BIT0, GPIO_PMD_OUTPUT);
  148.     GPIO_SetMode(PA, BIT1, GPIO_PMD_INPUT);

  149.     i32Err = 0;
  150.     printf("  GPIO Output/Input test ...... \n");

  151.     /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */
  152.     PA0 = 0;
  153.     CLK_SysTickDelay(10);   /* wait for IO stable */
  154.     if (PA1 != 0) {
  155.         i32Err = 1;
  156.     }

  157.     PA0 = 1;
  158.     CLK_SysTickDelay(10);   /* wait for IO stable */
  159.     if (PA1 != 1) {
  160.         i32Err = 1;
  161.     }

  162.     if ( i32Err ) {
  163.         printf("  [FAIL] --- Please make sure PA.0 and PA.1 are connected. \n");
  164.     } else {
  165.         printf("  [OK] \n");
  166.     }

  167.     /* Configure PA.0 and PA.1 to default Input mode */
  168.     GPIO_SetMode(PA, BIT0, GPIO_PMD_INPUT);
  169.     GPIO_SetMode(PA, BIT1, GPIO_PMD_INPUT);


  170.     /*-----------------------------------------------------------------------------------------------------*/
  171.     /* GPIO Interrupt Function Test                                                                        */
  172.     /*-----------------------------------------------------------------------------------------------------*/
  173.     printf("\n  GPB5, GPE2, GPB14(EINT0) and GPB15(EINT1) are used to test interrupt\n  and control LED (GPA7)\n");

  174.     /*Configure PA7 for LED control */
  175.     GPIO_SetMode(PA, BIT7, GPIO_PMD_OUTPUT);

  176.     /* Configure PB5 as Input mode and enable interrupt by rising edge trigger */
  177.     GPIO_SetMode(PB, BIT5, GPIO_PMD_INPUT);
  178.     GPIO_ENABLE_PULL_UP(PB, BIT5);
  179.     GPIO_EnableInt(PB, 5, GPIO_INT_RISING);

  180.     NVIC_EnableIRQ(GPABC_IRQn);

  181.     /*  Configure PE2 as Input mode pull-up and enable interrupt by low level trigger */
  182.     GPIO_SetMode(PE, BIT2, GPIO_PMD_INPUT);
  183.     GPIO_ENABLE_PULL_UP(PE, BIT2);
  184.     GPIO_EnableInt(PE, 2, GPIO_INT_LOW);

  185.     NVIC_EnableIRQ(GPDEF_IRQn);

  186.     /* Configure PB14 as EINT0 pin and enable interrupt by falling edge trigger */
  187.     SYS->PB_H_MFP = (SYS->PB_H_MFP & (~0x07000000)) | 0x01000000;
  188.     GPIO_SetMode(PB, BIT14, GPIO_PMD_INPUT);
  189.     GPIO_EnableEINT0(PB, 14, GPIO_INT_FALLING);
  190.     NVIC_EnableIRQ(EINT0_IRQn);

  191.     /* Configure PB15 as EINT1 pin and enable interrupt by rising and falling edge trigger */
  192.     SYS->PB_H_MFP = (SYS->PB_H_MFP & (~0x70000000)) | 0x10000000;
  193.     GPIO_SetMode(PB, BIT15, GPIO_PMD_INPUT);
  194.     GPIO_EnableEINT1(PB, 15, GPIO_INT_BOTH_EDGE);
  195.     NVIC_EnableIRQ(EINT1_IRQn);

  196.     /* Enable interrupt de-bounce function and select de-bounce sampling cycle time */
  197.     GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_HCLK, GPIO_DBCLKSEL_1);
  198.     GPIO_ENABLE_DEBOUNCE(PB, BIT5);
  199.     GPIO_ENABLE_DEBOUNCE(PE, BIT2);
  200.     GPIO_ENABLE_DEBOUNCE(PB, BIT14);
  201.     GPIO_ENABLE_DEBOUNCE(PB, BIT15);

  202.     /* Waiting for interrupts */
  203.     while (1);

  204. }


643757107 发表于 2017-11-21 08:58 | 显示全部楼层
这个是关于所有IO的中断操作例子。。
zhuotuzi 发表于 2017-11-21 15:21 | 显示全部楼层
根据楼上朋友的例子问题解决了吧。
wanduzi 发表于 2017-11-21 18:56 | 显示全部楼层
没有配置正确。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

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