Microcontroller C language tutorial: C51HEX file generation and microcontroller minimum system

Publisher:SparkCrafterLatest update time:2013-03-04 Source: 21icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The first MCU C language project has been established. However, in order to allow the compiled program to be written into the 51 chip through the programmer, the compiler must be used 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, and all data is represented by hexadecimal numbers. It is often used to save the target program code of the MCU 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 you can 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, and the same menu is available in the Project menu at this time. 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 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 made your choice? OK, 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

 

Microcontroller C language tutorial: C51HEX file generation and microcontroller minimum system

 

Figure 2-2 Project Options Window

 

http://www.21ic.com/mcu/

Figure 2-3 Compile Information Window [page]

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 minimum system of AT89c51. 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 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. It 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. Next, create a new project named OneLED to verify whether the minimized system can work. The program is as follows:

#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);

}

 

http://www.21ic.com/mcu/

 

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 should have a main function. The main function can call other functions, but other functions are not allowed to call the 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 written OneLED program and burn it into the newly built minimized system. Power on, the LED is not on 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 on, and then delay again, the LED goes out, and then alternately on and off. 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.

Keywords:MCU Reference address:Microcontroller C language tutorial: C51HEX file generation and microcontroller minimum system

Previous article:MCU C Language Tutorial: Appendix 1 Extended Keywords of C51 Compiler
Next article:Microcontroller C language tutorial: Use of C51 pointers

Recommended ReadingLatest update time:2024-11-16 20:56

Four stages of microcontroller learning 
    The first stage   is to browse the hardware part in the textbook first, and roughly understand the hardware structure of the single-chip microcomputer. Such as   ROM, RAM, address, I/O port, etc., and read some manufacturers' MCU data (Data Sheet) to strengthen the impression of the various resources provided by t
[Microcontroller]
51 MCU peripheral module——DS1302 clock module
1. Main performance indicators of DS1302 The DS1302 real-time clock has the ability to calculate seconds, minutes, hours, days, dates, weeks, months, and years before the year 2100, and can also adjust for leap years. Contains 31 bytes of static RAM internally and is user accessible. The serial data transmission metho
[Microcontroller]
51 MCU peripheral module——DS1302 clock module
MCS-51 MCU Register Function
The 21 special function registers (26 in the 52 series) are discontinuously distributed in the 128-byte SFR storage space, and the address space is 80H-FFH. In this SFR space, there is a 128-bit address space, and the address is also 80H-FFH, but there are only 83 valid bit addresses. Bit addressing operations can be
[Microcontroller]
MCS-51 MCU Register Function
Research and development of pressure measurement control system based on single chip microcomputer
1 Introduction At present, China is developing coal production mechanization rapidly. The application of comprehensive mining equipment is a measure to improve efficiency and safety. One of the main factors affecting the start-up rate is the control of the roof of the working face by the support. Therefore, i
[Microcontroller]
Research and development of pressure measurement control system based on single chip microcomputer
Design of fan temperature control system based on single chip microcomputer
0. Introduction Fans are general-purpose machines, which are widely used in various sectors of the national economy. Fans are widely used in ventilation, dust removal and cooling of factories, mines, vehicles, buildings, household appliances, etc.; drying and selection of grains; wind tunnel wind source and infl
[Microcontroller]
Design of fan temperature control system based on single chip microcomputer
Eight steps to learn microcontrollers
  Step 1: Use of digital I/O   Use buttons to input signals and LEDs to display output levels, and you can learn the digital I/O function of the pins. After pressing a button, a LED lights up. This is the function of combinational logic in digital circuits. Although it is very simple, you can learn general MCU program
[Microcontroller]
C51 MCU interrupt function
Take serial port interrupt as an example:   like: void serial() interrupt 4 {   } and void serial_uart() interrupt 4 {   } The functions of both functions are to define the serial port interrupt function. It is not important that the function names are different, but the interrupt 4 (interrup
[Microcontroller]
The rise of Renesas MCU in recent years
Friends who often read my official WeChat public account articles should have noticed that I have shared a lot about Renesas MCU this year. Again, you will find that Renesas Electronics has developed rapidly in recent years, with a large number of online and offline activities, and new MCU products cons
[Automotive Electronics]
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号