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 » trouble need help

March 15, 2012
by Mcheques
Mcheques's Avatar

Hello, I dont understand how to set these register bits. On this board at G12 i need that to be set as a output say a led and on G15 i need that to be set as a input. So if g15 is set to on it will turn g12 on and if g15 is off than g12 is off. Can some one show me this simple code and explain it thank you

March 15, 2012
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Macheues,

I'm not really sure what you are asking here. Could you be more specific about what you are trying to do? Are you working on the NerdKits Guide at the moment or some different project?


March 15, 2012
by Mcheques
Mcheques's Avatar

im using nerdkits, all i really want to know is how to set the different pins on the right side of the chip. I dont understand how to program them

March 15, 2012
by Rick_S
Rick_S's Avatar

Look at the code in the LED blink example in the downloaded file. That example will demonstrate how to turn on and off the pin at g12 on the breadboard.


March 16, 2012
by Mcheques
Mcheques's Avatar

ok this is what i need. pin 28 as a input pin, and pin 27 as a output. Esentialy i want a signal coming into pin 28, if its on than pin 27 turns on and if pin 28 is off than pin 27 is off. I dont know how to do this, can someone please explain it to me, thanks

March 16, 2012
by pcbolt
pcbolt's Avatar

Mcheques -

Pin 28 is PC5 and Pin 27 is PC4 (the way the microcontroller understands it). To set PC5 as and input pin you would code the Data Direcrtion Register C like this:

DDRC &= ~(1<<PC5);

To set PC4 as an output pin:

DDRC |= (1<<PC4);

Then you would set up an infinite code loop to keep checking if the input pin is high or low, like this:

while(1) {
  if (PINC & (1<<PC5))
    PORTC |= (1<<PC4);
    PORTC &= ~(1<<PC4);
March 17, 2012
by Mcheques
Mcheques's Avatar

thank you

Post a Reply

Please log in to post a reply.

Did you know that the Timer/Counter modules on the microcontroller can be configured to output a PWM (Pulse Width Modulation) signal? Learn more...