|
Re: 12F675 ADC 使用問題
|
|
新會員
|
ADCON0=0x00;// ADCON0.VCFG=0; Vref=VDD是5V沒錯
發表於: 2009/7/18 13:23
|
|
|
12F675 ADC 使用問題
|
|
新會員
|
第一次使用 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
|
|