• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   1 Anonymous Users






PIC16F917 AD轉換問題
#1
中級會員
中級會員


查看用戶資訊
請問大家 我現在用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
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... ]

教育訓練中心

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