打印
[DemoCode下载]

普通IO中断实现

[复制链接]
751|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
捉虫天师|  楼主 | 2019-8-31 23:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

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

//***********************************************************************************************************
//  File Function: ML51 pin interrupt demo code
//***********************************************************************************************************

#include "ML51.h"

/**
* [url=home.php?mod=space&uid=247401]@brief[/url]       Port0~5 Interrupt Subroutine
* @param       None
* [url=home.php?mod=space&uid=266161]@return[/url]      None
* [url=home.php?mod=space&uid=1543424]@Details[/url]     PIF 0~7 declair in GPIO_EnableInt interrupt.
*/
void PinInterrupt_ISR (void) interrupt 7
{
    if ((PIF&SET_BIT0)==SET_BIT0)
    {
      PIF&=CLR_BIT0;
      P30 = ~P30;
      printf ("\n PIT0 INT");
    }
    else if ((PIF&SET_BIT3)==SET_BIT3)
    {
      PIF&=CLR_BIT3;
      P30 = ~P30;
      printf ("\n PIT3 INT");
    }
}


void main (void)
{                             
/* Setting Multi function pin setting for GPIO toggle
   * include gipo.c in Library for GPIO mode setting
*/
    MFP_P30_GPIO;
    P30_PUSHPULL_MODE;                            /* set P1.2 as PushPull output mode */
  /*
For UART0 P3.1 as TXD output setting use VCOM function.
* include uart.c in Library Setting for UART0
*/
    MFP_P31_UART0_TXD;                            /* UART0 TXD use P31 */
    P31_QUASI_MODE;                               /* set P3.1 Quasi mode for UART0 trasnfer */
    UART_Open(24000000,UART0_Timer1,115200);      /* Open UART0 use timer1 as baudrate generate and baud rate = 115200 */
    ENABLE_UART0_PRINTF;                                   /* to use printf function, need set TI first. */

/* Setting Pin interrupt initial
   * include pinint.c in Library for GPIO mode setting
*/
    MFP_P25_GPIO;
    P25_INPUT_MODE;                               /* set P2.5 as input output mode */
    GPIO_Pull_Enable(Port2,SET_BIT5,PullUp);
    GPIO_EnableInt(PIT0,FALLING,EDGE,2,5);         /* Setting pin intterrupt channel 0 as P2.5 falling edge trigger. */
    MFP_P32_GPIO;
    P32_INPUT_MODE;                               /* set P3.2 as input output mode */
    GPIO_Pull_Enable(Port3,SET_BIT2,PullDown);
    GPIO_EnableInt(PIT3,RISING,EDGE,3,2);          /* Setting pin intterrupt channel 3 as P3.2 rising edge trigger. */
    ENABLE_GLOBAL_INTERRUPT;

    while(1);
}





使用特权

评论回复
沙发
捉虫天师|  楼主 | 2019-8-31 23:51 | 只看该作者
确实没有传统中断的独立入口那种操作简单,响应快

使用特权

评论回复
板凳
antusheng| | 2019-9-4 08:46 | 只看该作者
普通的基本上所有IO都可以

使用特权

评论回复
地板
643757107| | 2019-9-4 21:30 | 只看该作者
这都是从ARM单片机借鉴过来的

使用特权

评论回复
5
dongnanxibei| | 2019-9-4 23:23 | 只看该作者
那些特别寄存器操作还保留了。

使用特权

评论回复
6
heisexingqisi| | 2019-9-4 23:52 | 只看该作者
这种用宏表示方式非常容易阅读

使用特权

评论回复
7
huahuagg| | 2019-9-5 15:06 | 只看该作者
好像所有的IO端口都可以实现

使用特权

评论回复
8
huangcunxiake| | 2019-9-5 15:28 | 只看该作者
使能全局中断,51的特有风格

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

178

主题

3007

帖子

7

粉丝