Design of online Programming Control System Based on AT89S52 and PIC16F877A

Source: Internet
Author: User

Author: Chen jingxian Chen Zhisheng Source: modern electronic technology
Keywords:Download input byte Communication

L Introduction

Generally, in the experiment or development of single-chip microcomputer, programmers are essential in traditional parallel programming methods. After simulation and debugging, the program needs to be burned into the single-chip microcomputer or external program memory with the help of the programmer. During the development process, each time the program changes, it is necessary to unplug the chip on the circuit board and program it before inserting it. With the development of computer technology, many companies have launched MCU with in-chip Flash memory. Flash Memory has the features of electric erasable, no backup power protection data, and online programming. Online programming currently has two methods: Online System Programming (ISP) and online application programming (IAP ). Generally, the ISP program the flash memory in the single chip microcomputer through the serial programming interface dedicated to the single chip microcomputer, for example, AT-MEL company SCM AT89S52 provides a SPI serial interface for internal program memory programming (ISP ).

Online programming (ISP) allows the program running inside the microcontroller to rewrite the content of flash memory. Some operation parameters can be modified during the operation, programmed devices can also be erased or re-programmed using ISP. When a single-chip computer is powered on In ISP mode, it can perform ISP operations. In ISP mode, a single-chip computer communicates with an external host (such as a PC or terminal) through a serial port to receive commands and data from the host, used to erase and re-program the code storage area. ISP generally only requires a small number of external circuits for implementation. With ISP technology, you can program the chip by connecting to a download line. You can experiment and develop a single-chip microcomputer without a programmer, single-Chip Microcomputer chips can be directly welded to the circuit board. After debugging, the chip can be finished, or even be remotely upgraded or changed online.

2. Principle of AT89S52 ISP

AT89S52 has the ISP function. When the reset pins are in high-power periods, p1.5 (MoSi), p1.6 (Miso), and p1.7 (sck) pins are used to set or transmit data for program download. p1.5 (MoSi) the pin serves as the input port of the serial command, the p1.6 (Miso) PIN serves as the output port of the serial data, and the p1.7 (sck) PIN serves as the input port of the serial shift pulse.

The flash Address addressing in the at89s series is in bytes. during use, pay attention to the differences between high and low bytes. When the host computer communicates with the target board, it is generally a 4-byte instruction, 1st bytes indicates the operation code, 2nd bytes indicates the address code, and 3rd bytes indicates the data.

You can complete online download operations by downloading the waveform diagram in sequence and downloading the programming instruction set in sequence.

3 design of online programming control system

3.1 System Structure

AT89S52 is responsible for information interaction between man-machine interfaces. It consists of the display, keyboard, and data path.

The display part consists of the P1 and P2 ports of AT89S52. P2 is the eight-bit display data path, p1.1 ~ P1.4 is the Enable line of four LEDs to dynamically display 4-bit data.

The keyboard consists of int0, int1, ct0, and ct1. Interrupt priority Nesting is used to input commands and data, reducing the size of the keyboard. The hardware allocation is as follows:

The data path is mainly controlled by PSP. PSP is a general data port dedicated to 8-bit machines by the pic16fx series microprocessor. It consists of CS, wR, RD and 8-bit data lines and can be directly controlled by AT89S52.

When PIC receives PSP data, it generates an interrupt response, which is determined by the software designer. Therefore, you can set 0xc0 ~ 0xff is the command byte for control, 0x00 ~ 0x09 is the function number, which can be combined to implement various control commands.

Pic16fx has 4 A/D channels, precision is 10 B, conversion time is 56 μs. The built-in Hardware Watchdog Circuit improves reliability and reduces software costs. The four-way interrupt function is used to realize the system reset and repair and test functions. The PGM interface (online programming interface) can be programmed and debugged online using the icd2 adapter. System Structure 1.

3.2 system functions

(1) The frequency of AT89S52 is 4 MHz. It provides online programming without the need for a programmer to directly burn and write data. It can be set to AT89S52 [int0], [int1], [ct0], [CT1] The four pins are extracted separately to facilitate the keyboard interface.

(2) AT89S52 p1.1 ~ P1.4 is used as led1 ~ 4 enable line, effective at high level, P2 port as led1 ~ The four-digit eight-digit display data port.

(3) The AT89S52 serial port can communicate with the 16f877a serial port directly.

(4) AT89S52 P0 port and [ale 10 p1.0], [WR], and [RD] serve as 8-bit parallel port to communicate with 16f877a.

(5) PIC16F877A: 20 MHz:

① PA-AN [0]-onboard A/D channel: vref +/-adjustable

An [1], [5] An external A/D channel, an [2-3]-vref +/-adjustable, an [4]-T0CKI-WDT monitoring.

② PB-PB0-External int interrupt signal, low level/descent along valid, PB1, 2, 4, 5 as input1234, low level/descent along valid.

3.3 circuit schematic

The circuit principle 2 of the AT89S52 part is shown in.

The principle of Circuit section 3 of PIC16F877A is shown in.

4. Software Design

4.1 part AT89S52

First, execute system initialization, initial clock, global variable, timer, IO port, and keyboard interrupt service subroutine.

Then enter the mainloop program and wait for the keyboard to be interrupted. If the keyboard has an input action, the system will interrupt the keyboard and enter the keyboard interrupt service subroutine.

The main function of the keyboard interrupt service subroutine is to generate command data packets and process the command data packets according to user instructions.

The command data packet format is as follows:

If confirmed by the user, it will be sent to PIC16F877A for execution;

If you cancel the operation, exit the keyboard interrupt service subroutine and enter the waiting state again. The system running flowchart 4 is shown in.

4.2 PIC Software Structure

After the PIC system is initialized, the PWM output is started according to the default parameters. The A/D conversion is continuously performed during the startup process, and the collected data is adjusted according to the PID policy to adjust the PWM duty cycle, in this way, the motor speed can be adjusted without interrupting the PSP channel. If you receive the AT89S52 command packet, update the default startup parameter immediately, let the motor run at the new speed in the new parameter mode.

The flowchart 5 of the software execution process is shown in PIC16F877A.

5 knots

Using AT89S52 as the main processor and pic16f87x as the slave processor can greatly improve the control accuracy and reach 10-bit PWM accuracy. AT89S52 and pic16f87x provide online programming functions, complete functions, and rich on-chip resources to meet system upgrade requirements. With the widespread application and development of single-chip microcomputer with system online programming function, ISP technology has become the future development direction, and the application of control systems based on online programming technology will become more and more extensive.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.