Learn 51 MCU-KEIL usage and program download

Publisher:ZhenxiangLatest update time:2020-07-23 Source: 51heiKeywords:KEIL  Download Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

      Many people will encounter the situation when learning single-chip microcomputers. The program is beautifully written and the principle is thoroughly understood, but... I don’t know how to use the compiler software and how to download the program. It seems that my teacher didn’t teach me this in college, haha. So today I will mainly talk about the application of these two software.


      Note: There are many types of microcontrollers, so there are naturally many types of compilation environments. It will definitely take some time to learn a compilation software, but the software interfaces are basically the same. Once you learn one, it will be quick to learn another. There is also a phenomenon that many people like to use the Chinese version, but I personally feel that it is unnecessary. First of all, the Chinese version is not necessarily standard; secondly, there are only a few words in the tool English, and it is OK to remember them. The Chinese version will increase unnecessary trouble.


      Okay, enough nonsense, let’s get started!


      Let's talk about Keil Uvision first. The first step is to double-click to open the software. The interface is as follows:

      To write code, you need to create a new project, click: Project->New uvision project, and the following interface will pop up:

      Create a separate folder for each project, such as LED01, and then enter the project name, which can be the same as the folder name, such as LED01. Click Save.


      Note: This software does not need to consider the issue of Chinese and English paths. As far as I can remember, when debugging CPLD, the project generated by the software will go wrong if it is saved in the Chinese path.


      After saving, the following interface appears:

      Select the chip to be used in this interface. We use STC89C52C microcontroller, which is not included here, but you can use ATMEL's AT89C52 instead. Find the corresponding chip, select it, and click OK. The following interface pops up, click No:

      The page is as follows:

      Next, we need to create a document and write the code in it. Click File->New, create a new page, enter main.c, and then click Save to save the file as a C file, as shown below. After using it more, you will know that the two most commonly used files in microcontrollers are C files and H files.

      

      Then right-click Source Group->Add Existing Files to Source Group 1, and the following interface pops up:

      Select the main.c file we just saved and click Add. Why do we emphasize clicking here? Because you won’t see any changes after clicking. The only change is that there is a plus sign in front of Source Group1. Then click Close to close the page.


      Click the plus sign in front of Source Group1, main.c will appear, double-click it, and you can enter the code on the right page. Paste yesterday's code in, click the save and rebuild buttons, both of which are on the upper left of the page, you can try to find them yourself.

      The results are as shown above, 0 errors, 0 warnings.


      After the compilation is completed, a hex file will be generated. This file is what we will eventually download to the microcontroller. When you open the project we created, you will find that you cannot find the hex file. Why? Because one step is missing, which is also something many people often forget. Click Project->Options for Target, and the following page will appear. Click output, as follows:

          Check Create HEX File, click OK, recompile and rebuild, and you will find that the hex file appears in the project folder.


          The above is the process of using the compilation software. I am a little dizzy after taking so many screenshots. Now let’s move on to the downloading process, which is much simpler.


      Currently, there are roughly two circuits for serial port downloading. One is a serial port circuit built with MAX232, which downloads through the UART port of the microcontroller, and the other side of the line needs to be connected to the UART port of the computer.


            However, today's computers, whether desktops or laptops, rarely have UART ports, so the second type emerged.


      The second method is to use USB to serial port, which converts the UART signal into USB signal. There are too many USB ports on computers, so this is convenient. The chip I use is CH340T. When using this type of chip, you need to install the driver on the computer. I will upload the driver to the attachment later.


      After the driver is installed, right-click My Computer - Manage - Device Manager - Port and the COM port used will be displayed.


      I used the second method, connecting the board to the computer and keeping it powered on. Open the software STC-ISP, the page is as follows:

      Follow the instructions

      Step 1: Select the microcontroller: STC89C52C

      Step 2: Open the program file and select the hex file we just generated.

      Step 3: Select the port and baud rate. The port we selected is the one we saw in the device manager-port. Mine is COM2. The highest baud rate is 115200 and the lowest is 2400.

      Step 4: Do not change the current configuration.

      Step 5: Click Download, then press the power button on the board to turn off the power, and then press it again to turn it on. If the program is successfully written, the following information will be displayed:

      Well, so far, the use of compiling software and downloading software has been explained. You may learn it after reading it once and never read it again, but as long as it helps you, it is worth it. The programs and codes used in the tutorial are in the attachment, download them if you need them.

Keywords:KEIL  Download Reference address:Learn 51 MCU-KEIL usage and program download

Previous article:Learning 51 MCU - instruction cycle and LED flashing
Next article:Preparation for learning 51 single chip microcomputer

Latest Microcontroller Articles
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号