Generation of C51HEX file and single-chip minimum system

Publisher:心灵的旅程Latest update time:2012-09-21 Source: 21IC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the previous article, we established the first single-chip C language project. However, in order to allow the compiled program to be written into the 51 chip through the programmer, we need to use the compiler to generate a HEX file first. Let's take a look at how to use KEIL uVISION2 to compile and generate a HEX file for burning the chip. The HEX file format is data information arranged by address proposed by Intel. The data width is bytes. All data is represented by hexadecimal numbers. It is often used to save the target program code of the single-chip or other processors. It saves the target code image in the physical program storage area. General programmers support this format. Let's open the first project first, open its directory, find the test.Uv2 file, and then open the previous project. Then right-click the 1 project folder in Figure 2-1, the project function menu pops up, select Options for Target'Target1', and the project option setting window pops up. Also select the project folder icon first. At this time, there is also a same menu available in the Project menu. Open the project option window, go to the Output option page as shown in Figure 2-2. In the figure, 1 is to select the path for the compilation output, 2 is to set the file name generated by the compilation output, and 3 is to decide whether to create a HEX file. Select it to output the HEX file to the specified path. Have you chosen? Well, we will recompile it again, and soon the compilation information window will show that the HEX file has been created in the specified path, as shown in Figure 2-3. In this way, we can use the software attached to our programmer to read and burn it to the chip, and then use the experimental board to see the results. As for the various types of programmers or emulators, the specific methods can be found in their manuals, and they will not be discussed here.

(Tips: 1. In the project file tree in 1 in Figure 2-1, select the object first, then click it to rename it, and double-click the file icon to open the file. 2. At the bottom of the Project drop-down menu, there is a list of recently edited files.

The project path is saved here, and the most recently edited project can be quickly opened here.

Figure 2-1 Project function menu

Click to browse the next page

Figure 2-2 Project Options Window

Click to browse the next page

Figure 2-3 Compile Information Window

Perhaps you have burned the compiled file to the chip. If you buy or make a learning experiment board with serial port output components, you can connect the serial port to the PC serial port and use the serial port debugging software or Windows HyperTerminal to set the baud rate to 1200, and you can see the words "Hello World!" being output continuously. If you don't have an experiment board yet, let's talk about the AT89c51 minimum system first, and then use an example program to verify whether the minimum system is running. This minimum system is also easy to make for experiments. Figure 2-4 is the AT89c51 minimum system. However, in order to let us see that it is running, a resistor and an LED are added to display its status. The crystal oscillator can be used according to your own situation. Generally, 11.0592MHz or 12MHz is used on the experiment board. The advantage of using the former is that it can generate a standard serial port baud rate, while the latter has a machine cycle of 1 microsecond, which is convenient for precise timing. In my own experiments, please note that VCC is +5V, which cannot be higher than this value, otherwise the microcontroller will be damaged. If it is too low, it will not work properly. Pin 31 must be connected to a high level so that we can execute the program in the chip. If it is connected to a low level, the program memory outside the chip will be used. Let's create a new project named OneLED to verify whether the minimized system can work. The program is as follows:

[page]

#include //Preprocessing command

void main(void) //main function name

{

//This is the first comment method

unsigned int a; //define variable a as int type

/* This is the second comment type

*/

do{ //do while loop

for (a=0; a<50000; a++); //This is a loop P1_0 = 0; //Set P1.0 port to low level and turn on the LED for (a=0; a<50000; a++); //This is a loop P1_0 = 1; //Set P1.0 port to high level and turn off the LED

}

while(1);

}

Click to browse the next page

Figure 2-4 AT89c51 Minimized System

Here we will first talk about the comment statements supported by the KEIL C compiler. One is the statement that starts with the "//" symbol. The statements after the symbol are considered comments until there is a carriage return. The other is the comment within the "/*" and "*/" symbols. Comments will not be compiled by the C compiler. A C application program should have a main function, which can call other functions.

function, but other function are not allowed to call main function. No matter where the main function is placed in the program, it is always executed first. Use the knowledge learned above to compile the OneLED program and burn it into the newly made minimized system. Power on, the LED is not bright at first (because all IO ports are set to 1 pins at high level after power-on reset), then delay for a period of time (for (a=0; a<50000; a++) is running), the LED is bright, and then delay again, the LED goes out, and then alternately lights up and goes out. The first real small experiment is done. If there is no such effect, then you should carefully check the circuit or the steps of compiling and burning.

Reference address:Generation of C51HEX file and single-chip minimum system

Previous article:MCU C Language Tutorial: C51 Variables
Next article:MCU C language tutorial: Building your first KeilC51 project

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号