Pages: [1]   Go Down
Author Topic: individual I/O pin access  (Read 818 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: May 29, 2012, 10:06:57 am by James C4S » Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 499
Posts: 19065
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
digitalWrite(13, !digitalRead(13));  // inverts the state of an output pin.

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

Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: