• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: 寫了一段ad程式
#2
版主
版主


查看用戶資訊
Warning[361] C:\Program Files\Microchip\Docs\FAN.c 42 : function declared implicit int
檢查程式裡的 42 行,是否有定義不清不楚的。

Error[984] C:\Program Files\Microchip\Docs\FAN.c 50 : type redeclared
檢查程式裡的 50行,是否有重複定義。

看不出來會什麼要用浮點數來運算,如果只要取移動平均值的話只要用unsigned int 就好了。10-bit AD 就算是連續加總 32次(不要用30次) 也不會超過 unsigned int 這時總和再向右移5 bit (/32) 就好了。
最後的判斷也用 int 來判斷後點LED,簡單就好。這是個人意見討論討論。

發表於: 2008/8/7 14:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


寫了一段ad程式
#1
中級會員
中級會員


查看用戶資訊
如下所示

#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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------