Introduction
The most difference between a Microcontroller(MC) and a Microprocessor(MP) is that MC uses its build-in memory and registers with running a compiled program to do certain specific work; whereas the MP is concerdered as a general-purpose processing unit that can do multi-task work according to the I/O states.
-
There is always a pre-compiled program stored in the “code segment” (AKA: .cseg) used to determine which instruction should be executed next, this part of memory would not be initiated when the hardware is reset. Usually a MC has several parallel ports that can be configuared as either output (PORTx) or input (PINx) by configuration registers (DDRx), but they are independent from each other.
-
As for a MP, the processing device uses “BUS” as the interface to communicate with external devices. This means, the MP has only one interface on it. To introduce the BUS, serial and parallel communication is the pre-requisite. In brief, the MP exchanges the data with other external I/O devices by sending and receiving the data and address via BUS. The address is bundled with the data in order to nagivate the data, just like the Program Counter (PC) and the data in RAM (.dseg).
The reason why we want to configure a Microcontroller as a Microprocessor is that we sometime need a device to attach multiple I/O devices, to execute different programs according to different occasions/scenarios (or we simply just want it easier to upgrade), or to optimize its interface. Although the MC has limited ability to handle its outside devices, but it does not require lots of additional code and devices, with the completed RISC memory model it is widely used to controll electronic signals in simple applications nonetheless.
Example
The ATmega8515 is a well-known microprocessor in AVR serie, it has 4 ports (DDRA, DDRB, DDRC, DDRD) with 8 pins on each according to the data-sheet. As a MC, we use the following commands or instructions to get access with them.
- In C language:
- In Assembly:
In the above example, DDRA and DDRD are 8-bit I/O parallel interfaces, and they only exchange data once at a time according to the sequence in the code. Given the pinout diagram above, notive that there are AD7:AD0 and A15:8 in the brackets right beside the pins after PA and PC. And these, are also can be used as the BUS interface. To natively generate bus waveforms, a certain control register called “MCUCR” is used to switch the ATmega8515 into this mode.
- In Assembly: