Don't know what it's called - I/O pins serving multiple duties

I'm just beginning to create my first standalone MCU circuit. I'm already using an abbreviated version of it on a Mega1280. While the Mega1280 has more than enough I/O's for my project, I'll be using an atmega328p for the standalone project. Just a few days ago, I completed a "target board" with a ZIF socket on which to program my chips using the AVRISP MKII. After some effort, I managed to successfully upload my very first sketch using an ISP, the MKII and avrdude. That tells you where my skill level is... not very far.

So, the 328p has a total of 20 I/O pins. I'll need just about that many for my project. I figured I should be planning now for the inevitable need for more pins as I near project completion. While I need more pins, and registers would resolve that issue, I want to know how to "stack," for lack of a better word, peripherals (if that's the right word), on the pins that are already available on the MPU without the use of external registers.

Please bear with me. I'm having a difficult time putting my question into words. To date, what few Arduino projects I've done, have basically been connecting pin this to that and pin that to this without actually knowing how it all really works in the MPU. Likewise, when uploading a sketch using the ISP, I simply connected MISO to MISO etc. As I began allocating pins for my standalone project, I realized MISO is also an I/O pin. Same with SCK and MOSI. Further, the pinout shows all the I/O's have similar acronyms after them having meanings I've yet to learn. I've read through some of the MPU datasheets and get way lost. In designing a standalone project, normally, I probably would have connected my 6 pin header for ISP uploading to the MISO/MOSI/SCK pins. Those pins being "used", I would have simply used other pins for I/O, avoiding a seeming conflict. My instinct tells me that these pins are designed for multiple purposes and that something somewhere is telling them when they're to be an I/O and when to do their other function. In terms of ISP, am I wrong in connecting the MOSI pin to say a LCD in my project and using it like any other I/O? How is my circuit to know to ignore the signal coming across the MOSI pin from the ISP? Is there something I need to do in my circuit design? I'm just not sure how to design around these double duty functions. If I knew what this thing was called, I could probably google something for better comprehension of it. Does any of this make sense?

As an aside, I've already considered one non-register way to increase the number of I/O's. My project will be using a common 4-bit LCD. I also have a motor to control along with a couple limit switches. The LCD and the motor can be operated sequentially as sending instructions to either will never last more than a second or so. Instead of another 4 pins for my motor control, I'll only need to allocate one pin that will be used to "enable" the motor circuitry. The LCD already uses a similar pin so can be disabled easily enough. I know this probably isn't the most efficient, but it's the easiest for me to get my head around.

Your kind patience with a beginner is greatly appreciated.

Yes it takes some time to learn the right words.

peripherals (if that's the right word),

Yes

on the pins that are already available on the MPU without the use of external registers.

but registers is not the right word, I think you mean chips here.

Each arduino pin can be an input pin or an output depending on how you program it. You are already using four pins known as the SPI bus to program your Arduino, most people do not do that and use the serial port and "boot loader" code to do the programming.

am I wrong in connecting the MOSI pin to say a LCD in my project and using it like any other I/O?

That is right but those pins can have other specialized uses like the SPI bus.

How is my circuit to know to ignore the signal coming across the MOSI pin from the ISP?

It is a function of the code you write, your code can trigger different modes for pins.

The LCD and the motor can be operated sequentially as sending instructions to either will never last more than a second or so. Instead of another 4 pins for my motor control, I'll only need to allocate one pin that will be used to "enable" the motor circuitry.

You can indeed to this providing the common pins are outputs and the separate enable pins on the two devices do actually totally disable the device. However I would recommend against this as it is a bit complex and it is easy to go wrong.
Use an external chip to get more input / output. Popular chips to use are shift registers or Port Expanders.

chipwitch:
In terms of ISP, am I wrong in connecting the MOSI pin to say a LCD in my project and using it like any other I/O? How is my circuit to know to ignore the signal coming across the MOSI pin from the ISP? Is there something I need to do in my circuit design?

Two parts:

  1. The chip is only looking for programming commands on MOSI, MISO, etc. for a short time period after Reset is pulled low then high. Your sketch doesn't start until after that time has passed so it's impossible to interfere with that programming activity. If, after reset, the chip sees signals that do not follow its programming protocol it will error out and just skip the programming session - then your sketch continues as normal.
  2. If you connect peripherals to those pins it is possible that your peripherals can draw so much current that your ISP programmer can't reach the signal voltages required. So connecting something like a LED cathode (with a too-low value resistor) or mosfet gate to those pins could cause problems.

@Grumpy... YES!! SHIFT register! THAT was the word I was looking for.

SPI Bus... sounds like a good google search term.

Grumpy_Mike:

How is my circuit to know to ignore the signal coming across the MOSI pin from the ISP?

It is a function of the code you write, your code can trigger different modes for pins.

Okay... example. Pin 17 on a 328p... Say, I'm using it to saturate the base of an NPN that turns on a LED. Pin 17 is MOSI. If I've designed my own standalone board that uses the SPI, when I upload a sketch, at times won't pin 17 be HIGH? What prevents the LED from turning on? A LED is fairly benign, but some sub-circuits might actually respond in a very adverse way. No?

@Chagrin, thanks for that. You're addressing how the circuit might affect the SPI input. I realize what you're saying. The programming side is my stronger side and wasn't even considering THAT as a problem. Been programming since way back the Trash-80 days! (ACK, I'm old! How'd that happen?). Just goes to show, that I wasn't even CONSIDERING that aspect. BAD GIRL! Oversight is one of my biggest fears... missing something I should have at least considered. What I know, I know... What I don't know, scares me! Your point is well taken.

YES!! SHIFT register! THAT was the word I was looking for

Ha har yes that shift totally changes the meaning, a register is the name for a storage location inside a processor that normally controls some hardware feature or other.

when I upload a sketch, at times won't pin 17 be HIGH? What prevents the LED from turning on?

Yes that is a problem.
A similar one people face is with MIDI wanting to use the serial ports and the boot loader wanting to use them for uploading programs. The solution normally is to disconnect the circuit or arrange some switches so that it is out of the way during programming. See this page for an example of using switches :-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Shield.html
But hey that is part of designing a system and part of the fun.

And THAT, my Grumpy friend is precisely why I asked! Thank you.

BTW... you ain't so grumpy. :wink: