I wrote a program related to Event Handling. The program means that - whenever button is pressed, led(B2) must glow in STARTKIT.
I took the condition "pressing button" inside case , which leads to the occurring of event(glowing led as the event).
1 error ccurred at case statement(parse error before '(' token. ).
What is this error?
PROGRAM CODE:
#include <xs1.h>
#include <timer.h>
#include<stdio.h>
port p=XS1_PORT_32A;
int led=~(1<<11);
int delay=1000;
int main()
{
unsigned int b=0x00000000;
select
{
case b when (~b & 0x0000001):
p:> b;
p<:~(1<<11);
printf("event occurred");
break;
return 0;
}
}
About event handling in startkit device Topic is solved
-
- Member++
- Posts: 17
- Joined: Fri Dec 26, 2014 4:41 pm
-
- XCore Addict
- Posts: 158
- Joined: Thu Mar 20, 2014 8:04 am
hi,
select statement enables the events on the resources (channels, timers,) and waits for them to occur.
in that context, "case b when (~b & 0x0000001):" does not sound correct; pls double check what you want to achieve here.
'return 0;' //to be moved out of the select block isn't it!?
select statement enables the events on the resources (channels, timers,) and waits for them to occur.
in that context, "case b when (~b & 0x0000001):" does not sound correct; pls double check what you want to achieve here.
'return 0;' //to be moved out of the select block isn't it!?
You should do something like this:
#include <xs1.h>
#include <timer.h>
#include<stdio.h>
port p=XS1_PORT_32A;
int led=~(1<<11);
int delay=1000;
int app()
{
unsigned int b=0x00000000;
unsigned port_value;
p:> port_value;
while(1)
{
select
{
case p when pinsneq(port_value & 0x0000001):> port_value:
p:> b;
p<:~(1<<11);
printf("event occurred");
break;
}
}
return 0;
}
int main()
{
par
{
app();
}
return 0;
}
#include <xs1.h>
#include <timer.h>
#include<stdio.h>
port p=XS1_PORT_32A;
int led=~(1<<11);
int delay=1000;
int app()
{
unsigned int b=0x00000000;
unsigned port_value;
p:> port_value;
while(1)
{
select
{
case p when pinsneq(port_value & 0x0000001):> port_value:
p:> b;
p<:~(1<<11);
printf("event occurred");
break;
}
}
return 0;
}
int main()
{
par
{
app();
}
return 0;
}