STC12 MCU realizes automatic program download

Publisher:水手谷水手Latest update time:2019-05-11 Source: eefocusKeywords:STC12 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are two program areas in the STC microcontroller, the user program area and the ISP program area.


After the microcontroller is powered on (cold start, not external manual reset or watchdog reset), the ISP program will be run first to detect whether there is a legal download command flow, which takes tens to hundreds of milliseconds. 

If there is no legitimate download command stream, the user program is run immediately. 

If there is a legitimate download command stream, the ISP monitoring program starts to communicate with the ISP download software, and the software also enters the programming mode and sends the program code to the monitoring program. The monitoring program receives the program code and writes it into the user program area. 

After programming is completed and the program is successfully verified, the user program takes effect immediately and starts running.


If the IAP_CONTR register is not set in the software through the serial port with the host computer (such as the following program), when STC-ISP tries to handshake with the MCU, it will continuously send the "0x7F" signal from the serial port at the baud rate in the "minimum baud rate" setting item until the power-on cold start (or soft reset to ISP) detects the download command flow for tens to hundreds of milliseconds, and then stops sending the "0x7F" signal. 

If IAP_CONTR is set, the corresponding setting related commands will be executed.


#include


unsigned char RevData;

//void UartInit()   

//{

// PCON &= 0x7F;   

// SCON = 0x50;    

//AUXR &= 0xBF;   

// AUXR &= 0xFE;   

// TMOD &= 0x0F;   

// TMOD |= 0x20;   

// TL1 = 0xFD; 

//TH1 = 0xFD; 

//ET1 = 0;        

// TR1 = 1;        

//}

void UartInit()

{

    AUXR &= 0xF7;       

    S2CON = 0x50;       

    AUXR &= 0xFB;       

    BRT = 0xFD; 

    AUXR |= 0x10;   

}



void main()

{

    UartInit();

    EA = 1;

    ES = 1;

    P0 = 0;

    while(1);

}



void Uart() interrupt 4

{

    if(RI)

    {

        RI = 0;

        RevData = SBUF;

        if(RevData == 0x0a)

        {


            IAP_CONTR=0x60; 

        }

    }

    if(TI)

    {}

}

Write the picture description here


Keywords:STC12 Reference address:STC12 MCU realizes automatic program download

Previous article:Using the PWM function of the microcontroller to realize DAC with the help of filters
Next article:I2C communication timing problem of 89 and 12 microcontrollers

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

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号