Begineer need help about GPIO, PLEASE
Discussion in "ARM Development" started by mikemike Jul 19, 2008.
Sat Jul 19 2008, 07:45 pm
I'm new in arm, i don't quite understand about in the IOPIN...
for example,
#define LED 1<<24
#define KEY1 1<<16
int main(void)
{
unsigned int key = 0;
PINSEL0 = 0;
PINSEL1 = 0;
IO0DIR = LED;
IO0SET = 0x1010000; //set both P0.24 & P0.16 to high
while(1)
{
key = IO0PIN;
if(key==?) //key is pressed, will be "0"
...
...
}
}
i got a button and a led connected to P0.16 and P0.24, and i would like to read the status of the button in order to turn a led. but what value actually i need to put in the question mark??
don't know if i miss understand the concept.....
thank you
for example,
#define LED 1<<24
#define KEY1 1<<16
int main(void)
{
unsigned int key = 0;
PINSEL0 = 0;
PINSEL1 = 0;
IO0DIR = LED;
IO0SET = 0x1010000; //set both P0.24 & P0.16 to high
while(1)
{
key = IO0PIN;
if(key==?) //key is pressed, will be "0"
...
...
}
}
i got a button and a led connected to P0.16 and P0.24, and i would like to read the status of the button in order to turn a led. but what value actually i need to put in the question mark??
don't know if i miss understand the concept.....
thank you
[ Edited Sun Jul 20 2008, 10:00 am ]
Sun Jul 20 2008, 10:06 am
thank you, but i still confuse about it. if it is IO0SET = 0x1010000, so IO0PIN will read back 0x1010000?? also i don't quite understand the use of "key&(key1)"
if IO0PIN really read back 0x1010000, and "&" with key1 it becomes key1 that means the button is not pressed. if the button is pressed, it becomes 0.
don't know if i make it wrong, thank you
if IO0PIN really read back 0x1010000, and "&" with key1 it becomes key1 that means the button is not pressed. if the button is pressed, it becomes 0.
don't know if i make it wrong, thank you
Mon Jul 21 2008, 11:11 am
you can try like this.. and hope it explians itself..
now while only the led pin is set as output pin..it will efffect ony the led not the key1
so if u want the key1 to be effective high u will have to do
IODIR1 = Key1| Led1;
IOSET1 = Key1;
//and then again make key as input
IODIR1 = Led1;
hope that clears abit of your doubts...
:bye
#define LED 1<<24 #define KEY1 1<<16 int main(void) { unsigned int key = 0; PINSEL0 = 0; PINSEL1 = 0; IO0DIR = LED; // shyam: LED pin set as output.. other pins default to input IO0SET = 0x1010000; //set both P0.24 & P0.16 to high while(1) { key = IO0PIN; if((key&key1)==key1) //key is pressed, will be "0" ... ... } }
now while only the led pin is set as output pin..it will efffect ony the led not the key1
so if u want the key1 to be effective high u will have to do
IODIR1 = Key1| Led1;
IOSET1 = Key1;
//and then again make key as input
IODIR1 = Led1;
hope that clears abit of your doubts...
:bye
[ Edited Mon Jul 21 2008, 11:12 am ]
mikemike like this.
Powered by e107 Forum System