int main (void) { GPIOInit(); /* use port0_1 as input event, interrupt test. */ GPIOSetDir( PORT2, 4, 0 ); GPIOSetDir( PORT2, 1, 1 ); /* port0_1, single trigger, active high. */ GPIOSetInterrupt( PORT2, 4, 0, 0, 0 ); GPIOIntEnable( PORT2, 4 ); while( 1 ){ GPIOSetValue( PORT2, 1, 0 ); while (1){ if (val!=0){ GPIOSetValue( PORT2, 1, 1 ); }} }; } |
void PIOINT2_IRQHandler(void) { uint32_t regVal; val=1; gpio2_counter++; regVal = GPIOIntStatus( PORT2, 0 ); if ( regVal ) { p2_1_counter++; GPIOIntClear( PORT2, 0 ); } return; } |
#ifdef __USE_CMSIS #include "LPC13xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; // TODO: insert other include files here #include "gpio.h" // TODO: insert other definitions and declarations here volatile unsigned int v=0; int main(void) { volatile unsigned int tipka; GPIOInit(); //set interrupt P2.2 - red button LPC_GPIO2->DIR &= ~(0x4); //direction is input - button LPC_GPIO2->IS &= ~(0x4); //level sensitive LPC_GPIO2->IBE &= ~(0x4); //controlled by register IEV (not sure I did it correctly??) //LPC_GPIO2->IEV |= 0x4; //when I push the button then it's recognized LPC_GPIO2->IE |= (0x4); //!!!!!! //led LPC_GPIO2->DIR |= 0x2; // led had direction to be output LPC_GPIO2->DATA |= 0x2; //led is on LPC_GPIO3->DIR |= 0x1; // led had direction to be output LPC_GPIO3->DATA |= 0x1; //led is on //loop while(1){ LPC_GPIO2->DATA &= ~(0x2); // led is off while ((tipka=LPC_GPIO2->MIS) & 0x4){ LPC_GPIO2->DATA |= 0x2; //led is on only if there was interrupt } } return 0 ; } |
volatile uint32_t val=0; //this variable is added by me and corrected by ZERO |
volatile uint32_t val=0; |
volatile uint32_t val=0; //this variable is added by me and corrected by ZERO |