Keil Logo

C51: Adding to the Startup Code


Information in this article applies to:

  • C51 All Versions

QUESTION

How do I add code to the startup routines so that it executes before the main C function?

ANSWER

The startup code is very easy to modify. First, you must copy the proper startup code into your project folder and add it to your project.

Then, you must add your code to the correct place in the startup code. The following listings show excerpts from the startup code.

                CSEG    AT      0
?C_STARTUP:     LJMP    STARTUP1

This is the RESET vector. On the 8051, the reset vector is located at address 0000h (unless it has been moved to work with a target monitor or boot loader). Note that the reset vector is simply an LJMP to the startup code. The reset vector MUST be an LJMP because the first interrupt vector is located at address 0003h.

                RSEG    ?C_C51STARTUP

STARTUP1:

The next lines of code define a relocatable segment (named ?C_C51STARTUP) and a label (STARTUP1). Note that this is the label that the reset vector jumps to. Your initialization code should typically go immediately after this label.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.