Electronic – How does a microcontroller “remember” a program

microcontrollerpic

This is something thats really bugged me since I've graduated. We programmed PIC16f877a micrcontrollers in class but never got into the how it works, just the make it work. So let's say I write a program that makes LEDS flash in a specific order and send this program to the microcontroller through this special adapter to the right pins. What do you know, the LED's begin to flash as instructed. Now, I disconnect the power and remove the PIC from the breadboard. I put the PIC back in its correct spot, plug in the power, and the LED's still flash as previously programmed without having to reprogram it. How is this happening? How does this microcontroller essentially "remember" what I told it to do?

Best Answer

The PIC includes a type of nonvolatile memory called "Flash EEPROM". When you "send your program to the microcontroller", the special adapter is in fact programming your code into this memory. The physical memory is a special kind of transistor with a floating gate that can store a charge more or less indefinitely, even with no power applied. In most devices, "charged" = 0, "no charge" = 1.

Whenever the PIC is reset or powered-up, it begins executing your code, fetching it directly from this memory.

On the PIC, this memory is integrated into the same chip that holds the CPU and the rest of the logic (peripherals, etc.). The same kind of memory is used to hold the BIOS in your desktop/laptop PC, but it's a separate chip from the CPU. The first few screens you see when you switch on your PC come from the BIOS, which then loads your operating system from hard drive or SSD and runs that.