Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Phataas
PostPosted: Jan 30, 2012 - 01:42 AM
Rookie


Joined: May 04, 2011
Posts: 26


Any idea why this does not work?

Thanks in advance!

Code:
      PORTB.OUT = (PORTE_IN << 4);      //This one works!
      put_on_leds(0xAA);                //This one works!
      put_on_leds((PORTE_IN << 4));     //This one DO NOT work :(




Code:
 void put_on_leds(uint8_t value)
 {
    PORTB.OUT = (value << 4);
 }


Last edited by Phataas on Jan 30, 2012 - 02:13 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
Levenkay
PostPosted: Jan 30, 2012 - 01:52 AM
Resident


Joined: Dec 20, 2007
Posts: 943
Location: Portland, Oregon, USA

Phataas wrote:
Any idea why this does not work?

Thanks in advance!

Code:
      PORTB.OUT = (PORTE_IN << 4);      //This one works!
      put_on_leds(0xAA);                //This one works!
      put_on_leds((PORTE_IN << 4));     //This one DO NOT work :(
That all depends on what you've #define-d "PORTE_IN" to be, and what the function prototype for "put_on_leds()" is, if it's even a function (for all we know, it could be a macro, too). Such nonstandard macros as that are touted as making the code "clearer". Only they sure don't seem to be living up to that billing in this case, do they?
 
 View user's profile Send private message  
Reply with quote Back to top
Phataas
PostPosted: Jan 30, 2012 - 02:12 AM
Rookie


Joined: May 04, 2011
Posts: 26


Here follows a more clear explination (hopefully..):


PORTE_IN is defined in:

#include <avr/io.h> (iox128b1.h)

and is the 8-bit register that holds the values of my input (switches).

put_on_leds(uint8_t); simply output the argument to my LEDs at PORTB. In the same way as the upper line is. Here is the function:

Code:
 void put_on_leds(uint8_t value)
 {
    PORTB.OUT = (value << 4);
 }
 
 View user's profile Send private message  
Reply with quote Back to top
sternst
PostPosted: Jan 30, 2012 - 02:33 AM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2438
Location: Osnabrueck, Germany

It does not work because you shift the value read from the port twice by 4 (therefore the result is always 0).

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
Phataas
PostPosted: Jan 30, 2012 - 01:50 PM
Rookie


Joined: May 04, 2011
Posts: 26


THANK YOU! I have to stop programming when I should be sleeping...
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits