如何在 Keil Microvision 软件中创建项目?
Keil Microvision 软件是用于执行汇编语言程序和嵌入式 c 程序的 IDE,您可以在 Keil Microvision 软件中创建 hex 文件,这就是为什么它是创建与 hex 文件相关的项目的最佳软件,例如 LCD 接口、步进电机接口、交通灯系统和与机器人技术相关的项目,因为在所有这些项目中,我们需要一个程序的 hex 文件,在将这个 hex 文件加载到 IC 中并将这个 IC 插入硬件套件中之后,您可以运行您的项目。在本文中,您将在 Keil Microvision 软件中逐步创建一个演示项目。
在 Keil Microvision 软件中创建项目
让我们一步一步创建一个红绿灯系统项目:
第 1 步:打开您的 Keil Microvision 软件,单击项目选择新的 Microvision 项目。
第 2 步:为您的项目起一个正确的名称,并以扩展名 .c 保存它,因为在这个演示项目中,我们使用的是嵌入式 c 语言。
第 3 步:现在选择一个微芯片 AT89S52,然后单击确定。
第 4 步:将在右侧打开一个项目窗口,您将看到目标 1 单击它,然后双击源组 1,然后选择您之前保存的文件并将其添加到源组并关闭它。
第 5 步:现在双击源组 1 下方可见的文件,将打开一个纯文本区域。
第 6 步:在纯文本区域中键入您的程序,然后单击构建以检查错误,然后单击重建。
这是交通灯系统的源代码。本源代码为嵌入式c语言
C
// C program for traffic light system
#include
void delay(int);
void delay(int itime);
void main()
{
P0 = 0x00; //Clears content of port0
P1 = 0x00; //Clears content of port1
while(1)
{
P0 = 0xDB; //First route is open for traffic flow
P1 = 0xDE; //First route is open for traffic flow
delay(1000); // Long delay
P0 = 0xDD; //First route switching for traffic flow
P1 = 0xDE; //First route switching for traffic flow
delay (100); // short delay
P0 = 0xF6; // Second route is open for traffic flow
P1 = 0xDE; // Second route is open for traffic flow
delay(1000); // Long delay
P0 = 0xEE; // Second route is open for traffic flow
P1 = 0xDE; // Second route is open for traffic flow
delay(100); // short delay
P0 = 0xDE; // Third route is open for traffic flow
P1 = 0xDB; // Third route is open for traffic flow
delay(1000); //Long Delay
P0 = 0xDE; // Third route is open for traffic flow
P1 = 0xDD; // Third route is open for traffic flow
delay(100); // Short Delay
P0 = 0xDE; // Fourth route is open for traffic flow
P1 = 0xF6; // Fourth route is open for traffic flow
delay(1000); // Long Delay
P0 = 0xDE; // Fourth route is open for traffic flow
P1 = 0xEE; // Fourth route is open for traffic flow
delay(100); // short delay
}
}
void delay(int itime)
{
int i,j;
for(i = 0; i < itime; i++)
for(j = 0; j < 2000; j++);
}
C
#include
void delay(int);
void delay(int itime);
void main()
{
P0=0x00; //Clears content of port0
P1=0x00; //Clears content of port1
while(1)
{
P0=0xDB; //First route is open for traffic flow
P1=0xDE; //First route is open for traffic flow
delay(1000); // Long delay
P0=0xDD; //First route switching for traffic flow
P1=0xDE; //First route switching for traffic flow
delay (100); // short delay
P0=0xF6; // Second route is open for traffic flow
P1=0xDE; // Second route is open for traffic flow
delay(1000); // Long delay
P0=0xEE; // Second route is open for traffic flow
P1=0xDE; // Second route is open for traffic flow
delay(100); // short delay
P0=0xDE; // Third route is open for traffic flow
P1=0xDB; // Third route is open for traffic flow
delay(1000); //Long Delay
P0=0xDE; // Third route is open for traffic flow
P1=0xDD; // Third route is open for traffic flow
delay(100); // Short Delay
P0=0xDE; // Fourth route is open for traffic flow
P1=0xF6; // Fourth route is open for traffic flow
delay(1000); // Long Delay
P0=0xDE; // Fourth route is open for traffic flow
P1=0xEE; // Fourth route is open for traffic flow
delay(100); // short delay
}
}
void delay(int itime)
{
int i,j;
for(i=0;i
第 7 步:单击调试开始调试部分,以检查您的代码是否正在运行或不单击外围设备,选择您在程序中使用的输入输出端口。
第 8 步:单击调试并运行程序,您将看到您选择的端口发生了一些变化,这意味着您的代码是正确的并且运行良好。
第 9 步:现在单击目标的项目选择选项,
第 10 步:将 Xtal 频率写为 11.0592
第 11 步:现在单击输出以选择保存 hex 文件的文件夹,选择文件夹,然后单击创建 HEX 文件并按确定。
第 12 步:再次构建并重新构建您的程序,您将收到一条创建 HEX 文件的消息。
第 13 步:检查您之前选择的文件夹上创建的 hex 文件 您不了解创建的 hex 文件中的任何内容,以便实时提供此交通灯系统项目 您需要将此 hex 文件传输到微处理器(8051),然后您需要将此微处理器芯片连接到交通灯系统的硬件套件。
以下是红绿灯系统的源代码:
Note: This source code is in embedded c language
C
#include
void delay(int);
void delay(int itime);
void main()
{
P0=0x00; //Clears content of port0
P1=0x00; //Clears content of port1
while(1)
{
P0=0xDB; //First route is open for traffic flow
P1=0xDE; //First route is open for traffic flow
delay(1000); // Long delay
P0=0xDD; //First route switching for traffic flow
P1=0xDE; //First route switching for traffic flow
delay (100); // short delay
P0=0xF6; // Second route is open for traffic flow
P1=0xDE; // Second route is open for traffic flow
delay(1000); // Long delay
P0=0xEE; // Second route is open for traffic flow
P1=0xDE; // Second route is open for traffic flow
delay(100); // short delay
P0=0xDE; // Third route is open for traffic flow
P1=0xDB; // Third route is open for traffic flow
delay(1000); //Long Delay
P0=0xDE; // Third route is open for traffic flow
P1=0xDD; // Third route is open for traffic flow
delay(100); // Short Delay
P0=0xDE; // Fourth route is open for traffic flow
P1=0xF6; // Fourth route is open for traffic flow
delay(1000); // Long Delay
P0=0xDE; // Fourth route is open for traffic flow
P1=0xEE; // Fourth route is open for traffic flow
delay(100); // short delay
}
}
void delay(int itime)
{
int i,j;
for(i=0;i