Browsing this Thread:
1 Anonymous Users
|
PIC16F917 AD轉換問題
|
|
中級會員
Joined
: 2007/3/29 12:02 最後登入時間
: 2011/8/4 18:14
Group:
註冊會員
Level : 6 HP : 0 / 148 MP : 21 / 7654 EXP : 95
|
請問大家 我現在用PIC16F917 做AD轉換
我在AN0 這邊利用兩個1K電阻做分壓後輸入到AN0腳位
使用PORTB1~3看輸出電壓與測試電壓是否相同代表完成
AD轉換,測試電壓為0V~5V 所以按照道理AN0腳位偵測到的
電壓應該為0V~2.5V才對,這樣的觀念有錯嗎??
因為我現在AN0腳位用三用電錶量居然都不是0V~2.5V
而是0V~0.9V 很奇怪 不知道是哪邊出錯,我的IC供電電壓為
5V。
附上我的程式
#include <pic.h> void delay_1ms(unsigned int count);//TIME DELAY(時間=count ms) typedef unsigned int Word;
union adres { int y1; unsigned char adre[2]; }adresult;
void delay5000(void) {unsigned int t; t=5000; while(--t); }
/*** TIME DELAY(時間=count ms) ***/ void delay_1ms(unsigned int count) { unsigned int i, j; for (i = 0 ; i < count ; i++) for (j = 0 ; j < 90 ; j++); }
void init_a2d(void) { INTCON = 0x00; OPTION = 0x80; //禁止PROTB上拉致能 OSCCON = 0x61; //選擇內部振盪器作時脈4MHz LCDCON = 0x00; //把LCD模組關閉 //ADCON0= 0x80; // AN0 VDD VSS 右對稱 ADCON0= 0xE0; ADCON1= 0x10; // 轉換時脈2us ANSEL = 0x01; // TRISA = 0X1F; PORTB = 0x0E; TRISB = 0x00; GIE = 0;
}
void AD_Get(void) { ADON=1; // 打開AD delay_1ms(200); GODONE = 1; while(GODONE); adresult.adre[0] = ADRESL; adresult.adre[1] = ADRESH; if(adresult.y1>0x200) { //PORTB = 0x00; //PORTB=0XFF; PORTB = 0x0E; delay5000(); } else //PORTB=0XFF; PORTB = 0x00; //GODONE=1;
}
void main(void) { init_a2d();
while(1) { AD_Get(); } }
發表於: 2008/8/22 10:23
|
|
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.