[DemoCode下载] N79E715系列中断使用方法

[复制链接]
1015|5
 楼主| zhuotuzi 发表于 2016-12-29 23:52 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technology Corp.
  8. //  E-mail: MicroC-8bit@nuvoton.com
  9. //***********************************************************************************************************
  10. //  Application: Use interrupt service routine
  11. //  Set individual flag of each interrupt to execute ISR .
  12. //
  13. //  Output : P0 show result
  14. //           P1.4 flash when all interrupt pass
  15. //           P2.1 flash when all interrupt pass
  16. //           P0.7 flash when interrupt error
  17. //***********************************************************************************************************

  18. #include <stdio.h>
  19. #include "N79E715.h"
  20. #include "Typedef.h"
  21. #include "Define.h"
  22. #include "Common.h"
  23. #include "Delay.h"
  24. #include "ISR.h"
  25. #include "Version.h"
  26. bit EA_Save_bit;
  27. //-----------------------------------------------------------------------------------------------------------
  28. void Interrupt_Error(void)
  29. {
  30.     while(1)
  31.     {
  32.         P07 = 1;
  33.         Delay1ms(500);
  34.         P07 = 0;
  35.         Delay1ms(500);
  36.     }
  37. }
  38. //-----------------------------------------------------------------------------------------------------------
  39. void main(void)
  40. {
  41.     uint16_t i;
  42.     InitialUART0_Timer1(9600);                  // 9600 Baud Rate [url=home.php?mod=space&uid=72445]@[/url] 11.0592MHz
  43.     Show_Version_Number_To_PC();
  44.     printf ("\n*==========================================================================");
  45.     printf ("\n*  N79E715 Series Interrupt Sample Code.");
  46.     printf ("\n*==========================================================================\n");
  47.     TR1 = 0;                                    //Stop Timer1 for Interrupt Demo

  48.     IE   = 0x7F;
  49.     EIE  = 0xFF;
  50.     EA   = 1;

  51.     //********************** INT0 Test ***********************
  52.     P0 = 0xFF;
  53.     IT0 = 1;

  54.     set_IE0;                             // Trigger Interrupt

  55.     PCON |= SET_BIT0;                    // Enter Idle Mode

  56.     if(P0 != ~0x01)                      // Check ISR return value
  57.         Interrupt_Error();
  58.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  59.     //********************* Timer0 Test **********************
  60.     P0 = 0xFF;

  61.     set_TF0;                             // Trigger Interrupt

  62.     PCON |= SET_BIT0;                    // Enter Idle Mode

  63.     if(P0 != ~0x02)                      // Check ISR return value
  64.         Interrupt_Error();
  65.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  66.     //********************** INT1 Test ***********************
  67.     P0 = 0xFF;
  68.     IT1 = 1;

  69.     set_IE1;                             // Trigger Interrupt

  70.     PCON |= SET_BIT0;                    // Enter Idle Mode

  71.     if(P0 != ~0x03)                      // Check ISR return value
  72.         Interrupt_Error();
  73.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  74.     //********************* Timer1 Test **********************
  75.     P0 = 0xFF;

  76.     set_TF1;                             // Trigger Interrupt

  77.     PCON |= SET_BIT0;                    // Enter Idle Mode

  78.     if(P0 != ~0x04)                      // Check ISR return value
  79.         Interrupt_Error();
  80.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  81.     //********************** UART0 Test **********************
  82.     P0 = 0xFF;

  83.     set_RI;                              // Trigger Interrupt

  84.     PCON |= SET_BIT0;                    // Enter Idle Mode

  85.     if(P0 != ~0x05)                      // Check ISR return value
  86.         Interrupt_Error();
  87.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  88.     //********************* Timer2 Test **********************
  89.     P0 = 0xFF;

  90.     set_TF2;                             // Trigger Interrupt

  91.     PCON |= SET_BIT0;                    // Enter Idle Mode
  92.     /* Check ISR return value */
  93.     if(P0 != ~0x06)                      // Check ISR return value
  94.         Interrupt_Error();
  95.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  96.     //********************** I2C Test ************************
  97.     P0 = 0xFF;

  98.     set_SI;                              // Trigger Interrupt

  99.     PCON |= SET_BIT0;                    // Enter Idle Mode

  100.     if(P0 != ~0x07)                      // Check ISR return value
  101.         Interrupt_Error();
  102.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  103.     //********************** KBI Test ************************
  104.     P0 = 0xFF;

  105.     set_KBIF0;                           // Trigger Interrupt

  106.     PCON |= SET_BIT0;                    // Enter Idle Mode

  107.     if(P0 != ~0x08)                      // Check ISR return value
  108.         Interrupt_Error();
  109.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  110.     //********************** BOD Test ************************
  111.     P0 = 0xFF;

  112.     set_BOF;                             // Trigger Interrupt

  113.     PCON |= SET_BIT0;                    // Enter Idle Mode

  114.     if(P0 != ~0x09)                      // Check ISR return value
  115.         Interrupt_Error();
  116.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  117.     //********************** SPI Test ************************
  118.     P0 = 0xFF;
  119.                                          // Trigger Interrupt
  120.     set_SPIF;

  121.     PCON |= SET_BIT0;                    // Enter Idle Mode

  122.     if(P0 != ~0x0A)                      // Check ISR return value
  123.         Interrupt_Error();
  124.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  125.     //******************* Watch Dog Test *********************
  126.     P0 = 0xFF;

  127.     set_WDTF;                            // Trigger Interrupt

  128.     PCON |= SET_BIT0;                    // Enter Idle Mode

  129.     if(P0 != ~0x0B)                      // Check ISR return value
  130.         Interrupt_Error();
  131.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  132.     //********************** ADC Test ************************/
  133.     P0 = 0xFF;

  134.     set_ADCI;                            // Trigger Interrupt

  135.     PCON |= SET_BIT0;                    // Enter Idle Mode

  136.     if(P0 != ~0x0C)                      // Check ISR return value
  137.         Interrupt_Error();
  138.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  139.     //******************** Capture Test **********************
  140.     P0 = 0xFF;

  141.     set_CAPF0;                           // Trigger Interrupt

  142.     PCON |= SET_BIT0;                    // Enter Idle Mode

  143.     if(P0 != ~0x0D)                      // Check ISR return value
  144.         Interrupt_Error();
  145.     for(i = 0 ; i < 60000 ; i++);        // Delay time
  146.     //********************** PWM Test ************************
  147.     P0 = 0xFF;

  148.     set_BKF;                             // Trigger Interrupt

  149.     PCON |= SET_BIT0;                    // Enter Idle Mode

  150.     if(P0 != ~0x0E)                      // Check ISR return value
  151.         Interrupt_Error();
  152.     for(i = 0 ; i < 60000 ; i++);        // Delay time

  153.     EA = 0;                              // Disable all interrupt
  154.     InitialUART0_Timer1(9600);           // 9600 Baud Rate @ 11.0592MHz
  155.     printf("\nInterrupt Test OK!");
  156.     while(1)
  157.     {
  158.         P14 = 1;
  159.         P21 = 1;
  160.         Delay1ms(500);
  161.         P14 = 0;
  162.         P21 = 0;
  163.         Delay1ms(500);
  164.     }
  165. }
  166. //-----------------------------------------------------------------------------------------------------------
  167. void INT0_ISR(void) interrupt 0          // Vector @  0x03
  168. {
  169.     P0 = 0xFF-1;
  170.     clr_IE0;
  171. }
  172. //-----------------------------------------------------------------------------------------------------------
  173. void Timer0_ISR(void) interrupt 1        // Vector @  0x0B
  174. {
  175.     P0 = 0xFF-2;
  176.     clr_TF0;
  177. }
  178. //-----------------------------------------------------------------------------------------------------------
  179. void INT1_ISR(void) interrupt 2          // Vector @  0x13
  180. {
  181.     P0 = 0xFF-3;
  182.     clr_IE1;
  183. }
  184. //-----------------------------------------------------------------------------------------------------------
  185. void Timer1_ISR(void) interrupt 3        // Vector @  0x1B
  186. {
  187.     P0 = 0xFF-4;
  188.     clr_TF1;
  189. }
  190. //-----------------------------------------------------------------------------------------------------------
  191. void UART0_ISR(void) interrupt 4         // Vector @  0x23
  192. {
  193.     P0 = 0xFF-5;
  194.     clr_RI;
  195. }
  196. //-----------------------------------------------------------------------------------------------------------
  197. void Timer2_ISR(void) interrupt 5        // Vector @  0x2B
  198. {
  199.     P0 = 0xFF-6;
  200.     clr_TF2;
  201. }
  202. //-----------------------------------------------------------------------------------------------------------
  203. void I2C_ISR(void) interrupt 6           // Vector @  0x33
  204. {
  205.     P0 = 0xFF-7;
  206.     clr_SI;
  207. }
  208. //-----------------------------------------------------------------------------------------------------------
  209. void KBI_ISR(void) interrupt 7           // Vector @  0x3B
  210. {
  211.     P0 = 0xFF-8;
  212.     clr_KBIF0;
  213. }
  214. //-----------------------------------------------------------------------------------------------------------
  215. void BOD_ISR(void) interrupt 8           // Vector @  0x43
  216. {
  217.     P0 = 0xFF-9;
  218.     clr_BOF;
  219. }
  220. //-----------------------------------------------------------------------------------------------------------
  221. void SPI_ISR(void) interrupt 9           // Vector @  0x4B
  222. {
  223.     P0 = 0xFF-10;
  224.     clr_SPIF;
  225. }
  226. //-----------------------------------------------------------------------------------------------------------
  227. void WDT_ISR(void) interrupt 10          // Vector @  0x53
  228. {
  229.     P0 = 0xFF-11;
  230.     clr_WDTF;
  231. }
  232. //-----------------------------------------------------------------------------------------------------------
  233. void ADC_ISR(void) interrupt 11          // Vector @  0x5B
  234. {
  235.     P0 = 0xFF-12;
  236.     clr_ADCI;
  237. }
  238. //-----------------------------------------------------------------------------------------------------------
  239. void Capture_ISR(void) interrupt 12      // Vector @  0x63
  240. {
  241.     P0 = 0xFF-13;
  242.     clr_CAPF0;
  243. }
  244. //-----------------------------------------------------------------------------------------------------------
  245. void PWM_Brake_ISR(void) interrupt 14    // Vector @  0x73
  246. {
  247.     P0 = 0xFF-14;
  248.     clr_BKF;
  249. }
  250. //-----------------------------------------------------------------------------------------------------------








 楼主| zhuotuzi 发表于 2016-12-29 23:53 | 显示全部楼层
我们可以从例程看出来,该例程包含了所有的中断源的中断使用方法。
dongnanxibei 发表于 2016-12-30 00:00 | 显示全部楼层
没想到这个芯片支持这么多种中断方式。
gejigeji521 发表于 2016-12-30 00:07 | 显示全部楼层
竟然还可以用于捕获的操作,给力。
 楼主| zhuotuzi 发表于 2016-12-30 17:11 | 显示全部楼层
备注里给出了中断向量地址,可以明显的看清楚是多少个中断源可以触发
墙上的咖啡 发表于 2016-12-30 19:55 | 显示全部楼层
中断看上去和51没什么区别的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

214

主题

3375

帖子

7

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