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 » AVRISP v2 programmer

October 13, 2012
by Robotnik
Robotnik's Avatar

I have been trying to program the ATMEGA 328p with an AVRISP v2 programmer, and avrdude loads the program onto the microcontroller without any problems, but it won't turn on an led.
here is my code:

#include<avr/io.h>

int main()
{
  DDRC |= (1<<PC5);
  PORTC |= (1<<PC5);

  while(1);
  return 0;
}

Does anyone know what i'm doing wrong?

October 13, 2012
by pcbolt
pcbolt's Avatar

Robotnik -

The 328p needs a special "io.h" file. If you go to the Members/Downloads section of this site, you'll find an "Upgrade 328 Nano Guide" . On page 7 they provide a link for the correct file called "io_328p.h". If you want to check if this is the problem before you download anything, try replacing lines 5 and 6 above with;

DDRC |= (1<<5);
PORTC |= (1<<5);
October 14, 2012
by Robotnik
Robotnik's Avatar

Ah okay, that fixed it thanks. Interesting, i'm just getting back into programming the ATMEGA328p, and I don't remember ever having to do that.

Post a Reply

Please log in to post a reply.

Did you know that a microcontroller can measure an RC time constant? Learn more...