1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
| void PIOINT0_IRQHandler(void)
{
uint32_t regVal;
unsigned int i,j;
gpioSetValue(0,2,0);
for(i = 0 ;i < 500; i++)
for(j = 0; j < 10000; j++);
gpio0_counter++;
regVal = gpioIntStatus(0, 1);
if (regVal)
{
p0_1_counter++;
gpioIntClear(0, 1);
}
return;
}
int main(void)
{
SystemCoreClockUpdate();
gpioInit(); //initialize gpio clock
gpioSetDir(0,1,0); //set pin 0.1 as input
gpioSetDir(0,2,1); //set pin 0.2 as output
GPIOSetInterrupt(0,1,0,0,1); //set interrupt on pin 0.1
gpioIntEnable(0,1); //enable interrupt
while(1);
}
void gpioInit(void)
{
/* Enable AHB clock to the GPIO domain. */
LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_GPIO;
/* Set up NVIC when I/O pins are configured as external interrupts. */
NVIC_EnableIRQ(EINT0_IRQn);
return;
}
void gpioIntEnable(unsigned char portNum,unsigned char bitPos)
{
switch (portNum)
{
case PORT0:
LPC_GPIO0->IE |= (0x1<<bitPos);
break;
case PORT1:
LPC_GPIO1->IE |= (0x1<<bitPos);
break;
case PORT2:
LPC_GPIO2->IE |= (0x1<<bitPos);
break;
case PORT3:
LPC_GPIO3->IE |= (0x1<<bitPos);
break;
default:
break;
}
return;
} |