Keil5MDK creates C51 project

Keil5MDK creates C51 project

1 Overview

The previous article introduced the installation of Keil5MDK and C51 tools. This article introduces the use of the tools. First, it introduces how to create a 51 microcontroller project, write a demo program, compile it, and burn it to the microcontroller.
The address of the first installation tool article: https://blog.csdn.net/m0_38039437/article/details/134599013

2. Create 51 microcontroller project

2.1.Create project

1. Create a project.
Open the Keil tool and click ProjectSelect.New uVision Project
Insert image description here

2. Enter the project name
, create a folder to store the project, and name the folder with the project name.
Insert image description here

Enter the created project folder and enter the project name

Insert image description here

3. Select the microcontroller model used in the project.
I am using the STC12C2052 microcontroller, which is domestically produced. The Keil software is foreign, so there is no such model. Here you can choose AT89C55, which is a common model for 51 microcontrollers.

Insert image description here

4. Initialize the microcontroller.
Copy the 8051 startup code to the project and initialize it when the microcontroller starts. You can choose any one here, it won’t make any difference, this time the choice is.
Insert image description here
5. The project creation is completed.
The project directory we created is displayed on the left side of the window.
Insert image description here

View the project directory to display the created files
Insert image description here

2.2.Create files

1.Create a new file
and click FileSelectNew
Insert image description here

Insert image description here

2. Save the file.
Select the save path under the project path C51PJT
and customize the file name. The suffix must be .c, it is a C language file.

Insert image description here

3. Add files to the project
Right Source Group1-click and select Add Existing File to Group 'Source Group1', which in Chinese means to add existing files to Source Group1the group.

Insert image description here

Select led.cthe file, click Addthe Add button, and click Closeto close the window.
Insert image description hereled.cThe file has been added to the project
Insert image description here
4. Set the compilation output format
Click Target魔法棒log图标, click Output, select Create HEX FileClick OKto close the window
Insert image description here

5. Set the encoding format.
In order to avoid garbled Chinese characters when writing code, set the encoding format below to support Chinese.
Click 设置the icon, select Editor, and Encodingselect UTF-8the encoding format in
Insert image description here

3. Develop Demo program

1. Program code

A demo program for LED flashing is provided below. Copy the code to led.ca file.


/*************************************************************
* 程序名 * 点亮LED灯
* 编写人 * Bruce 
* 日  期 * 2023-11-24
/*************************************************************/

/*************************************************************
* 头文件定义 *
/*************************************************************/
#include <AT89X52.h>

/*************************************************************
* IO定义 *
/*************************************************************/
sbit LED    =   P1 ^ 7;		//定义P1.7为LED控制口,低电平使能

/*************************************************************
* 毫秒级延时函数 *
调用函数必须给延时函数一个0~65535的延时值对应0MS到65535MS
/*************************************************************/
void Delay (unsigned int a){
    
    				//需要输入变量值0~65535
		unsigned int i;
		while( --a != 0){
    
    					//i 从0加到600,CPU大概就耗时1毫秒
				for(i = 0; i < 600; i++);	//空指令循环		
		}
}
/*************************************************************
* 主函数 *
实验板上连接到单片机上的LED闪烁程序
/*************************************************************/
void main (void){
    
    		//
	while(1){
    
    			//无限循环以下程序
		LED = ~LED;		//取LED相反状态
		Delay(250);		//修改这里的数值看看会有什么变化
	}					//(0~65535之间)
}


Click the compile button. If there is no error message in the compilation output column, it means that the file is compiled successfully.
Insert image description here

2.Circuit principle

Insert the positive pole of the LED light into the 20th pin VCC of the microcontroller, and the negative pole into the 19-pin IO port
Insert image description here

3.Experimental results

1. Open the STC-ISP tool, select the compiled c.hexfile, and burn it to the microcontroller

Insert image description here

Guess you like

Origin blog.csdn.net/m0_38039437/article/details/134604477