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

論壇索引


Board index » All Posts (lwh_126)




Re: 12F675 ADC 使用問題
#1
新會員
新會員


ADCON0=0x00;// ADCON0.VCFG=0; Vref=VDD是5V沒錯

發表於: 2009/7/18 13:23
頂部


12F675 ADC 使用問題
#2
新會員
新會員


第一次使用 12F675 ADC, 依照手冊設定 MCU SFR後, 若設定無誤, VDD=5V, ANALOG 輸入如果在1.3V以上應該可以得到1024/4以上的 AD值, 可是實際測試卻要接近5V左右, 不知問題出在哪裡
以上, 還請不吝指教
CODE如下

#include <pic12f675.h>
//ADC utilities

void init_a2d(void){
ANSEL=0x34;//ADC CLOCK INTERNAL, Analog Select only AN2
//ADCON0=0x80; // right justify result.
ADCON0=0x00; // left justify
ADON=1; // turn on the A2D conversion module
}

//unsigned int read_a2d(unsigned char channel){// for 10bit ADC
unsigned char read_a2d(unsigned char channel){// for 8bit ADC
channel&=0x03; // truncate channel to 2 bits
ADCON0&=0xc3; // clear current channel select
ADCON0|=(channel<<2); // apply the new channel select
GO_DONE=1; // initiate conversion on the selected channel
while(GO_DONE);
//return (ADRESH<<8)+ADRESL; // return ADC value of the result
return ADRESH;
}



void main(void)
{


//internal RC oscilator calibration
_asm
bsf STATUS, 5 ;Bank 1
call 3FFh ;Get the cal value
movwf OSCCAL ;Calibrate
bcf STATUS, 5 ;Bank 0
_endasm;

TRISIO=0x04;// set AN2(GP2) as "input" direction pin
CMCON=0x07;
init_a2d();

/*
// for debug and test code
while(1)
{
delay_ms(1000);
GPIO=GPIO^0x30;
}
*/
while(1)
if(read_a2d(2)>63) GP5=1;
else GP5=0;

}

發表於: 2009/7/17 15:25
頂部






:::

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... ]

教育訓練中心

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