• slider image 442
  • slider image 497
  • slider image 498
  • slider image 499
  • slider image 500
  • slider image 502
:::


Browsing this Thread:   1 Anonymous Users






Re: 關於F877A的AD中斷問題...
#3
新會員
新會員


查看用戶資訊
真的很感謝你的詳細解說
講的很詳細
幫了我好大的忙
也建立了我ㄧ些觀念
謝謝你~

發表於: 2008/3/14 22:21
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於F877A的AD中斷問題...
#2
中級會員
中級會員


查看用戶資訊
這是因為主要程式裡沒有令 ADIF=1 的程式存在。

ADIF會被設定為1, 是因為A/D轉換工作的完成,
而你從舊程式改過來時只執行了 init_a2d();
其中並沒有設定 channel 與 ADGO = 1, 所以沒有任何 A/D 轉換被起始,
當然也就不會有 A/D 轉換完成時 ADIF 會被設定為1的動作了。

----------------------------------------------------------------------
建議修改...

將原本的 void init_a2d() 與 unsigned char read_a2d() 工作內容合併為新的 void init_a2d(),

void init_a2d(unsigned char channel){
ADCON0=0b01000000;
ADCON1=0;
ADON=1;

channel&=0x07;
ADCON0&=0xC5;
ADCON0|=(channel<<3);
ADIF=0;
ADGO=1;
}
這樣可以設定好 channel 並使 A/D轉換開始,

然後修改中斷程式內容...
void interrupt usart(void)
{
unsigned char x;
// 參考原本的 read_a2d(), 但不需設定 channel
// 所以直接從 ADRESH 讀取轉換完成的結果值
x=ADRESH;
PORTD = (8>>(x>>6));
ADIF=0;
ADGO=1;
// 最後讓 A/D 轉換再次開始, 否則就不會連續不停的轉換了
}


然後呢! 主程式會有一點點不一樣...
void main(void){

// 因為新的 init_a2d(channel) 需要一個 channel 的引數
init_a2d(1);
GIE=1;
PEIE=1;
ADIE=1;
TRISD=0xF0;
while(1)
{;}

}

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


關於F877A的AD中斷問題...
#1
新會員
新會員


查看用戶資訊
想請教一下為什麼下面這個程式
我原先是沒有寫中斷 有成功\r
成功結果會是PORTD的0~3位元輪流亮滅
(EX: 暗的順序是:0.1.2.3.3.2.1.0.0.1.2.3....)
但是我只是把放在主程式的轉換AD寫到中斷裏
(就是判斷ADIF有沒有變為1)
就不能跑
想請問程式哪里出了問題?

(RA0輸入 一個sin弦波
把AD轉換結果輸出到PORTD讓LED燈閃:

#include <pic.h>
__CONFIG(HS&WDTDIS&PWRTDIS&BORDIS&LVPDIS&DEBUGEN&PROTECT);

void init_a2d(void){
ADCON0=0b01000000;
ADCON1=0;
ADON=1;
}

unsigned char read_a2d(unsigned char channel){
channel&=0x07;
ADCON0&=0xC5;
ADCON0|=(channel<<3);
ADGO=1;
while(ADGO)continue;
return(ADRESH);
}

void main(void){

init_a2d();
GIE=1;
PEIE=1;
ADIE=1;
TRISD=0xF0;
while(1)
{;}

}

void interrupt usart(void)
{
unsigned char x;
x=read_a2d(1);
PORTD = (8>>(x>>6));
ADIF=0;
}

先謝謝各位了~

發表於: 2008/3/12 20:46
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... ]

教育訓練中心

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