The push buttons and LEDs are available on PORTF. //******************************************** //******************************************** // // Definitions for LEDs and push buttons // //********************************************* //********************************************* //PORTF: // |1 1 1 1 | 1 1 | | | // |5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 | // |--------|---------|---------|---------| // | | | | | // |x x x x | L L L L | L L P P | P P x x | // |x x x x | E E E E | E E B B | B B x x | // |x x x x | D D D D | D D 4 3 | 2 1 x x | // | | 6 5 4 3 | 2 1 | | // | | | | | // // // #include //mask for LEDs #define LED_MASK (0x0FC0) //mask for push buttons #define PB_MASK (0x003C) #define LED1_PORTF (0x0040) #define LED2_PORTF (0x0080) #define LED3_PORTF (0x0100) #define LED4_PORTF (0x0200) #define LED5_PORTF (0x0400) #define LED6_PORTF (0x0800) #define LED_ALL (LED1_PORTF|LED2_PORTF|LED3_PORTF|LED4_PORTF|LED5_PORTF|LED6_PORTF) int iLEDState = 0; #define PB1_PORTF (0x0004) #define PB2_PORTF (0x0008) #define PB3_PORTF (0x0010) #define PB4_PORTF (0x0020) #define PB_ALL (PB1_PORTF|PB2_PORTF|PB3_PORTF|PB4_PORTF) // ------ END of definitions for LEDs and push buttons ------ int iPortflag; // Example for reading the push buttons //read port F iPortflag=*pPORTFIO; //clear all pending events *pPORTFIO_CLEAR = PB_MASK; // the buttons' state are available in iPortflag if (iPortflag&PB2_PORTF){ // here comes the program code belonging to pushed button 2 } // The LEDs can be set and clear in the following way: // 1. the LEDs can be set by writing the bit belonging to the LED in register *pPORTFIO_SET // 2. the LEDs can be cleared by writing the bit belonging to the LED in register *pPORTFIO_CLEAR //Example: iLEDState |= LED3_PORTF; // set LED 3 iLEDState &= ~LED4_PORTF; // clear LED 4 *pPORTFIO_SET = iLEDState&LED_MASK; //set the bits *pPORTFIO_CLEAR = (~iLEDState)&LED_MASK; //clear the bits