AT89C52 is a low-voltage, high-performance CMOS 8-bit microcontroller. It contains 8k bytes of rewritable Flash read-only program memory and 256 bytes of random access data memory (RAM). The device adopts ATMEL's high-density, Produced with non-volatile storage technology, compatible with the standard MCS-51 instruction system, with a built-in general-purpose 8-bit central processor and Flash memory unit, the AT89C52 microcontroller is widely used in the electronics industry.
AT89C52 microcontroller hardware structure
As shown in Figure 3-1, it is the hardware structure diagram of AT89C52. The internal structure of the AT89C52 microcontroller is basically the same as that of the MCS-51 series microcontroller. The CPU is composed of arithmetic units and controllers. The arithmetic unit is mainly used to perform arithmetic, logical operations and bit operations on the operands. The controller is the command and control component of the microcontroller. It identifies instructions for its main tasks and controls the functional components of the microcontroller according to the nature of the instructions, thereby ensuring that all parts of the microcontroller can work automatically and harmoniously. Its program memory is 8K bytes of rewritable Flash memory. The flash memory allows online +5V electrical erasure, electrical writing, or repeated programming using a programmer. The data memory is much larger than the 51 series microcontroller, with 256 bytes of RAM. The instruction system and pin functions of the AT89C52 microcontroller are fully compatible with those of the MCS-51.
Main performance parameters
• 8K bytes of rewritable Flash memory
• 1000 erasable and writable cycles
• Fully static operation: 0Hz-24MHz
• Level 3 encrypted program memory
• 256×8 bytes internal RAM
• 32 programmable I/O lines
• 3 16-bit timer/counters
• 8 interrupt sources
• Programmable serial UART channel
• Low-power idle and power-down modes
AT89C52 external pin diagram
AT89C52 pin description
VCC: power supply GND: ground
Port P0: Port P0 is an 8-bit open-drain bidirectional I/O port. As an output port, each bit can drive 8 TTL logic levels. When "1" is written to the P0 port, the pin acts as a high-impedance input. When accessing external program and data memory, Port 0 is also used as the lower 8-bit address/data multiplexing. In this mode, P0 has an internal pull-up resistor.
During flash programming, the P0 port is also used to receive instruction bytes: during program verification, the instruction bytes are output. When the program is validated, an external pull-up resistor is required.
Port P1: Port P1 is an 8-bit bidirectional I/O port with an internal pull-up resistor. The output buffer stage of P1 can drive (sink or output current) 4 TTL logic levels. When "1" is written to P1, the current ILL will be output due to the internal pull-up resistor.
AT89C52 crystal oscillator characteristics
The AT89C52 microcontroller has an inverting amplifier used to form an internal oscillator. XTAL1 and XTAL2 are the input and output terminals of the amplifier respectively. Both quartz crystals and ceramic resonators can be used together to form a self-excited oscillator. If the device is driven from an external clock, XTAL2 can be left unconnected and connected through XTAL1. Since the external clock signal is input to the external clock circuit after being triggered by dividing by two, there are no other requirements for the duty cycle of the external clock signal. The maximum low-level duration and the minimum high-level duration must still meet the requirements. .
Quartz crystal oscillator C1, C2=30PF+-10PF Ceramic resonator C1, C2=40PF+-10PF
AT89C52 microcontroller minimum system interface circuit design
AT89C52, clock circuit (including crystal oscillator, capacitor C19, C20), and power-on reset circuit (including R42, C5, S3, VD1, C3, R9) constitute the minimum system of the microcontroller. Among them, the crystal oscillator uses a 12MHz highly stable passive crystal oscillator, which forms an oscillator with the reverse amplifier in the AT89C52 to provide a highly stable clock signal to the CPU. Capacitors C19 and C20 can play the role of frequency fine-tuning. The capacitance value can be selected between 5pF and 30pF. For this circuit, 20pF is selected. Capacitor C5 and resistor R42 constitute a power-on reset circuit. When the power is turned on, the power charges the capacitor C5 and generates a high pulse at the reset terminal of the CPU. As long as the high level is maintained for longer than two machine cycles (24 oscillation cycles). The CPU can be reset. The function of the diode VD1 is to quickly release the charge stored in the capacitor C5 when the power is turned off, so that it can be reliably reset the next time the power is turned on. Capacitor C5 can filter out high-frequency interference and prevent the microcontroller from erroneously resetting. Button S3 and resistor R9 constitute a button reset circuit.
AT89C52 timer 2 working mode:
Timer 2 is a 16-bit timer/counter. It can be used as a timer or an external event counter, and its working mode is selected by the C/T2 bit of the special function register T2CON (see Table 3). Timer 2 has three working modes: capture mode, automatic reload (up or down counting) mode and baud rate generator mode. The working mode is selected by the control bit of T2CON. Timer 2 consists of two 8-bit registers TH2 and TL2. In the timer working mode, the value of the TL2 register is incremented by 1 for each machine cycle. Since one machine cycle consists of 12 oscillation clocks, the counting rate is the oscillation frequency. 1/12. In the counting mode, when the external input signal on the T2 pin generates a falling edge from 1 to 0, the value of the register is incremented by 1. In this mode of operation, the external input is sampled during 5SP2 of each machine cycle. . If the value taken in the first machine cycle is 1 and the value taken in the next machine cycle is 0, then the register is incremented by 1 during S3P1 of the following cycle. Since it takes 2 machine cycles (24 oscillator periods) to recognize a 1 to 0 transition, the maximum counting rate is 1/24 of the oscillator frequency. In order to ensure the accuracy of sampling, the input level is required to be maintained for at least a complete cycle before changing to ensure that the input signal is sampled at least once.
Capture method:
In capture mode, two modes are selected through the T2CON control bit EXEN2. If EXEN2=0, Timer 2 is a 16-bit timer or counter. When the count overflows, the overflow flag TF2 of T2CON is set and the interrupt is activated at the same time. If EXEN2=1, timer 2 completes the same operation, and when the T2EX pin external input signal undergoes a negative transition from 1 to 0, the values in TH2 and TL2 are captured into RCAP2H and RCAP2L respectively. In addition, the transition of the T2EX pin signal causes EXF2 in T2CON to be set. Similar to TF2, EXF2 will also activate the interrupt. The capture method is shown in Figure 4. ·Auto-reload (up or down counter) mode:
When Timer 2 works in 16-bit auto-reload mode, it can be programmed to count up or down. This function can be programmed through the special function register T2CON.
Selected by the DCEN bit (allowing down counting) (see Table 5). On reset, the DCEN bit is "0" and Timer 2 is set to count up by default. When DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin, see Figure 5. When DCEN=0, Timer 2 is automatically set to count up. In this case In mode, the EXEN2 control bit in T2CON has two options. If EXEN2=0, timer 2 counts up to 0FFFFH and overflows, sets TF2 to activate the interrupt, and at the same time reloads the 16-bit counting registers RCAP2H and RCAP2L, RCAP2H and RCAP2L The value can be preset by software. If EXEN2=1, the 16-bit reload of Timer 2 is triggered by an overflow or a falling edge from 1 to 0 at the external input T2EX. This pulse sets EXF2, which also generates an interrupt if interrupts are enabled.
AT89C52 timer
The interrupt entry address of timer 2 is: 002BH - 0032H.
When DCEN=1, Timer 2 is allowed to count up or down, as shown in Figure 6. In this mode, the T2EX pin controls the counter direction. When the T2EX pin is logic "1", the timer counts upward. When the count 0FFFFH overflows upward, TF2 is set, and the 16-bit count registers RCAP2H and RCAP2L are reloaded into TH2 and TL2. When the T2EX pin is logic "0", timer 2 counts down. When the values in TH2 and TL2 are equal to the values in RCAP2H and RCAP2L, the count overflows, TF2 is set, and the 0FFFFH value is reloaded into the timing register. .
The EXF2 bit is set when Timer/Event Counter 2 overflows or underflows. ·Baud rate generator: When TCLK and RCLK in T2CON are set, Timer/Counter 2 is used as a baud rate generator. If Timer/Counter 2 is used as a transmitter or receiver, its transmit and receive baud rates can be different, and Timer 1 is used for other functions, as shown in Figure 7. If RCLK and TCLK are set, Timer 2 operates in baud rate generator mode.
The mode of the baud rate generator is similar to the auto-reload mode, in which a TH2 rollover causes the Timer 2 register to be reloaded with the 16-bit value in RCAP2H and RCAP2L, which is set by software. In mode 1 and mode 3, the baud rate is determined by the overflow rate of timer 2 according to the following formula: The baud rate of mode 1 and 3 = the overflow rate of the timer/16 The timer can work in both timing mode and For counting mode, in most applications, it works in timing mode (C/T2=0). When Timer 2 is used as a baud rate generator, its operation is different from that of a timer. Usually, when used as a timer, the value of the register is increased by 1 at each machine cycle (1/12 oscillation frequency), and as a baud rate When the generator is used, the register value is incremented by 1 at each state time (1/2 oscillation frequency). The baud rate is calculated as follows:
Previous article:Design of intelligent traffic light using AT89C52 microcontroller
Next article:Working principle and production method of LED dot matrix Chinese character display circuit
Recommended ReadingLatest update time:2024-11-23 15:10
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- ADI Vital Signs Monitoring Technology: Monitor the human body and win prizes by answering questions
- Live: Introduction to Intel FPGA programmable acceleration platform, getting close to AI, data center, genetic engineering and other major projects
- 【TI recommended course】#Lecture on basic knowledge of electronic circuits#
- Bluetooth intercom
- Because he mastered the company's "core technology", the boss hired several strong men to kidnap people on the street after leaving the company
- i.MX8MP Application Notes | Solutions to Common Problems
- Embedded System Learning Log
- Design of three-way intelligent synchronous acquisition card with phase-locked loop based on single-chip microcomputer control
- Torque motor???
- It's time to test your eyesight