寫了一段ad程式
|
||||
---|---|---|---|---|
中級會員
|
如下所示
#include "Define.h" #include "pic16f91x.h" #include "pic.h" #define BATTERY_SAFE 2.95082 #define BATTERY_DANGER 2.87234 #define MAX_COUNT_RESULT 30 #define LED_GREEN_SET SetOutPort(TRISB,BIT1) #define LED_GREEN_H OutPortH(PORTB,BIT1) #define LED_GREEN_L OutPortL(PORTB,BIT1) #define LED_YELLOW_SET SetOutPort(TRISB,BIT2) #define LED_YELLOW_H OutPortH(PORTB,BIT2) #define LED_YELLOW_L OutPortL(PORTB,BIT2) #define LED_RED_SET SetOutPort(TRISB,BIT3) #define LED_RED_H OutPortH(PORTB,BIT3) #define LED_RED_L OutPortL(PORTB,BIT3) float Result[MAX_COUNT_RESULT]; Byte CountResult; void main(void) { OPTION = 0x80; //禁止PROTB上拉致能 OSCCON = 0x61; //選擇內部振盪器作時脈來源4MHz LCDCON = 0x00; //把LCD模組關閉 ANSEL = 0x00; //SET RA0 TO ANALOGY;ELSE I/O while(1) { BatteryCheck(); } } void BatteryCheck(void) { Word temp; float result; Byte i; ADCON1 = 0x10; //選則轉換時脈 2us ADCON0 = 0x80; //選用通道 & 參考電壓 ADON = 1; //打開模組 GODONE = 1; //開始轉換,轉換 11*2us while(GODONE); //等待轉換完畢 temp = ((Word)(ADRESH) << 8); temp |= (Word)(ADRESL); result = (float)(temp)*((float)(5.27)/(float)(1024.0)); Result[CountResult++] = (float)(temp)*((float)(5.27)/(float)(1024.0)); //將數值用陣列表示 for (i = 0,result = 0; i < MAX_COUNT_RESULT; i++) //將result以30次為一個單位計算 result += Result[i]; result /= i; //取30次平均值 if (result >= BATTERY_SAFE) //define BATTERY_SAFE 2.95082 電量正常顯示綠燈 { LED_GREEN_L; // RB1輸出LOW綠燈亮 LED_YELLOW_H; //RB2輸出High黃燈滅 LED_RED_H; // RB3輸出High紅燈滅 } else if (result < BATTERY_DANGER) //電量不足顯示紅燈 { LED_GREEN_H; //RB1輸出high綠燈滅 LED_YELLOW_H; //RB2輸出High黃燈滅 LED_RED_L; //RB3輸出LOW紅燈亮 } else //電量顯示中間值 顯示為黃燈 { LED_GREEN_H; //RB1輸出high綠燈滅 LED_YELLOW_L; //RB2輸出LOW黃燈亮 LED_RED_H; //RB3輸出High紅燈滅 } } 編譯後出現以下訊息 Warning[361] C:\Program Files\Microchip\Docs\FAN.c 42 : function declared implicit int Error[984] C:\Program Files\Microchip\Docs\FAN.c 50 : type redeclared 找很久bug找不出來 請問是發生什麼事了
發表於: 2008/8/7 14:03
|
|||
|