1 / 15

單元一

單元一. Keil C. C 和 VB 的不同. Keil C 的程式結構. // 前端處理器 #include <reg51.h>. // 變數及自定函數宣告區 void delay(int); int i;. // 主程式. main() { while(1) { } }. // 自定函數區 ( 即副程式 ). void delay(int x) { }. Keil C 標頭檔 reg51.h.

jovita
Download Presentation

單元一

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 單元一 Keil C

  2. C和VB的不同

  3. Keil C的程式結構 //前端處理器 #include <reg51.h> //變數及自定函數宣告區 void delay(int); int i; //主程式 • main() • { • while(1) • { • } • } //自定函數區(即副程式) void delay(int x) { }

  4. Keil C標頭檔 reg51.h Keil C已定義好的標頭檔 reg51.h 檔案裏主要存放8051單晶片中的一些特殊暫存器,例如:輸出入埠-P0、P1、P2、P3;累積器ACC等。

  5. Keil C數值型別 Keil C專屬:

  6. Keil C記憶體類型 Keil C專屬:

  7. 變數宣告 Keil C的變數宣告格式如下: 資料型態 [記憶體類型] 變數名稱[=預設值]; 範例: int x; int x=100; int x,y,z; unsigned char x; unsigned char code x; sbit led1=P1^0; bit flag=0;

  8. 函數(副程式)宣告 宣告格式如下: 傳回引數的資料形態 函數名稱(傳入參數) • 傳回引數之資料型態: 若函數的運算結果需傳回給程式使用,則要依傳回值的資料型態來宣告,若無需傳回任何資料則以void代替。 • 傳入參數: 若函數在執行時需由呼叫它的程式提供一參數以供運算,則可在此欄位中指定,此傳入之引數亦可為多個,但一定要明確的指定其資料型態,若沒有可空白不打。

  9. 函數(副程式)宣告範例

  10. 主程式 main() 在C語言中,定會有一個名為 main() 的程式段,這個程式段就是 C 的主程式,即程式在執行時會從 main() 開始;而對8051而言,在main()裏一定會有一段無窮迴圈 Main() { while(1) { 單晶片的要重覆執行的主程式 } }

  11. C的四則運算

  12. C的關係運算(用於判斷程式) 關係運算的結果不是1(TRUE)就是0(FALSE)

  13. C的邏輯運算(用於判斷程式) 此處的邏輯運算是以TRUE和FALSE為運算對像(非數值,數值的邏輯運算在C中稱為位元運算,符號亦不同)

  14. C的位元運算 設x=01110010,y=11001100 關係運算的結果不是1(TRUE)就是0(FALSE)

  15. C的運算優先順序

More Related