在坛子里看到大家对回调函数的讨论,总觉得十分难。今天把中断这个测试做了,认为完全没有必要去讨论回调函数。
首先看下什么是回调函数:
如果参数是一个函数指针,调用者可以传递一个函数的地址给实现者,让实现者去调用它,这称为回调函数(Callback Function)
这就行了,我想新唐公司用这个函数就是为了不修改.S文件。象流明的每到一个中断必须修改。否则程序不好用。
下面这个程序是按键KEY2中断,我把中断函数换成任何名字,当然中断使能名字也得换,换成什么名字都好用,不信大家试试。
看了下
管脚中断使能的说明,也确实如此,大家不要要。。。。CALLBACK.吓到了,抓紧时间学习吧。
/*----------------------------------------------------------------------*/
/* Function: DrvGPIO_EnableEINT0 */
/* */
/* Parameter: */
/* TriggerType - [in] */
/* E_DRVGPIO_INT_TYPE, specify the interrupt trigger type. */
/* It could be E_IO_RISING, E_IO_FALLING or E_IO_BOTH_EDGE and */
/* it's meaning the interrupt function enable by rising egde/high level, */
/* falling edge/low level or both riging edge and falling egde. */
/* If the interrupt mode is E_MODE_LEVEL and interrupt type is */
/* E_BOTH_EDGEthen calling this API is ignored. */
/* Mode - [in] */
/* E_DRVGPIO_INT_MODE, specify the interrupt mode. */
/* It could be E_MODE_EDGE or E_MODE_LEVEL to control the interrupt is by */
/* edge trigger or by level trigger. */
/* If the interrupt mode is E_MODE_LEVEL and interrupt type is */
/* E_BOTH_EDGEthen calling this API is ignored. */
/* pfEINT0Callback - [in] */
/* It's the function pointer of the external INT0 callback function. */
/* Returns: */
/* None */
/* Description: */
/* Enable the interrupt function for external GPIO interrupt from /INT0(GPB.14) pin. */
/*---------------------------------------------------------------------------------------------------*/
上我的中断调试程序,那个INT0可以换成任何名字,如:ddllxxrr
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include "NUC1xx.h"
#include "DrvGPIO.h"
#include "DrvUART.h"
#include "DrvSYS.h"
void INT0(void)
{
printf("Interrupt\n");
}
void Delay(uint32_t counter)
{
while (counter--);
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
STR_UART_T sParam;
/* SYSCLK =>12Mhz*/
UNLOCKREG();
/* Enable 12M Crystal */
DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);
/* Switch to PLL clock */
DrvSYS_SelectHCLKSource(0);
LOCKREG();
/* Set UART0 Pin */
DrvGPIO_InitFunction(E_FUNC_UART0);
/* UART Setting */
sParam.u32BaudRate = 9600;
sParam.u8cDataBits = DRVUART_DATABITS_8;
sParam.u8cStopBits = DRVUART_STOPBITS_1;
sParam.u8cParity = DRVUART_PARITY_NONE;
sParam.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES;
/* Select UART Clock Source From 12Mhz*/
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0);
/* Set UART0 Configuration */
DrvUART_Open(UART_PORT0, &sParam);
/*---------------------------------------------------------------------------------------------------------*/
/* GPIO Interrupt Test */
/*---------------------------------------------------------------------------------------------------------*/
/* Configure general GPIO interrupt */
DrvGPIO_Open(E_GPB, 14, E_IO_INPUT);
/* Configure external interrupt */
DrvGPIO_EnableEINT0(E_IO_BOTH_EDGE, E_MODE_EDGE, INT0);
/* Waiting for interrupts */
while (1)
{
printf("Deep Sleep\n");
while (UART0->FSR.TE_FLAG == 0);
GPIOA->DOUT |= 0x7000;
UNLOCKREG();
SCB->SCR = 4;
SYSCLK->PWRCON.PD_WU_INT_EN = 0;
SYSCLK->PWRCON.PD_WAIT_CPU = 1;
SYSCLK->PWRCON.PWR_DOWN = 1;
LOCKREG();
__WFI();
}
}
效果图:
工程文件:
NUC+testINT.rar
(1.1 MB)
|