free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
mikemike
Sat Jul 19 2008, 07:15AM
 User Offline
Registered Member #6498
Joined: Fri Mar 07 2008, 12:09AM

Posts: 6
Thanked 0 times in 0 posts
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 Sat Jul 19 2008, 09:30PM ]
Back to top


Ajay
Sat Jul 19 2008, 08:28AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3681
Thanked 684 times in 646 posts
its like this.
.
CODE:
if(key&(key1)){
   //not pressed
}
else{
   //Pressed
}
 


www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top



This post has been thanked 1 time
 mikemike 
mikemike
Sat Jul 19 2008, 09:36PM
 User Offline
Registered Member #6498
Joined: Fri Mar 07 2008, 12:09AM

Posts: 6
Thanked 0 times in 0 posts
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
Back to top


shyam
Sun Jul 20 2008, 10:41PM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 719
Thanked 107 times in 103 posts
you can try like this.. and hope it explians itself..
CODE:

#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...



[ Edited Sun Jul 20 2008, 10:42PM ]

lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top



This post has been thanked 1 time
 mikemike 
 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems