Go Down

Topic: ACCESSING PORTS (Read 729 times) previous topic - next topic

hi guys,
am a beginner in arduino, my doubts will definitely be stupid but kindly help me

can i send a hexa decimal value or decimal to a port and view it through led?
the sample codes shows i have to configure each pin n send either high or low bit, i want to access the whole port throgh some commands like portB=H5f of watever, is it possible in an arduino uno?

dxw00d

http://www.arduino.cc/en/Reference/PortManipulation

Tom Carpenter

#2
Oct 06, 2012, 11:23 am Last Edit: Oct 06, 2012, 11:27 am by Tom Carpenter Reason: 1
This wouldn't work:
Code: [Select]
portB=H5f
This would:
Code: [Select]
PORTB=0x5F

You can dec/increment the value in the port register too:
Code: [Select]
PORTB++;
PORTB += 10;
PORTB--;

And toggle all bits at once:
Code: [Select]
PORTB ^= 0xFF;
And pretty much anything you can do with a byte type variable (not quite but most things).
~Tom~

Nick Gammon



You can dec/increment the value in the port register too:
Code: [Select]
PORTB++;
PORTB += 10;
PORTB--;



Another entrant: http://www.ioccc.org/
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Tom Carpenter

~Tom~

dhenry

Or to define a set of macros:

#define setbits(var, bits) var |= (bits)
#define clrbits(var, bits) var &=~(bits)
#define flpbits(var, bits) var ^= (bits)

with that, you can operate on the port (or ddr or any other register for that matter)

  setbits(PORTB, (1<<2)); //sets bit2 on portb
  clrbits(DDRB, (1<<0)); //bit0 on portb set as input
  flpbits(PORTB, (1<<2) | (1<<3)); //flip bit2 and bit3 on portb

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy