1. What is a microcontroller? A microcontroller is a single-chip microcomputer that integrates a microprocessor, memory, and I/O interface circuits on one integrated circuit chip. Intel launched the MCS-51 series microcontrollers, which integrate an 8-bit CPU, 4KB ROM, 128 bytes RAM, 4 8-bit parallel ports, and 1 full-duplex serial port, along with 2 16-bit timer/counters. The addressing range is 64K, and it features a powerful Boolean processor.2. The role of microcontrollers Introduction to projects using microcontrollers: Handheld grain storage temperature detection device Graduation defense scoring device Telephone desk lamp Automatic sensing faucet Any electronic device related to control or simple calculations can be implemented with a microcontroller. Depending on the specific requirements, different performance microcontrollers can be chosen, such as: Atmel, STC, PIC, AVR, Sunplus, 80C51, ARM, etc. Industrial automation: data acquisition, measurement and control technology. Intelligent instruments: digital oscilloscopes, digital signal sources, digital multimeters, inductive ammeters, etc. Consumer electronics: washing machines, refrigerators, air conditioners, televisions, microwaves, mobile phones, IC cards, automotive electronic devices, etc. Communication: modems, programmable switching technology, mobile phones, etc. Weaponry: aircraft, warships, tanks, missiles, spacecraft, torpedo guidance, smart weapons, etc. And so on…3. Prerequisites for learning microcontrollers(1) In digital circuits, there are only two levels: high and low. Define the microcontroller as TTL level: High +5V Low 0V(2) RS232 level: the serial port of the computer High -12V Low +12V Therefore, a level conversion chip is needed for communication between the computer and the microcontroller.(3) Base conversion and logical, arithmetic operations(4) Basics of C language(5) Understanding of 80C51 The 80C51 is a typical variety in the MCS-51 series; other manufacturers’ CMOS microcontroller products developed based on the 8051 core are collectively referred to as the 80C51 series.(6) Bus (BUS) is a common channel for transmitting information between various components of a computer. There are two types of buses in microcomputers: internal bus and external bus. The internal bus connects components within the CPU. The external bus connects the CPU to other components. There are three types of external buses: Data Bus (DB), Address Bus (AB), and Control Bus (CB).(7) CPU: Composed of arithmetic and control logic, including an interrupt system and some external special function registers; RAM: Used to store read and write data, such as intermediate results, final results, and data to be displayed; ROM: Used to store programs, some raw data, and tables; I/O ports: Four 8-bit parallel I/O ports, which can be used for both input and output; T/C: Two timer/counters, which can operate in either timer mode or counter mode; An interrupt control system with five interrupt sources; A full-duplex UART (Universal Asynchronous Receiver Transmitter) serial I/O port for serial communication between microcontrollers or between a microcontroller and a computer; On-chip oscillator and clock generation circuit, with quartz crystal and trimmer capacitor needing to be connected externally. The maximum oscillation frequency depends on the microcontroller model and performance.(8) C51 data storage types Example: Data type Variable name char var1; bit flags; unsigned char vector[10]; int wwww; Note: Variable names cannot use keywords from the C language.(9) Included header files (can be checked in the INC directory under the installation directory) Commonly include: reg51.h reg52.h math.h ctype.h stdio.h stdlib.h absacc.h Commonly used: reg51.h reg52.h (Define special function registers and bit registers); math.h (Defines common mathematical operations);(10) Format of interrupt service routine function_name() interrupt n using m{ Internal implementation …}(11) I/O port definition sbit beep=P2^3;(12) Basic timing of microcontrollers Machine cycle and instruction cycle: (1) Oscillation cycle: also known as clock cycle, refers to the period of the oscillation source providing clock pulse signals to the microcontroller, which is 11.0592MHZ on the TX experiment board. (2) State cycle: Each state cycle is twice the clock cycle, obtained by dividing the oscillation cycle by two. (3) Machine cycle: A machine cycle contains 6 state cycles S1~S6, which is 12 clock cycles. Within a machine cycle, the CPU can complete an independent operation. (4) Instruction cycle: It refers to the total time required for the CPU to complete an operation. The execution time of each instruction consists of one or several machine cycles. In the MCS-51 system, there are single-cycle instructions, double-cycle instructions, and four-cycle instructions.4. Learning objectives for microcontrollers Necessary conditions for the minimum system to run. 1. Power supply 2. Crystal oscillator 3. Reset circuit Arbitrary operations on any I/O port of the microcontroller 1. Output control levels 2. Input level detection. Timer: Focus on mastering the most commonly used methods Interrupts: External interrupts, timer interrupts, serial port interrupts Serial communication: between microcontrollers, between microcontrollers and computers