1 / 15

南台科技大學 機電整合系統程式 期末報告

南台科技大學 機電整合系統程式 期末報告. 指導 教授 : 余遠渠 組員 : 葉致邑 (4A112001) 蕭亦宏 (4A112070) 涂家睿 (4A112094) 書面報告製作 : 涂 家 睿 . 序論. 第一 節 機電整合創新概念

derry
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. 南台科技大學 機電整合系統程式期末報告 指導教授:余遠渠 組員: 葉致邑(4A112001) 蕭亦宏(4A112070) 涂家睿(4A112094) 書面報告製作: 涂家睿

  2. 序論 第一節機電整合創新概念 第二節程式架構與系統架構圖 第三節心得報告

  3. 機電整合創新概念 • 第一百八十九條    特別安全梯或緊急昇降機間排煙室之排煙設備,依下列規定選擇設置二、設置排煙、進風風管時,應符合下列規定:(四)排煙機、進風機之排煙量、進風量在每秒四立方公尺(兼用時,每秒六立方公尺)以上,且可隨排煙口、進風口開啟而自動啟動。所以應有排煙量6*60=360CMM (每分鐘立方公尺 M^3/min)閘門左上 左下 右上 右下 中間等5點測出風速(用風速計)m/sec算出平均風速V(m/sec),閘門面積A(㎡)排煙量Q(CMM)=V*A*60

  4. 1.利用C語言寫出偵測與控制馬達程式 • 2.安裝煙霧偵測器與步進馬達 • 3.以偵測煙霧的大小來控制馬達轉速 • 4.步進馬達原理

  5. 程式架構與系統架構圖 主程式 #include <stdio.h> /* 主程式 涂家睿 */ #include <stdlib.h> #include <string.h> #include <time.h> struct record { /* 記錄結構宣告 */ char date[20]; int time; float smoke; }; typedefstruct record student; /* 函數原型宣告 */ void addRecord(FILE *, char *, int, float); /* 主程式 */ int main(void) { FILE *fp; /* 宣告變數 */ char fname[20] = "smoke.dat"; fp = fopen(fname, "wb"); /* 開啟二進位檔案 */ printf("開始寫入檔案%s....\n", fname);

  6. /* 呼叫函數寫入記錄資料 */ inta,b,c,x=24,y=31; srand(time(NULL)); char tstr[24]; for(c=1; c<=31; c++) { for(a=1;a<=24;a++){ b=rand()%500; sprintf( tstr, "2013/5/%d:", c); addRecord(fp, tstr,a, b); } } if ( ferror(fp) ) printf("錯誤: 寫入錯誤!\n"); else printf("已經寫入%d筆記錄!\n",(x*y)); fclose(fp); /* 關閉檔案 */ system("PAUSE"); return 0; }

  7. /* 函數: 新增記錄 */ void addRecord (FILE *fp,char *date,inttime,float smoke) { student temp; strcpy(temp.date, date); /* 指定結構內容 */ temp.time = time; temp.smoke =smoke; fwrite(&temp,sizeof(temp),1,fp); /* 寫入檔案 */ }

  8. 副程式 #include <stdio.h> /* 副程式 涂家睿 */ #include <stdlib.h> struct record { /* 記錄結構宣告 */ char date[20]; int time; float smoke; }; typedefstruct record smoke; int main(void) { FILE *fp; /* 宣告變數 */ smoke std; char fname[20] = "smoke.dat"; float sum=0; fp = fopen(fname, "rb"); /* 開啟檔案新增內容 */ if ( fp != NULL ) { /* 檢查是否有錯誤 */ /* 顯示記錄資料 */ while ( !feof(fp) ) { /* 是否是檔尾 */

  9. /* 讀取記錄 */ if ( fread(&std, sizeof(std), 1, fp) ) { void delay(int sec){ time_t _t; _t = time (NULL); // 讀取系統時間 while(time (NULL) <= _t + sec){}; // 比對時間差 } inti; int a=0 ; srand(time(0)); for (a=3; a>0; a--){ printf("程式%d秒後自動偵測\n",a); delay(0); }

  10. printf("Date: %s\t", std.date); printf("Time: %d hr ", std.time); printf("Smoke: %.2f\n", std.smoke); if(std.smoke>=360) printf(“偵測煙量%.f m3 煙量高於360 m3 馬達啟動轉速500轉\n",std.smoke); else if (std.smoke<360 && std.smoke>150) printf(“偵測煙量%.f m3 煙量介於150~360 m3 馬達啟動轉速250轉\n",std.smoke); else if (std.smoke<150&& std.smoke>0) printf(“偵測煙量%.f m3 煙量低於150 m3 馬達啟動轉速150轉\n",std.smoke); else{ printf(“偵測煙量%.f m3 煙量 0 m3 馬達關閉\n",std.smoke); sum += std.smoke;

  11. } } fclose(fp); /* 關閉檔案 */ } else printf("錯誤: 檔案開啟錯誤...\n"); printf("average smoke %.2fm3", sum/744); system("PAUSE"); return 0; }

  12. 執行程式

  13. 系統架構圖

  14. 程式系統架構

  15. 心得報告 此次的期末報告讓學生學習到很多,老師的目的在於給 我們自己發揮創意然後撰寫程式,之間可以查到自己沒 學過的程式寫法,為大二的課程打下基礎 中間可以跟同學討論 教其他組的同學 甚至可以從中學習到同學利用不同的方式撰寫程式 程式要練強是靠自己不斷地練習很多時候程式是要靠自己去想出來的 完成的時間很長 有整個下午都坐在電腦前 上網查資料 不斷的DEBUG 當程式完成之後的成就感真的很棒 期待大二打出的程式接上硬體能真正使用在生活上 其實要學會C語言很簡單常練習 常討論 還要有自己創意的想法 這就是當初進自動化控制組的目的 因為很有趣

More Related