a variety of newbie questions

I'm trying to read some code, but find lots of identifiers that I can't find in the Reference.

Here's some code:


// pinMode is about 6 times slower than assigning
// DDRB directly, but that pause is important
pinMode(pin, OUTPUT);
PORTB = 0;
pinMode(pin, INPUT);
while((PINB & mask) == 0)
count++;


What is DDRB? How would I have figured this out without asking here?

I know what PinMode is, but what is PORTB? It reads as if it is a way to send output to a pin/port, but to what pin/port? The most recent?

What is PinB? Reads as if it is a way to get input, but from what?

Or what about this one:

extern volatile unsigned long timer0_overflow_count;

There are no Includes in this program, so where is this Extern resolved?

I don't want people to answer every question I have: I need to know how to find the answers myself.

Thanks!

Jon

These are command that access the hardware ports directly. The commands are described here Arduino Reference - Arduino Reference

As the web page on that link indicates, Generally speaking, using the low level stuff is not a good idea.
Its kind of self selecting, if you understand it its easy to use it, if not may be best to use the documented Arduino abstractions.

the extern is a variable declared in \hardware\cores\arduino\wiring.c

Thank you!

Regarding the Extern, wouldn't the original code have had to include Wiring.C in order to resolve this? I'm puzzled that the original source code lacked a reference to this file.

Jon

Hi Jon, the code from wiring.c Is automatically included in the build process. Its not made visible so as not to confuse the novice arduino programer with the low level plumbing.

The build process is discussed here: Redirecting

That's great, and thanks for the reference. The thing that puzzled me was that the compiler complained about the Extern. If it had resolve it silently, I would not have had to try to figure out where it had come from.

Probably not worth continuing on this thread. Thanks again.

That variable was defined in versions before 0012, the latest version uses different code to calculate time and the variables have different names. You can read more about that here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226014847

BTW, that is a good example of how stuff that is not officially documented like timer0_overflow_count can be a real problem. There is no guarantee that it will be supported in future, or much worse that the implantation may change so it still compiles but the code doesn't work correctly in a future release.

There is a sense of adventure delving into the undocumented plumbing, but you may be on your own if it breaks your application.
One guy I used to work with said the definition of extern should be: “ a bug lying dormant until some future release of the code.”