• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
:::


Browsing this Thread:   1 Anonymous Users






Re: 關於APP020的類比轉數位問題
#2
版主
版主


查看用戶資訊
1. 看了你的描述後,有件事情還是要說清楚: 程式編譯成功只是最基本的第一步驟,失敗了就無法執行程式進行除錯。程式最大的難關還是在於流程控制的正確性,流程處理邏輯有錯則程式一定就會錯的,這是不變的道理。所以一定要思緒清楚的區規劃在推論流程的正確性及可行性。
2. 程式用看的也只能給個建議而已,最好是經自己一步一步的除錯找BUG。你的程式有邏輯上的嚴重錯誤就是:你啟動了ADIE 的中斷卻沒有對中斷做個別的處理,所以你的程式應該會ㄧ直跳到 Reset 的狀態。所以我會建議你到下載中心下載 RTC 課程裡的 "dsPIC30F Module Training" 來研讀一下,那裡的練習也都是用 APP020 寫的。

發表於: 2008/6/18 9:36
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


關於APP020的類比轉數位問題
#1
新會員
新會員


查看用戶資訊
想請問我現在已經寫了一個程式,當SW5按一下時LED1會亮再按一下SW5時LED1會暗,想請問我還要再加上設定兩段電壓範圍來控制LED1的亮跟暗,當在電壓範圍一4V到4.1V時LED1要暗,當在電壓範圍二2V到3V時要亮,我是利用PIC30F4011的AN0腳位來當類比輸入,以下是我的程式,我編譯時沒問題,執行動作時按SW5時動作都正常,可是電壓不同時沒有改變,以下主要部分為類比轉數位輸入時的程式,想請教各位前輩幫小弟看一下類比轉數位的程式有何問題,謝謝!!!PS(.....為我按SW5控制LED1的程式為求版面簡潔所以就沒放
#define __dsPIC30F4011__
#include <p30F4011.h>
#define LED1 LATEbits.LATE0
#define DIR_LED1 TRISEbits.TRISE0
#define SW5 PORTEbits.RE8
#define DIR_SW5 TRISEbits.TRISE8
#define INPUT 1
#define OUTPUT 0
#define LED_DATA LATE
void InitADC10(void);
void ADCCON(void);
int main(void )

{
InitADC10();
ADCCON();
DIR_LED1 = OUTPUT ;
DIR_SW5 = INPUT ;
LED_DATA = 0xffff ;

while (1)
{……..
………
………..
} //End of While(1) Loop
}// End of main program}
//
void InitADC10(void)
{
ADPCFG = 0x0078;
ADCON1 = 0x026E;
ADCON2 = 0x0000;
ADCHS = 0x0000;
ADCON3 = 0x0003;
IFS0bits.ADIF = 0;
IEC0bits.ADIE = 1;
ADCON1bits.ADON = 1;
}
void ADCCON(void)
{
float ADC_Value;
ADC_Value = ADCBUF0;
if(( ADC_Value < 0x399 ) && ( ADC_Value > 0x333))
{ LED1 = 1 ; }
if (( ADC_Value < 0x266 ) && ( ADC_Value > 0x199))
{ LED1 = 0 ; }
}

發表於: 2008/6/17 20:14
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... ]

教育訓練中心

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