Discussion in "ARM Development" started by    mikemike    Jul 19, 2008.
Sat Jul 19 2008, 07:45 pm
#1
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


[ Edited Sun Jul 20 2008, 10:00 am ]
Sat Jul 19 2008, 08:58 pm
#2
its like this.
.
if(key&(key1)){
   //not pressed
}
else{
   //Pressed
}
 mikemike like this.
Sun Jul 20 2008, 10:06 am
#3
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
Mon Jul 21 2008, 11:11 am
#4
you can try like this.. and hope it explians itself..
#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.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

RodneyKnorb
Thu Apr 25 2024, 07:08 pm
Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm