[SOLVED]Rules for declaring pins for an Arduino UNO vs for ATMega328P

Do the protocols used to declare pins for an Arduino UNO project apply to declaring pins when only using an ATMega328P (with boot loader)?

So for instance if I were using an Arduino UNO for my project and needed to use pin 7 on the Arduino UNO for an LED, I would declare it as "int ledPin = 7;"
Pin diagrams for Arduino UNO and ATMega328
According to the above page, pin 7 (as labelled on the arduino) corresponds to pin 13 on the ATMega328 (or PD7). So now if I used the above code for a project where I have replaced my Arduino with just an ATmega328 (and the necessary capacitors and oscillator) then will the chip know that I by ledPin = 7 I am referring to pin 7 on what would have been the Arduino UNO (or PD7 / pin 13 on the ATmega328)? Or will it think I am referring to pin 7 on the ATmega (which would be the Vcc pin!)?

j_fc:
will the chip know that I by ledPin = 7 I am referring to pin 7 on what would have been the Arduino UNO (or PD7 / pin 13 on the ATmega328)?

Yes. But it's not a matter of the chip "knowing" it. It's the exact same thing. The Uno's PCB simply connects the ATmega328P pins to the female headers on the edges of the board. There is no magic there. It's just some wires.

So if I was directly using the ATmega328 and wanted to refer to say pin 19 on the ATmega, I would have to refer to it as pin 13 or PB5 (since on the Arduino UNO pin 19 on the ATmega connects to the female header labelled 13...)?

Apologies for being a bit dense about this and thank you for your time!

The board labels are D0 to D13, then A0 to A5 (on an Uno).
Your code will refer to them as 0 to 13, and A0 to A5.

The software takes care of the rest, mapping 0 to 7 do PortD, mapping 8 to 13 to PortB, and mapping A0 to A5 to PortC.

Bootload your 328P as an Uno, the mapping will stay the same, 0 to 7 will still come from PortD, 8 to 13 will come from PortB, and A0 to A5 will come from PortC.

Here is an example of a minimal setup from back when I first started using Eagle.

Thank you! I get it now!

You can see it is not the best of designs, with no 0.1uF caps on VCC, AVCC, or a diode across the reset resistor to catch spikes that can occur when the reset switch is released and can cause a spike that th chip sees as "high voltage" to kick off, and then hang, in high voltage programming mode.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.