Introduction of AT89C52 Flash MCU

Introduction of AT89C52 Flash MCU

The control component chooses AT89C52 single-chip microcomputer produced by ATMEL company. AT89C52 is a low-power, high-performance 8-bit microcontroller with 4KB of Flash programmable and erasable read-only memory on-chip. It uses CMOS technology and high-density non-volatile memory (NURAM) technology, and the pins and instruction system are compatible with MCS-51. The on-chip Flash memory allows reprogramming in the system or programming with a conventional non-volatile memory programmer. AT89C52 is a kind of single-chip microcomputer with strong function, high flexibility and reasonable price, which can be easily applied in various control fields.

1. The main features of AT89C52 microcontroller

(1) 4KB of reprogrammable Flash memory (erasable 1000 times).

(2) Full static operating frequency: 0~24Hz.

(3) The three-level program memory is confidential.

(4) 128 bytes of internal RAM.

(5) 32 programmable 1/O lines.

(6) Two 16-bit timers/counters.

(7) Six interrupt sources.

(8) Programmable full-duplex serial channel.

(9) On-chip clock oscillator.

AT89C52 is designed with static logic, its operating frequency can be reduced to 0Hz, and provides two power-saving modes that can be selected by software, namely, idle mode and power-down mode. In the idle mode, the CPU stops working, while the RAM, timer/counter, serial port, and interrupt system all continue to work. In the power-down mode, the on-chip oscillator stops working. Because the clock is “frozen”, all functions are suspended, and only the contents of the internal RAM are maintained until the next hardware reset.

2. Oscillator

AT89C52 has a high-gain inverting amplifier used to form an on-chip oscillator. Pins XTAL1 and XTAL2 are the input and output of this amplifier, respectively. This amplifier is also used as a feedback element and forms a self-excited oscillator with an external quartz crystal or ceramic resonator. The connection method of the oscillation circuit is shown in Figure 1.

Introduction of AT89C52 Flash MCU
Figure 1 – Internal oscillator connection

An external quartz crystal (or ceramic resonator) and capacitors C1 and C2 form a parallel resonant circuit, which is connected to the feedback loop of the amplifier. Although there are no strict requirements on the value of the external capacitors C1 and C2, the size of the capacitor will affect the oscillator frequency, the stability of the oscillator, the rapidity of the start-up and the stability of the temperature. When connecting a quartz crystal, C1 and C2 generally take (30±10) pF. When an external ceramic oscillator is connected, C1 and C2 generally take (40±10) pF. This control system adopts quartz crystal oscillator, C1 and C2 take 30pF.

An external oscillator can also be used. The connection method using external oscillator is shown in Figure 2. At this time, the signal of the external oscillator is connected to the XTAL1 terminal, the input terminal of the internal clock generator, and the XTAL2 terminal is left unused.

Introduction of AT89C52 Flash MCU
Figure 2 – External oscillator connection

3. The power-saving working mode of the CPU

AT89C52 has two power-saving modes that can be selected by software, namely idle working mode and power-down working mode. These two working modes are controlled by the PD (PCON.1) and IDL (PCON.0) bits in the dedicated register PCON (power control register).

PD is the power-down mode bit. When PD is 1, the power-down mode is activated, and IDL is the idle mode bit; when the IDL is 1, the idle mode is activated. If PD and IDL are 1 at the same time, the power-down mode is activated first.

This control system takes the P1 port of the single-chip microcomputer as the signal input terminal, and then connects the 0~6 sensors in sequence.

4. Clock circuit

Since the system needs to carry out some time-related controls, if a single-chip microcomputer is used for timing, it will cause larger errors over time. This requires the use of a real-time clock, and the control system uses the serial I²C/calendar chip HYM8563 produced by Wuhan Microelectronics Co., Ltd. HYM8563 is a low-power CMOS real-time clock/calendar chip. It provides programmable clock output, timer, alarm, interrupt output and power-down detector. All addresses and data are serially transmitted through the I²C bus interface, the maximum bus speed is 400kbits/s, and the working voltage range is 1.0~5.5V. Since the interrupt output and clock output of HYM8563 are both open-drain output, an external pull-up resistor is required.

There are 16 addressable 8-bit parallel registers inside HYM8563. The first two registers are used as control registers and status registers, 0FH is an 8-bit timer, controlled by the register (0EH), TD1 and TD0 are used to set the frequency of the timer (4096, 64, 1 or 1/60 Hz), and TE sets the timer on or off. TIE=1 is the timing interrupt enable control bit, TI/TP=0 is the interrupt signal low level/pulse mode selection. Therefore, set TE=1, TIE=1, TI/TP=0, set the frequency of the timer to 1/60Hz (ie 1min), set the time interval in 0FH, and set an interrupt when the timer counts down. The application mark is TF, and a low level is generated at the pin as an interrupt signal. The interrupt request flag is TF can only be cleared by software. When reading the timer, it returns the current countdown value.