⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 button.c

📁 AT91所有开发板的资料 AT91所有开发板的资料
💻 C
字号:

/**************************************************************************
 *
 * ARM - Strategic Support Group
 *
 **************************************************************************/

/***************************************************************************
 *
 * Title	: Button
 * Module	: button.c
 * Description 	:
 *
 *    Services the button being pressed and toggles LED(1)
 *
 * Platform	: AEB-1 / KPI-00041a
 * Status	: PROTOTYPE
 * History	:
 *
 *	990929 ASloss
 *	
 *		started working on button.c 	
 *
 **************************************************************************/

/**************************************************************************
 * IMPORTS
 **************************************************************************/

#include "led.h"
#include "macros.h"

/**************************************************************************
 * MACROS
 **************************************************************************/

// none...

/**************************************************************************
 * STATICS
 **************************************************************************/

static int toggle = 0;

/**************************************************************************
 * IMPORTS
 **************************************************************************/

/*
 * Update the register on the target which masks the irq passed to the IC.
 * This routine is target-specific.  Turn the interrupt source off.
 */
void uHALir_MaskIrq(unsigned irq) 
{

   *(volatile int*)INTMSK |= (1 << irq);

}

/*
 * Update the register on the target which masks the irq passed to the IC.
 * This routine is target-specific.  Turn the interrupt source on.
 */
void uHALir_UnmaskIrq(unsigned irq1,unsigned irq2) 
{

   *(volatile int*)INTMSK &= ~((1 << INT_GLOBAL) | (1<<irq1) | (1<<irq2));   /* Force global disable OFF */

}


/* -- button_init ---------------------------------------------------------
 *                                                            
 * Description  :  Initialises the button interrupt    
 *
 * Parameters   : none...   
 * Return       : none...
 * Notes        : none...
 *                                                                             
 */

void button_init (void)
{	
	// Bitwise OR incase an existing set of Interrupts have been .....
	// set by Angel Debug Monitor ....................................
		
	uHALir_UnmaskIrq(10,0);	

  *(unsigned *)IOPCON 	|= IO_ENABLE_INT0; 			// enable int0
  *(unsigned *)IOPCON	|= IO_ACTIVE_HIGH_INT0; 	// set as active high
  *(unsigned *)IOPCON	|= IO_RISING_EDGE_INT0;		// allow for RISING EDGE
}

/* -- button_pressed ----------------------------------------------------
 *
 * Description	: The interrupt button has been pressed. Toggles D1 LED...
 *
 * Parameters	: none...
 * Return	: none...
 * Notes	: none...
 *
 */

void button_pressed (void)
{
	if( toggle == 0 ) {
	toggle = 1;
	LED_1_ON;
	} else {
	toggle = 0;
	LED_1_OFF;
	}

	
	// add user function code here...
}

/* -- button_irq  ----------------------------------------------------------
 *
 * Description  : handles the button press interrupt...
 *
 * Parameters   : none...
 * Return       : none...
 * Notes        : none...
 *
 */ 

void  button_irq (void) 
{
   /* Read in the Interrupt source .................................. */
	
	*(unsigned *) INTPND |= INT_SW3_MASK;

	button_pressed ();		// Call toggle LED's.......	
}

/**************************************************************************
 * End of button.c
 **************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -