LED1 state is changed by creating an external interrupt via key S1
1 /****************************************************************************2 * File name: main.c3 * Author: Amo [www.amoMcu.com single chip microcomputer]4 * Revision: 2014-04-085 * Version: 1.06 * Description: The LED1 state is changed by creating an external interrupt via the key S17 ****************************************************************************/8#include <ioCC2540.h>9 Tentypedef unsignedCharUchar; Onetypedef unsignedint UINT; A - #defineLED1 P1_0//P1.0 Port Control LED1 - #defineKEY1 P0_1//P0.1 Port Control S1 the - - /**************************************************************************** - * Name: delayms () + * Function: Delay in milliseconds, default to 16M when system clock is not configured (very accurate with oscilloscope measurement) - * Entry parameters: msec delay parameter, the higher the value, the longer the delay + * Export parameters: None A ****************************************************************************/ at voidDelayms (UINTmsec) - { - UINTi,j; - - for(i=0; i<msec; i++) - for(j=0; j<535; J + +); in } - to /**************************************************************************** + * Name: initled () - * Function: Set the corresponding IO port of the LED lamp the * Entry parameters: None * * Export parameters: None $ ****************************************************************************/Panax Notoginseng voidInitled (void) - { theP1dir |=0x01;//P1.0 defined as output port +LED1 =0;//LED1 Light off A } the + /**************************************************************************** - * Name: Initkey () $ * Function: Set key corresponding IO port, use interrupt mode $ * Entry parameters: None - * Export parameters: None - ****************************************************************************/ the voidInitkey () - {WuyiP0ien |=0x2;//P0.1 set to interrupt Mode 1: Interrupt enable thePictl |=0x2;//Falling Edge Trigger -IEN1 |=0x20;//allow P0 port interruption; WuP0IFG =0x00;//Initialize interrupt flag bit -EA =1;//Open Total Interrupts About } $ - /**************************************************************************** - * Name: P0_isr (void) Interrupt handler function - * Description: #pragma vector = interrupt vector, followed by interrupt handler A ****************************************************************************/ + #pragmaVector = P0int_vector the__interruptvoidP0_ISR (void) - { $Delayms (Ten);//delay to shake theLED1 = ~led1;//Change the LED1 state theP0IFG =0;//Clear Interrupt Flag theP0if =0;//Clear Interrupt Flag the } - in /**************************************************************************** the * Program Entry function the ****************************************************************************/ About voidMainvoid) the { theInitled ();//set the corresponding IO port of the LED light theInitkey ();//set the S1 corresponding IO port + while(1) - { the }Bayi}
Interrupt Settings Related:
Therefore, the interrupt configuration is as follows:
Initkey void () () { p0ien |= 0x2; P0.1 set to interrupt Mode 1: Interrupt enable to pictl |= 0x2; The falling edge triggers a IEN1 |= 0x20; Allow P0 port interruption; P0IFG = 0x00; Initialization of the interrupt flag bit EA = 1; Open Total Interrupt 56}
Where the Broken subroutine is:
58/****************************************************************************59 * Name : P0_ISR (void) Interrupt handling function 60 * Description : #pragma vector = interrupt vector, followed by interrupt handler 61 ********************************************************************** /62 #pragma vector = p0int_vector __interrupt void P0_isr (void{ delayms ( (ten); Delay to shake the LED1 = ~led1; Change LED1 status P0IFG = 0; Clear Interrupt Sign p0if = 0; }
There is a question : is 7~0 a total of 8 interrupts in this interrupt function processing? To differentiate by P0IFG?
Profile: Http://pan.baidu.com/s/1dkQNs
3. Change the LED1 state (it's interrupt-register and interrupt subroutine) by pressing the key S1 to generate an external interrupt