Introduction to the method of programming the ISP protocol of STC microcontroller

Publisher:ping777Latest update time:2012-11-08 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The STC microcontroller contains two Flash blocks. The program running in one Flash can erase and reprogram the other Flash. Generally, the ISP program is stored in a Flash with a smaller capacity (Block1), and the user code is stored in a Flash with a larger capacity (Block0). The ISP program in Block1 erases and reprograms the user code in Block0. Friends who are doing STC microcontroller decryption or using it know that there is a section of about 3K code after the program storage area of ​​the STC microcontroller. This code is the ISP program of the STC microcontroller. There is information about ISP in the data sheet of the STC microcontroller. Since this code can be upgraded, we can be sure that this area can be rewritten. Haha, these involve the technology of soft decryption of STC microcontrollers. I won’t say more. You can use your own wisdom.

The following is some information for designing your own STC ISP protocol. Many application systems require program code upgrades. If the program code is in an external Flash memory, the program code upgrade can be implemented by directly operating the external Flash. However, for some system program codes inside the microcontroller, the microcontroller is required to support the IAP (In-Application-Programming) function. This article introduces the ISP (In-System-Programming) programming method in this case, as well as its specific implementation on SST and STC microcontrollers.
1 Basic structure of ISP implementation
There are many ways to implement ISP, but they generally follow the process shown in Figure 1.



Figure 1


Among them, there are generally the following ways to judge the user ISP selection.
(1) Connect to the computer system and select by the system command
When entering the user ISP selection judgment, the microcontroller first sends specific feature data, and then waits for the command data. If the selection command sent by the computer system is received within a certain period of time, it will enter the user code upgrade, otherwise it will jump directly to the user code execution.
(2) Select by the jumper on the user board
Generally, a code upgrade selection jumper is designed using the spare port of the microcontroller. When entering the user ISP selection judgment, the microcontroller can directly determine whether to enter the user code upgrade or directly jump to the user code execution based on the status of this port.
(3) Select by the user board operation function
In the function menu or function combination of the user board, the user is allowed to select the code upgrade function, and at the same time, the corresponding flag is stored in the external memory. When the code upgrade function is selected, specific data is written in the external memory, and then the program is reset. When entering the user ISP selection judgment, the data in the external memory is judged. If it meets the conditions, it will enter the user code upgrade, otherwise it will jump directly to the user code execution.
2 IAP Program
Design At present, many microcontrollers support IAP function. Generally, these microcontrollers contain two Flash blocks. The program running in one Flash can erase and reprogram the other Flash. Generally, the ISP program is stored in a Flash with smaller capacity (Block1), and the user code is stored in a Flash with larger capacity (Block0). The ISP program in Block1 erases and reprograms the user code in Block0.
The following introduces the IAP program design by taking two 51 series compatible Flash microcontrollers as examples. One is SST89C54 and the other is STC89C516RD.
(1) SST89C54 related features
SST89C54 has 20KB (16KB+4KB) program memory inside, with unified addressing. Block0 is 0000H~3FFFH; Block1 is F000H~FFFFH. Block1 can be selected to map to the 1KB/2KB/4KB program area starting from address 0000H.
(2) STC89C516RD related features
SST89C516RD has 72KB (64KB+8KB) program memory. Block0 is 0000H~FFFFH, and Block1 can be mapped to the 8KB program area starting from address 0000H (power-on reset defaults to address mapping).
The IAP operation of SST and STC microcontrollers is almost exactly the same. The C program source code IAP.C of the IAP function is given on the website of this journal (www.dpj.com.cn). It should be noted that the selection of block0 in the Block0_erase function is different for the two microcontrollers (just the opposite).
3 Switching from ISP program to user code
In design, the ISP program is generally designed as a program that runs after power-on reset. If the user code does not need to be upgraded or after the upgrade is completed, the program must be switched to user code execution. The switching from ISP program to user code varies from microcontroller to microcontroller.
(1) The switch from SST89C54 program area Block1 to Block0 is realized
when the SST89C54 microcontroller is burned, the ISP program is written to Block1, and the burn mapping selection bit RB0/RB1 (RE-MAP[1:0]) is set. In this way, when the program is powered on and reset, Block1 is automatically mapped to the 4KB program area starting at address 0000H, and the ISP program is executed. Since Block1 is also allocated at address F000H~FFFFH, when compiling and generating the ISP program code, all address ranges are set to F000H~FFFFH. When it is necessary to switch to the user code (Block0) to run, Modify the SFCF[7] control bit VIS, cancel the 0000H address mapping of Block1, and then jump to address 0000H to execute, and then start running the user code program in Block0. The
ISP C program source code ISP.C is given on the website of this magazine. It should be noted that this program needs to create a project file in Keil-C, including
IAP.C function and STARTUP.A51, and the definition of STC should be removed in IAP.C and ISP.C. In order to set the address range to F000H~FFFFH, the program entry address in STARTUP.A51 should be changed from 0 to 0F000H, as follows:
CSEG AT 0F000H
C_STARTUP: LJMP STARTUP1.
You also need to modify the compilation options in the Target tab to set Off-chip Code memory: Start
= 0xF000; Size = 0x1000; and set the C51 tab to set Interrupt Vectors at address: 0xF000.
(2) Switching from Block1 to Block0 in the STC89C516RD program area
When the STC89C516RD microcontroller is burned, the ISP program is written to Block1. (Note: the SC0/SC1 bit is not burned). When the microcontroller is powered on and reset, the default Block1 is mapped to the 8KB program area starting at address 0000H and enters the ISP program execution. When it is necessary to switch to the user code (Block0) to run, the ISP modifies the SFCF[1] control bit SWR to generate a soft reset (Software Reset). Since SC0 and SC1 are not burned, after the program is soft reset, Block1 will no longer be mapped to the address 0000H, and the user code program in Block0 will start to run.
The ISP C program source code ISP.C is given on the website of this magazine. It should be noted that this program needs to create a project file in Keil-C, including the IAP.C function, and the definition of STC must be retained in IAP.C and ISP.C.

4 Communication protocol with computer
When upgrading user code, it is necessary to communicate with the computer. RS232 serial communication is generally used, and the data protocol adopts a simple protocol. This protocol refers to the ISP data protocol of the ADuC812 microcontroller. (ADuC812 microcontroller hardware has a built-in ISP program).
(1) Reset command (computer → microcontroller)
The computer sends a 4-byte reset command: 21H, 5AH, 00H, A6H, and the microcontroller returns reset information.
(2) Reset information (microcontroller → computer)
The reset information is 25 bytes, the first 3 bytes are the microcontroller company's characteristic characters (such as: "ADI", "SST", "STC"), and the last 1 byte is the checksum.
(3) Data packet format (computer → microcontroller)
The computer sends a data packet format: 07H, 0EH, length, data, checksum (length and data checksum).
(4) Erase
command The computer sends a data packet, which contains only 1 byte of data and the content is: character "A" or "C". After erasing the user program area, the microcontroller returns 1 byte 06H to indicate success; 05H indicates failure.
(5) Programming command
The computer sends a data packet, which contains: "W", 00H, address high byte, address low byte, program data. The microcontroller returns 1 byte 06H to indicate success; 05H indicates failure.
(6) Run user program
The computer sends a data packet, which contains only 1 byte of data and the content is: character "U". The microcontroller returns 1 byte 06H to indicate success, and then jumps to the user program to run.
This magazine website provides the C program source code Download.C ​​for computer download software. Conclusion Based on the above ISP program design ideas and examples, you can modify the ISP initial code, or enrich its ISP functions (read function, password control, etc.), and try to design your own ISP program, which will definitely add a lot to your system.

Reference address:Introduction to the method of programming the ISP protocol of STC microcontroller

Previous article:Design and implementation of DC ripple tester based on STC89C52 single chip microcomputer
Next article:Design of power-free electronic lock system using STCl2C2052

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号