CC2530————Interrupt mode control LED lights

the definition #include "ioCC2530.h" // references the header file that contains the CC2530 registers, interrupt vectors, etc.
/ ********************************************************** *******************************************/

#define LED1 P1_0 // P1_0 is defined as P1.0
#define SW1 P1_2 // P1_2 is defined as SW1

/*********************************************************************

  • Function name: init

  • Function: Initialize the system IO, so that the P1_2 pin can accept and process interrupts

  • Entry parameters: none

  • Export parameters: none

  • Return value: None
    ************************************************ **********************/
    void init()
    {//P1SEL &=~0x3D; // Set LED1 and SW1 as ordinary IO ports
    P1DIR |= 0x39 ; // Set LED1 as output
    P1DIR &= ~0x04; //Sw1 button is at P1.2, set as input
    P1 &= ~0x39;
    PICTL &= ~0x02; //Configure the interrupt edge of port P1 as rising edge generation Interrupt
    P1IEN |= 0x04; //Enable P1.2 interrupt
    IEN2 |= 0x10; //Enable P1 port interrupt

    EA = 1; //Enable global interrupt
    )

/*********************************************************************

  • Function name: EINT_ISR
  • Function: external interrupt service function
  • Entry parameters: none
  • Export parameters: none
  • Return value: None
    ************************************************ ********************* /
    #pragma vector=P1INT_VECTOR
    __interrupt void P1_INT(void)
    { EA = 0; // Close the global interrupt /

    if it is generated by P1.2 Interrupt*/
    if(P1IFG & 0x04)
    { LED1=!LED1; P1IFG &= ~0x04; // Clear P1.2 interrupt flag } EA = 1; // Enable global interrupt }




/*********************************************************************

  • Function name: main
  • Function: main function entrance
  • Entry parameters: none
  • Export parameters: none
  • Return value: None
    ************************************************ **********************/
    void main(void)
    { init(); //Call the initialization function while(1) { } }




Guess you like

Origin blog.csdn.net/News53231323/article/details/113186890