Go Down

Topic: individual I/O pin access (Read 872 times) previous topic - next topic

Rolandchok

i just shifted from PIC to atmel. i have a trouble of finding the individual PIN status change. in PIC you just state like access PORTB pin No. 7 you just state it "PORBTD.F7 = 1". i don't know if there is a function in arudino or atmel which do the same. aside from using digital write. its more of an old school. thank you so much.

Grumpy_Mike

You can do the old school port access here:
http://www.arduino.cc/en/Reference/PortManipulation
If you want, but most of the time the individual bit abstraction of digitalWrite is much simpler and portable across different models of arduino.

Rolandchok

thanks i don't have much choice then i have to use digital write. no old school stuff. but how state like on button press it inverts the old state of the port. what we do in PIC just "portd.f1 = ~portd.f1" for example. it actually makes the code compact with this method. are there any statements that does the same thing using digitalwrite?

thanks

James C4S

#3
May 28, 2012, 09:41 pm Last Edit: May 29, 2012, 05:06 pm by James C4S Reason: 1

thanks i don't have much choice then i have to use digital write. no old school stuff.

Already given to you:  http://www.arduino.cc/en/Reference/PortManipulation

PORTD = PORTD | 0x04;   // sets Pin 2 of Uno to Input.
int singleBit = PIND & 0x04 >> 2;  // read Pin 2 on an UNO

or as most people prefer
pinMode(2, INPUT);  // only run once
int singleBit = digitalRead(2);



but how state like on button press it inverts the old state of the port. what we do in PIC just "portd.f1 = ~portd.f1" for example.

pinMode(13, OUTPUT);  // only run once
digitalWrite(13, !digitalRead(13));  // inverts the state of an output pin.

Edit:  Forgot the bang.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Rolandchok

it really helps thank you so much. its kind a big adjustment for migrating to arduino.

James C4S


it really helps thank you so much. its kind a big adjustment for migrating to arduino.

The source code for all of the Arduino functions are included with the IDE.  So you can see how functions like digitalWrite() work.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Grumpy_Mike

Code: [Select]
digitalWrite(13, digitalRead(13));  // inverts the state of an output pin.
Should that not be
Code: [Select]
digitalWrite(13, !digitalRead(13));  // inverts the state of an output pin.

Nick Gammon


what we do in PIC just "portd.f1 = ~portd.f1" for example. it actually makes the code compact with this method.


Compact and incomprehensible, if you like that sort of thing.

Code: [Select]
digitalWrite(13, !digitalRead(13));  // inverts the state of an output pin.

... is pretty compact too, and more comprehensible.

Please post technical questions on the forum, not by personal message. Thanks!

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

Rolandchok

ok i will try to program using the arduino IDE for now and lets see how it goes thank you so so much for your help guys.


yeah your right the syntax for inverting the pin is "digitalWrite(13,!digitalRead(l13));" it needs the "!".

i think it wont take me much time migrating as im still coding C base.

Go Up