All microcontrollers (MCUs) share the same basic principles and functions. The main differences lie in their peripheral module configurations, number of features, and instruction sets. Although instruction sets may seem vastly different, they are essentially just different notations; the underlying meanings, functions, and addressing modes are often quite similar. Therefore, any MCU can be understood by focusing on the following key aspects.
Parameter Initialization
After initializing the MCU's hardware and resources, the next step is to set up the variables and data used in the program. This part of the initialization must be designed according to the specific project requirements and overall program structure. For applications that store pre-configured device parameters in EEROM, it is recommended to copy this data to the MCU's RAM during initialization. This improves data access speed and reduces system power consumption, as accessing external EEPROM generally increases power draw.
Key MCU Characteristics
To understand an MCU, you first need to know its specifications, including ROM and RAM space, number of I/O pins, number and type of timers, available peripheral modules, interrupt sources, operating voltage, and power consumption.
I/O Ports
Every MCU has a certain number of I/O ports, which are essential for communication with external components. They can be classified into the following types.
Dedicated Input or Output Ports: The function of these ports is fixed by the hardware design and cannot be changed by software.
Direct Read/Write Ports: The I/O ports on the MCS-51 are a classic example. When an I/O read instruction is executed, the port acts as an input. When a write instruction is executed, it automatically functions as an output.
Direction-Programmable I/O Ports: The direction (input or output) of these ports can be set by the program as needed. This flexibility is useful for implementing bus-level applications such as the I2C bus or control lines for various LCD and LED drivers.
When using I/O ports, it is crucial to remember that input pins must have a defined logic level signal and should never be left floating (this can be achieved by adding a pull-up or pull-down resistor). For output pins, their state must be considered in relation to external connections to ensure they are not sourcing or sinking current unnecessarily during standby or static states.
External Interrupts
External interrupts are a standard feature on most MCUs, typically used for real-time signal triggers, data sampling, and state detection. Interrupts can be triggered by a rising edge, falling edge, or logic level. External interrupts are generally implemented through input pins. If a configurable I/O pin is used, its interrupt function is usually active only when configured as an input. If set as an output, the external interrupt function is automatically disabled (though some exceptions exist, such as in Atmel's ATiny series, where an output pin can still trigger an interrupt).
ALLPCB