Not listed in Reference

I have been looking for a way to read some pins (3 in this case) that would create an address for the program I have and is working very well.

I found this in the forum and it works great but puzzled why I can't find it in the language reference under the learning drop down box.

dipSwitch = PIND & 0b00011100; // read PORTD, mask off for bits 4, 3, 2

The command/function(?) "PIND" reads the port D pins and that is anded with a binary value to mask all the bits except 2, 3 and 4 but I can't find this useful function/command( sorry confused as to what it may be called) in the language reference. I wonder if the reverse could be used, outputting a byte or any number of bits at same time? So where can I find a definition and all the quirkiness for this plus what others are missing/not listed that could be of use? Thanks Bruce

I found this in the forum and it works great but puzzled why I can't find it in the language reference

Because it isn't portable.

So where can I find a definition and all the quirkiness for this plus what others are missing/not listed that could be of use?

there's the processor data sheet.

PIND is the Atmel name for the Port D Input Register. You may use PIND but it is not necessarily correct for other Arduinos. digitalRead(…) is safer.

Many of the Atmel names have been defined for your usage… but many are not portable. Get the data sheet for the processor on your Arduino and you may be able to do some amazing things… but it may not be portable.

WARNING: The data sheet for the ATmega328P is a PDF file containing 448 pages. Good Luck!

Thanks for the replies. Not portable..hmmm...ok so will keep that in mind and look at the data sheet for the processor I am using. Just curious though is there a copy of the datasheet here on this forum or a link? I am using the Atmel mega 328p.

Yes digitalRead() I am aware of but that is a single pin/bit and collecting the 3 pins to see what their values are can get messy (just looking at code listed when I did a search here and tried them, at least to me).

Oh well learned something new today.

Have you considered going to Atmel.com ? Or googling it? They actually want people to know about their processors.

I don't "Google" but I did search and found the Atmel site and a 660 page PDF, oh fun looking through that!

7b_w: I don't "Google" but I did search and found the Atmel site and a 660 page PDF, oh fun looking through that!

I'm afraid "google" has become a regular verb. Use whatever search engine pleases you.

"I wonder if the reverse could be used, outputting a byte or any number of bits at same time?"

Yes, use PORTD.

PORTD = PORTD & 0b11100111; // clear bits 4 & 5 PORTD = PORTD | 0b00011000; // set bits 4 & 5

'328 has PORTD (D7-D0), PORTB (upper 2 not accessible, and D13-D8), and PORTC (upper 2 not accessible, and D19-D14, aka A5-A0)

I use them all the time, as I when I write code I write it for a specific project and portability is not a concern. It's called Direct Port Manipulation https://www.arduino.cc/en/Reference/PortManipulation

I don't why know you other folks can't provide a simple answer sometimes.

CrossRoads: I don't why know you other folks can't provide a simple answer sometimes.

Simple to you. People are giving advice to a person who wonders whether PIND is a command or a function. It would not hurt such a person to know about other options.

Thank you CrossRoads. I got the PIND function from your reply to someone else trying to implement a dip switch address selector elsewhere in this forum.

And thanks for the link to 'port manipulation', but I would not been able to find that on my own. Whenever I select 'reference' under the drop down window from 'learning' I get this: https://www.arduino.cc/en/Reference/HomePage and no where on that page can I find a link to 'port manipulation'.

and no where on that page can I find a link to 'port manipulation'.

Probably because it's not a beginner subject, and also a potential Pandora's box.

Wow, ok AWOL I understand it could present a huge problem for some here but at some point users will advance and are going to want that info. Play at your own risk so if you burn up your board that's your problem and learn from your mistakes. So where is the advanced users section of this forum where one can find info like "port manipulation"?

With the Reference page open, I did a search for Port Manipulation, and got a page of hits. Port Manipulation was the first one. Having read many forum topics, one sees a lot terms, that helps when it comes time for a search.

At this level of hardware stuff, to "advance" one of the first things you need to do is get the data sheet for the processor you are working with and become familiar with it. Things will start to make more sense then. As far as the "portable" part goes, you can either learn about it or get bitten by it. I often use the PIC processors for various things too with the CCS C compiler. They have a "getenv" function that allows you to get basic parameters about a processor then use them in your code. The advantage to that (this applies to almost everything where you are down at the register/hardware level) is that when you decide that there is a newer version of the processor (or bigger) that has all the features you need, it is easy to port your working code over to it instead of having to spend hours and hours going over the internal register maps and your code making sure you got them all changed to the new processor. You only have to do that a few times before you start to appreciate the term "portable". At the level of these boards and what we do with them, it is important to understand how the processor is built and what the limitations are (output current per pin etc.). Once you let the magic smoke out, there is no way to stuff it back in.

Thanks CrossRoads I will keep that tip in mind when looking for something specific.

PS: looked at your webpage, very interesting offerings there!

Gpsmikey, I have written programs for the PIC chips before and Atmel's MCS51 derivatives (89C1051, 2051) but that was all using assembler code and no C code at all even though I have a CCS C compiler that I meant to try but never did. Was happy with assembler language and what I was able to accomplish.