NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Question Regarding Registers

December 16, 2010
by Mindale
Mindale's Avatar

I am working on the LED blink project and was wondering why the bit set to one on the DDRC register is PC4

DDRC |= (1<<PC4);

I understand that this is setting pin PC4 to be an output pin, but when I consulted the data sheet it says that the pin I should set to output should be DDC4.

December 16, 2010
by bretm
bretm's Avatar

DDC4 isn't a pin, it's the number of the bit in the DDRC register corresponding to pin PC4, and you're right--that's the right way to do it. But DDRC4 so far has always equalled the value of PC4 in every AVR they've made, so the incorrect code has always worked and people havegotten into the habit of doing it that way.

December 16, 2010
by met_fredrik
met_fredrik's Avatar

Is that really true? The datasheet clearly says DDRC is the direction register for PORTC. I don't see why your calling it incorrect code?

December 16, 2010
by Mindale
Mindale's Avatar

Thanks for the clarification. When I change the code such that PC4 is now DDC4, everything seems to run correctly.

December 16, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi everyone,

DDRC is the data direction register, and we do use that correctly. The argument here is about how we name (and access) the individual pins of the register. The datasheet does refer to the bits of the DDRC register as DDxn (i.e. DDC0). avr-libc does define teh DDxn variables and you could do

DDRC |= (1<<DDC4);

However like bretm mentioned DDC4 is the exact same thing as saying PC4 (they both equal the number 4) so when referring to a specific pin we tend to just use PC4 everywhere. It is probably strictly speaking not as correct, but its one of things that has been done long enough that it works.


Post a Reply

Please log in to post a reply.

Did you know that you can build an analog amplifier with one transistor and a few resistors? Learn more...