Keil uVision4起步簡單程式設計 __note1
本例編寫一個對應晶片的延時函式並呼叫之:
開啟Keil uVision4,點選project,New一個uVision4 Project:

放在test檔案下:

選擇晶片:


ctrl+N 建立三個檔案(main.c/delay.c/Delay.h),這裡debug一下標頭檔案和原始檔的聯編,實際上也可以將Delay.h以及delay.c的內容放進main.c中:

#include <reg51.h> #include <Delay.h> void main(void) { P2=0x0f; while(1) { Delay10ms(100); P2=~P2; } }
該晶片的延時10ms的函式:

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

#ifndef _DELAY_H_ #define _DELAY_H_ void Delay10ms(int ms); #endif
檔案編寫完畢,右鍵資料夾Source Group 1,使用Add Files to Group 'Source Group 1'的方式依次將檔案新增進目錄:


下面是檔案目錄:

編譯:
