Keil uVision4起步简单编程 __note1

本例编写一个对应芯片的延时函数并调用之:

打开Keil uVision4,点击project,New一个uVision4 Project:

Keil uVision4起步简单编程 __note1

放在test文件下:
Keil uVision4起步简单编程 __note1

选择芯片:
Keil uVision4起步简单编程 __note1

Keil uVision4起步简单编程 __note1

ctrl+N 创建三个文件(main.c/delay.c/Delay.h),这里debug一下头文件和源文件的联编,实际上也可以将Delay.h以及delay.c的内容放进main.c中:
Keil uVision4起步简单编程 __note1

   #include <reg51.h>
   #include <Delay.h>
   void main(void)
   {
        P2=0x0f;
        while(1)
        {
            Delay10ms(100); 
            P2=~P2;
        }
   }

该芯片的延时10ms的函数:

Keil uVision4起步简单编程 __note1

    Delay10ms(int ms)
    {
        int i;
        unsigned char tem;
        for(i=0;i<ms;i++)
            for(tem=0;tem<120;tem++){}
    }

Keil uVision4起步简单编程 __note1
    #ifndef _DELAY_H_
    #define _DELAY_H_
    void Delay10ms(int ms);
    #endif

文件编写完毕,右键文件夹Source Group 1,使用Add Files to Group 'Source Group 1'的方式依次将文件添加进目录:

Keil uVision4起步简单编程 __note1

Keil uVision4起步简单编程 __note1

下面是文件目录:
Keil uVision4起步简单编程 __note1

编译:
Keil uVision4起步简单编程 __note1