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 » Tip for passing a register into a function by reference.

December 19, 2011
by Striker
Striker's Avatar

I had a few functions that I wanted to be able to pass a register into as a pointer and manipulate, but the data type of the registers wasn't very easy for me (and I'm sure other beginners) to figure out, so I'll just leave this here for posterity.

void function foo(volatile unsigned char* reg)
{
    *reg = 1;
}

int main()
{
    foo(&PORTB); //PORTB = 1
}

If this has already been mentioned elsewhere, then I'm sorry; the forum search isn't very good.

Post a Reply

Please log in to post a reply.

Did you know that essentially all power supplies' voltages drop when current is drawn from them? Learn more...